@@ -541,15 +541,27 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
541541 rsp .vendorExtensions .put ("x-response-id" , responseId );
542542 }
543543
544- if (rsp .dataType != null ) {
545- List <String > producesTypes = new ArrayList <>();
544+ List <String > producesTypes = new ArrayList <>();
546545
547- if (original .getContent () != null ) {
548- producesTypes .addAll (original .getContent ().keySet ());
549- }
546+ if (original .getContent () != null ) {
547+ producesTypes .addAll (original .getContent ().keySet ());
548+ }
550549
551- List <Map <String , Object >> responseContentTypes = new ArrayList <>();
550+ List <Map <String , Object >> responseContentTypes = new ArrayList <>();
552551
552+ // If there are no content types (no body), create a single variant without content
553+ if (producesTypes .isEmpty ()) {
554+ Map <String , Object > contentTypeInfo = new HashMap <>();
555+
556+ // Use the response-id directly as the variant name for responses without content
557+ if (rsp .vendorExtensions .containsKey ("x-response-id" )) {
558+ String baseId = (String ) rsp .vendorExtensions .get ("x-response-id" );
559+ contentTypeInfo .put ("x-variant-name" , baseId );
560+ }
561+
562+ responseContentTypes .add (contentTypeInfo );
563+ } else {
564+ // Process each content type
553565 for (String contentType : producesTypes ) {
554566 Map <String , Object > contentTypeInfo = new HashMap <>();
555567 contentTypeInfo .put ("mediaType" , contentType );
@@ -576,11 +588,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
576588 } else {
577589 // Everything else is plain-text
578590 contentTypeInfo .put ("x-content-suffix" , "PlainText" );
579- if (bytesType .equals (rsp .dataType )) {
580- contentTypeInfo .put ("x-serializer-bytes" , true );
581- } else {
582- contentTypeInfo .put ("x-serializer-plain" , true );
583- }
591+ // Note: serializer flags will be set after determining the actual body type
584592 }
585593
586594 // Group together the x-response-id and x-content-suffix created above in order to produce
@@ -599,6 +607,9 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
599607 bodyType = stringType ;
600608 } else if (contentTypeInfo .get ("x-output-mime-type" ).equals (plainTextMimeType )) {
601609 bodyType = bytesType .equals (rsp .dataType ) ? bytesType : stringType ;
610+ } else if (contentTypeInfo .get ("x-output-mime-type" ).equals (octetMimeType )) {
611+ // For octet-stream, always use ByteArray
612+ bodyType = bytesType ;
602613 } else if (contentTypeInfo .get ("x-output-mime-type" ).equals (eventStreamMimeType )) {
603614 Schema <?> ctSchema = Optional .ofNullable (original .getContent ())
604615 .map (c -> c .get (contentType ))
@@ -619,14 +630,26 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
619630 bodyType = stringType ;
620631 }
621632 contentTypeInfo .put ("x-body-type" , bodyType );
633+ contentTypeInfo .put ("dataType" , bodyType ); // Also set dataType for template conditionals
634+
635+ // Set serializer flags based on the actual body type for plain-text/octet-stream
636+ if (!contentTypeInfo .containsKey ("x-serializer-json" ) &&
637+ !contentTypeInfo .containsKey ("x-serializer-form" ) &&
638+ !contentTypeInfo .containsKey ("x-serializer-event-stream" )) {
639+ if (bytesType .equals (bodyType )) {
640+ contentTypeInfo .put ("x-serializer-bytes" , true );
641+ } else {
642+ contentTypeInfo .put ("x-serializer-plain" , true );
643+ }
644+ }
622645 }
623646
624647 responseContentTypes .add (contentTypeInfo );
625648 }
626-
627- rsp .vendorExtensions .put ("x-response-content-types" , responseContentTypes );
628649 }
629650
651+ rsp .vendorExtensions .put ("x-response-content-types" , responseContentTypes );
652+
630653 for (CodegenProperty header : rsp .headers ) {
631654 if (uuidType .equals (header .dataType )) {
632655 additionalProperties .put ("apiUsesUuid" , true );
0 commit comments