@@ -869,207 +869,6 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
869
869
return op ;
870
870
}
871
871
872
-
873
-
874
-
875
-
876
- public CodegenOperation fromOperation (String path , String httpMethod , Operation operation , Map <String , Model > definitions ) {
877
- CodegenOperation op = CodegenModelFactory .newInstance (CodegenModelType .OPERATION );
878
- Set <String > imports = new HashSet <String >();
879
-
880
- String operationId = operation .getOperationId ();
881
- if (operationId == null ) {
882
- String tmpPath = path ;
883
- tmpPath = tmpPath .replaceAll ("\\ {" , "" );
884
- tmpPath = tmpPath .replaceAll ("\\ }" , "" );
885
- String [] parts = (tmpPath + "/" + httpMethod ).split ("/" );
886
- StringBuilder builder = new StringBuilder ();
887
- if ("/" .equals (tmpPath )) {
888
- // must be root tmpPath
889
- builder .append ("root" );
890
- }
891
- for (int i = 0 ; i < parts .length ; i ++) {
892
- String part = parts [i ];
893
- if (part .length () > 0 ) {
894
- if (builder .toString ().length () == 0 ) {
895
- part = Character .toLowerCase (part .charAt (0 )) + part .substring (1 );
896
- } else {
897
- part = initialCaps (part );
898
- }
899
- builder .append (part );
900
- }
901
- }
902
- operationId = builder .toString ();
903
- LOGGER .warn ("generated operationId " + operationId );
904
- }
905
- operationId = removeNonNameElementToCamelCase (operationId );
906
- op .path = path ;
907
- op .operationId = toOperationId (operationId );
908
- op .summary = escapeText (operation .getSummary ());
909
- op .notes = escapeText (operation .getDescription ());
910
- op .tags = operation .getTags ();
911
-
912
- if (operation .getConsumes () != null && operation .getConsumes ().size () > 0 ) {
913
- List <Map <String , String >> c = new ArrayList <Map <String , String >>();
914
- int count = 0 ;
915
- for (String key : operation .getConsumes ()) {
916
- Map <String , String > mediaType = new HashMap <String , String >();
917
- mediaType .put ("mediaType" , key );
918
- count += 1 ;
919
- if (count < operation .getConsumes ().size ()) {
920
- mediaType .put ("hasMore" , "true" );
921
- } else {
922
- mediaType .put ("hasMore" , null );
923
- }
924
- c .add (mediaType );
925
- }
926
- op .consumes = c ;
927
- op .hasConsumes = true ;
928
- }
929
-
930
- if (operation .getProduces () != null && operation .getProduces ().size () > 0 ) {
931
- List <Map <String , String >> c = new ArrayList <Map <String , String >>();
932
- int count = 0 ;
933
- for (String key : operation .getProduces ()) {
934
- Map <String , String > mediaType = new HashMap <String , String >();
935
- mediaType .put ("mediaType" , key );
936
- count += 1 ;
937
- if (count < operation .getProduces ().size ()) {
938
- mediaType .put ("hasMore" , "true" );
939
- } else {
940
- mediaType .put ("hasMore" , null );
941
- }
942
- c .add (mediaType );
943
- }
944
- op .produces = c ;
945
- op .hasProduces = true ;
946
- }
947
-
948
- if (operation .getResponses () != null && !operation .getResponses ().isEmpty ()) {
949
- Response methodResponse = findMethodResponse (operation .getResponses ());
950
-
951
- for (Map .Entry <String , Response > entry : operation .getResponses ().entrySet ()) {
952
- Response response = entry .getValue ();
953
- CodegenResponse r = fromResponse (entry .getKey (), response );
954
- r .hasMore = true ;
955
- if (r .baseType != null &&
956
- !defaultIncludes .contains (r .baseType ) &&
957
- !languageSpecificPrimitives .contains (r .baseType )) {
958
- imports .add (r .baseType );
959
- }
960
- r .isDefault = response == methodResponse ;
961
- op .responses .add (r );
962
- }
963
- op .responses .get (op .responses .size () - 1 ).hasMore = false ;
964
-
965
- if (methodResponse != null ) {
966
- if (methodResponse .getSchema () != null ) {
967
- CodegenProperty cm = fromProperty ("response" , methodResponse .getSchema ());
968
-
969
- Property responseProperty = methodResponse .getSchema ();
970
-
971
- if (responseProperty instanceof ArrayProperty ) {
972
- ArrayProperty ap = (ArrayProperty ) responseProperty ;
973
- CodegenProperty innerProperty = fromProperty ("response" , ap .getItems ());
974
- op .returnBaseType = innerProperty .baseType ;
975
- } else {
976
- if (cm .complexType != null ) {
977
- op .returnBaseType = cm .complexType ;
978
- } else {
979
- op .returnBaseType = cm .baseType ;
980
- }
981
- }
982
- op .examples = new ExampleGenerator (definitions ).generate (methodResponse .getExamples (), operation .getProduces (), responseProperty );
983
- op .defaultResponse = toDefaultValue (responseProperty );
984
- op .returnType = cm .datatype ;
985
- if (cm .isContainer != null ) {
986
- op .returnContainer = cm .containerType ;
987
- if ("map" .equals (cm .containerType )) {
988
- op .isMapContainer = Boolean .TRUE ;
989
- } else if ("list" .equalsIgnoreCase (cm .containerType )) {
990
- op .isListContainer = Boolean .TRUE ;
991
- } else if ("array" .equalsIgnoreCase (cm .containerType )) {
992
- op .isListContainer = Boolean .TRUE ;
993
- }
994
- } else {
995
- op .returnSimpleType = true ;
996
- }
997
- if (languageSpecificPrimitives ().contains (op .returnBaseType ) || op .returnBaseType == null ) {
998
- op .returnTypeIsPrimitive = true ;
999
- }
1000
- }
1001
- addHeaders (methodResponse , op .responseHeaders );
1002
- }
1003
- }
1004
-
1005
- List <Parameter > parameters = operation .getParameters ();
1006
- CodegenParameter bodyParam = null ;
1007
- List <CodegenParameter > allParams = new ArrayList <CodegenParameter >();
1008
- List <CodegenParameter > bodyParams = new ArrayList <CodegenParameter >();
1009
- List <CodegenParameter > pathParams = new ArrayList <CodegenParameter >();
1010
- List <CodegenParameter > queryParams = new ArrayList <CodegenParameter >();
1011
- List <CodegenParameter > headerParams = new ArrayList <CodegenParameter >();
1012
- List <CodegenParameter > cookieParams = new ArrayList <CodegenParameter >();
1013
- List <CodegenParameter > formParams = new ArrayList <CodegenParameter >();
1014
-
1015
- if (parameters != null ) {
1016
- for (Parameter param : parameters ) {
1017
- CodegenParameter p = fromParameter (param , imports );
1018
- allParams .add (p );
1019
- if (param instanceof QueryParameter ) {
1020
- p .isQueryParam = new Boolean (true );
1021
- queryParams .add (p .copy ());
1022
- } else if (param instanceof PathParameter ) {
1023
- p .required = true ;
1024
- p .isPathParam = new Boolean (true );
1025
- pathParams .add (p .copy ());
1026
- } else if (param instanceof HeaderParameter ) {
1027
- p .isHeaderParam = new Boolean (true );
1028
- headerParams .add (p .copy ());
1029
- } else if (param instanceof CookieParameter ) {
1030
- p .isCookieParam = new Boolean (true );
1031
- cookieParams .add (p .copy ());
1032
- } else if (param instanceof BodyParameter ) {
1033
- p .isBodyParam = new Boolean (true );
1034
- bodyParam = p ;
1035
- bodyParams .add (p .copy ());
1036
- } else if (param instanceof FormParameter ) {
1037
- if ("file" .equalsIgnoreCase (((FormParameter ) param ).getType ())) {
1038
- p .isFile = true ;
1039
- } else {
1040
- p .notFile = true ;
1041
- }
1042
- p .isFormParam = new Boolean (true );
1043
- formParams .add (p .copy ());
1044
- }
1045
- }
1046
- }
1047
- for (String i : imports ) {
1048
- if (!defaultIncludes .contains (i ) && !languageSpecificPrimitives .contains (i )) {
1049
- op .imports .add (i );
1050
- }
1051
- }
1052
- op .bodyParam = bodyParam ;
1053
- op .httpMethod = httpMethod .toUpperCase ();
1054
- op .allParams = addHasMore (allParams );
1055
- op .bodyParams = addHasMore (bodyParams );
1056
- op .pathParams = addHasMore (pathParams );
1057
- op .queryParams = addHasMore (queryParams );
1058
- op .headerParams = addHasMore (headerParams );
1059
- // op.cookieParams = cookieParams;
1060
- op .formParams = addHasMore (formParams );
1061
- // legacy support
1062
- op .nickname = op .operationId ;
1063
-
1064
-
1065
- if (op .allParams .size () > 0 ) {
1066
- op .hasParams = true ;
1067
- }
1068
- op .externalDocs = operation .getExternalDocs ();
1069
-
1070
- return op ;
1071
- }
1072
-
1073
872
public CodegenResponse fromResponse (String responseCode , Response response ) {
1074
873
CodegenResponse r = CodegenModelFactory .newInstance (CodegenModelType .RESPONSE );
1075
874
if ("default" .equals (responseCode )) {
0 commit comments