@@ -861,8 +861,12 @@ private Response findMethodResponse(Map<String, Response> responses) {
861
861
}
862
862
return responses .get (code );
863
863
}
864
-
864
+
865
865
public CodegenOperation fromOperation (String path , String httpMethod , Operation operation , Map <String , Model > definitions ) {
866
+ return fromOperation (path , httpMethod , operation , definitions , null );
867
+ }
868
+
869
+ public CodegenOperation fromOperation (String path , String httpMethod , Operation operation , Map <String , Model > definitions , Swagger swagger ) {
866
870
CodegenOperation op = CodegenModelFactory .newInstance (CodegenModelType .OPERATION );
867
871
Set <String > imports = new HashSet <String >();
868
872
op .vendorExtensions = operation .getVendorExtensions ();
@@ -899,14 +903,25 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
899
903
op .notes = escapeText (operation .getDescription ());
900
904
op .tags = operation .getTags ();
901
905
902
- if (operation .getConsumes () != null && operation .getConsumes ().size () > 0 ) {
906
+ List <String > consumes = new ArrayList <String >();
907
+ if (operation .getConsumes () != null && operation .getConsumes ().size () > 0 ) {
908
+ // use consumes defined in the operation
909
+ consumes = operation .getConsumes ();
910
+ } else if (swagger != null && swagger .getConsumes () != null && swagger .getConsumes ().size () > 0 ) {
911
+ // use consumes defined globally
912
+ consumes = swagger .getConsumes ();
913
+ LOGGER .debug ("Using global consumes (" + swagger .getConsumes () + ") for " + op .operationId );
914
+ }
915
+
916
+ // if "consumes" is defined (per operation or using global definition)
917
+ if (consumes != null && consumes .size () > 0 ) {
903
918
List <Map <String , String >> c = new ArrayList <Map <String , String >>();
904
919
int count = 0 ;
905
- for (String key : operation . getConsumes () ) {
920
+ for (String key : consumes ) {
906
921
Map <String , String > mediaType = new HashMap <String , String >();
907
922
mediaType .put ("mediaType" , key );
908
923
count += 1 ;
909
- if (count < operation . getConsumes () .size ()) {
924
+ if (count < consumes .size ()) {
910
925
mediaType .put ("hasMore" , "true" );
911
926
} else {
912
927
mediaType .put ("hasMore" , null );
@@ -917,14 +932,25 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
917
932
op .hasConsumes = true ;
918
933
}
919
934
920
- if (operation .getProduces () != null && operation .getProduces ().size () > 0 ) {
935
+ List <String > produces = new ArrayList <String >();
936
+ if (operation .getProduces () != null && operation .getProduces ().size () > 0 ) {
937
+ // use produces defined in the operation
938
+ produces = operation .getProduces ();
939
+ } else if (swagger != null && swagger .getProduces () != null && swagger .getProduces ().size () > 0 ) {
940
+ // use produces defined globally
941
+ produces = swagger .getProduces ();
942
+ LOGGER .debug ("Using global produces (" + swagger .getProduces () + ") for " + op .operationId );
943
+ }
944
+
945
+ // if "produces" is defined (per operation or using global definition)
946
+ if (produces != null && produces .size () > 0 ) {
921
947
List <Map <String , String >> c = new ArrayList <Map <String , String >>();
922
948
int count = 0 ;
923
- for (String key : operation . getProduces () ) {
949
+ for (String key : produces ) {
924
950
Map <String , String > mediaType = new HashMap <String , String >();
925
951
mediaType .put ("mediaType" , key );
926
952
count += 1 ;
927
- if (count < operation . getProduces () .size ()) {
953
+ if (count < produces .size ()) {
928
954
mediaType .put ("hasMore" , "true" );
929
955
} else {
930
956
mediaType .put ("hasMore" , null );
0 commit comments