{"record":{"id":"95eb4273250418a5","repo":"OpenAPITools/openapi-generator","slug":"only-1-response-media-type-supported-when-sse-is","errorCode":null,"errorMessage":"only 1 response media type supported, when SSE is detected","messagePattern":"only 1 response media type supported, when SSE is detected","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java","lineNumber":1511,"sourceCode":"                        schema:\n                        type: array\n                        format: event-stream\n                        items:\n                            type: <type> or\n                            $ref: <typeRef>\n                 */\n            Map<String, List<Schema>> schemaTypes = operation.getResponses().entrySet().stream()\n                    .map(e -> Pair.of(e.getValue(), fromResponse(e.getKey(), e.getValue())))\n                    .filter(p -> p.getRight().is2xx) // consider only success\n                    .map(p -> p.getLeft().getContent().get(MEDIA_EVENT_STREAM))\n                    .map(MediaType::getSchema)\n                    .collect(Collectors.toList()).stream()\n                    .collect(Collectors.groupingBy(Schema::getType));\n            if (schemaTypes.containsKey(\"array\")) {\n                // we have a match with SSE pattern\n                // double check potential conflicting, multiple specs\n                if (schemaTypes.size() > 1) {\n                    throw new RuntimeException(\"only 1 response media type supported, when SSE is detected\");\n                }\n                // double check schema format\n                List<Schema> eventTypes = schemaTypes.get(\"array\");\n                if (eventTypes.stream().anyMatch(schema -> !\"event-stream\".equalsIgnoreCase(schema.getFormat()))) {\n                    throw new RuntimeException(\"schema format 'event-stream' is required, when SSE is detected\");\n                }\n                // double check item types\n                Set<String> itemTypes = eventTypes.stream()\n                        .map(schema -> schema.getItems().getType() != null\n                                ? schema.getItems().getType()\n                                : schema.getItems().get$ref())\n                        .collect(Collectors.toSet());\n                if (itemTypes.size() > 1) {\n                    throw new RuntimeException(\"only single item type is supported, when SSE is detected\");\n                }\n                codegenOperation.vendorExtensions.put(\"x-sse\", true);\n            } // Not an SSE compliant definition\n        }","sourceCodeStart":1493,"sourceCodeEnd":1529,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java#L1493-L1529","documentation":"While post-processing an operation, the Spring generator detects the server-sent-events (SSE) pattern: a 2xx response with media type text/event-stream whose schema has type array. It then groups all text/event-stream success schemas by type and requires exactly one distinct type; if both array and a non-array type appear, generation aborts because a reactive SSE endpoint can only be modelled one way.","triggerScenarios":"An operation declares multiple 2xx responses (e.g. 200 and 201) with text/event-stream content, where one response schema has type: array and another has type: object or type: string.","commonSituations":"Async APIs that mix event streams and plain JSON success bodies under different status codes; specs assembled from multiple teams; specs converted from other formats where media types got merged onto several success responses.","solutions":["Keep a single schema type across all 2xx text/event-stream responses: move non-stream success payloads to application/json or another media type.","Verify the array schema also declares format: event-stream and one item type, so the follow-up SSE checks pass.","Model varied payloads as a oneOf item schema inside the single event-stream array."],"exampleFix":"# before\nresponses:\n  '200':\n    content:\n      text/event-stream:\n        schema:\n          type: array\n          format: event-stream\n          items: { $ref: '#/components/schemas/Event' }\n  '201':\n    content:\n      text/event-stream:\n        schema:\n          type: object   # second schema type -> error\n\n# after\nresponses:\n  '200':\n    content:\n      text/event-stream:\n        schema:\n          type: array\n          format: event-stream\n          items: { $ref: '#/components/schemas/Event' }","handlingStrategy":"validation","validationCode":"// node: reject mixed schema types across 2xx event-stream responses\nconst assertSingleSseType = (op) => {\n  const types = Object.values(op.responses || {})\n    .filter(r => r.content && r.content['text/event-stream'])\n    .map(r => r.content['text/event-stream'].schema?.type);\n  const uniq = [...new Set(types)];\n  if (uniq.length > 1) throw new Error(`multiple SSE schema types: ${uniq.join(',')}`);\n};\nObject.values(spec.paths).forEach(p => Object.values(p).forEach(assertSingleSseType));","typeGuard":null,"tryCatchPattern":"// Java: catch spec-shape errors separately from option errors\ntry { new DefaultGenerator().opts(input).generate(); }\ncatch (RuntimeException e) {\n    // SSE messages come from operation post-processing; point users at the operation in the spec\n    throw new SpecValidationException(e.getMessage(), e);\n}","preventionTips":["Lint the spec in CI with a custom rule enforcing one event-stream success shape per operation.","Keep SSE payloads under a single 2xx response; use headers, not extra codes, for variations.","Document the generator's SSE convention (type: array + format: event-stream + one item type) in the spec README."],"tags":["spring","sse","openapi","spec-validation"],"backgroundTag":"sse-schema-validation","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}