1717package org .openapitools .codegen .languages ;
1818
1919import io .swagger .v3 .oas .models .OpenAPI ;
20- import io .swagger .v3 .oas .models .PathItem ;
2120import io .swagger .v3 .oas .models .media .ArraySchema ;
2221import io .swagger .v3 .oas .models .media .MapSchema ;
2322import io .swagger .v3 .oas .models .media .ObjectSchema ;
@@ -85,7 +84,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
8584
8685 private boolean wrapComplexType = true ;
8786
88- private boolean supportMultipleResponses = false ;
87+ private boolean supportMultipleResponses = true ;
8988
9089 @ Override
9190 public CodegenType getTag () {
@@ -245,8 +244,10 @@ public void processOpts() {
245244 this .setAggregateModelsName ((String ) additionalProperties .get (AGGREGATE_MODELS_NAME ));
246245 }
247246
248- if (additionalProperties .containsKey (this .SUPPORT_MULTIPLE_RESPONSES )) {
247+ if (additionalProperties .containsKey (this .SUPPORT_MULTIPLE_RESPONSES )) {
249248 this .supportMultipleResponses = convertPropertyToBooleanAndWriteBack (SUPPORT_MULTIPLE_RESPONSES );
249+ } else {
250+ additionalProperties .put (this .SUPPORT_MULTIPLE_RESPONSES , this .supportMultipleResponses );
250251 }
251252
252253 supportingFiles .add (new SupportingFile ("README.mustache" , "" , "README.md" ));
@@ -530,7 +531,9 @@ public void addUnspecifiedToAllowableValues(Map<String, Object> allowableValues)
530531
531532 if (allowableValues .containsKey ("values" )) {
532533 List <String > values = (List <String >) allowableValues .get ("values" );
533- values .add (0 , "UNSPECIFIED" );
534+ List <String > modifiableValues = new ArrayList <>(values );
535+ modifiableValues .add (0 , "UNSPECIFIED" );
536+ allowableValues .put ("values" , modifiableValues );
534537 }
535538 }
536539 }
@@ -964,11 +967,11 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
964967 if (r .returnProperty == null ) {
965968 r .vendorExtensions .put ("x-oneOf-response-type" , "google.protobuf.Empty" );
966969 r .vendorExtensions .put ("x-oneOf-response-name" , "empty" );
967- } else if (r .isMap ) {
970+ } else if (r .isMap && r . additionalProperties != null ) {
968971 r .vendorExtensions .put ("x-oneOf-response-type" , r .returnProperty .additionalProperties .dataType );
969972 r .vendorExtensions .put ("x-oneOf-response-name" , resolveVarName (r .returnProperty .additionalProperties ));
970973 LOGGER .warn ("Mapping responses for operations with supportMultipleResponses flag (operation ID: {}) is not currently supported." , op .operationId );
971- } else if (r .isArray ) {
974+ } else if (r .isArray && r . items != null ) {
972975 r .vendorExtensions .put ("x-oneOf-response-type" , r .returnProperty .items .dataType );
973976 r .vendorExtensions .put ("x-oneOf-response-name" , resolveVarName (r .returnProperty .items ));
974977 LOGGER .warn ("Array responses for operations with supportMultipleResponses flag (operation ID: {}) is not currently supported." , op .operationId );
@@ -983,9 +986,14 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
983986 }
984987
985988 if (this .aggregateModelsName != null ) {
989+ List <Map <String , String >> imports = objs .getImports ().stream ()
990+ .filter (importMap -> !importMap .get ("import" ).startsWith ("models/" ))
991+ .collect (Collectors .toList ());
992+
986993 List <Map <String , String >> aggregate_imports = Collections .singletonList (Collections
987994 .singletonMap (IMPORT , toModelImport (this .aggregateModelsName )));
988- objs .setImports (aggregate_imports );
995+ imports .addAll (aggregate_imports );
996+ objs .setImports (imports );
989997 }
990998 return objs ;
991999 }
0 commit comments