111
111
import static io .swagger .codegen .v3 .generators .handlebars .ExtensionHelper .getBooleanValue ;
112
112
113
113
public abstract class DefaultCodegenConfig implements CodegenConfig {
114
- private static final Logger LOGGER = LoggerFactory .getLogger (DefaultCodegenConfig .class );
114
+ protected static final Logger LOGGER = LoggerFactory .getLogger (DefaultCodegenConfig .class );
115
115
116
116
public static final String DEFAULT_CONTENT_TYPE = "application/json" ;
117
117
public static final String REQUEST_BODY_NAME = "body" ;
@@ -358,12 +358,18 @@ public void processModelEnums(Map<String, Object> objs) {
358
358
}
359
359
cm .allowableValues .put ("enumVars" , enumVars );
360
360
}
361
+ updateCodegenModelEnumVars (cm );
362
+ }
363
+ }
361
364
362
- // update codegen property enum with proper naming convention
363
- // and handling of numbers, special characters
364
- for (CodegenProperty var : cm .vars ) {
365
- updateCodegenPropertyEnum (var );
366
- }
365
+ /**
366
+ * update codegen property enum with proper naming convention
367
+ * and handling of numbers, special characters
368
+ * @param codegenModel
369
+ */
370
+ protected void updateCodegenModelEnumVars (CodegenModel codegenModel ) {
371
+ for (CodegenProperty var : codegenModel .vars ) {
372
+ updateCodegenPropertyEnum (var );
367
373
}
368
374
}
369
375
@@ -2290,7 +2296,26 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
2290
2296
final Schema responseSchema = getSchemaFromResponse (response );
2291
2297
codegenResponse .schema = responseSchema ;
2292
2298
codegenResponse .message = escapeText (response .getDescription ());
2293
- // TODO: codegenResponse.examples = toExamples(response.getExamples());
2299
+
2300
+ if (response .getContent ()!= null ) {
2301
+ Map <String , Object > examples = new HashMap <>();
2302
+ for (String name : response .getContent ().keySet ()) {
2303
+ if (response .getContent ().get (name ) != null ) {
2304
+
2305
+ if (response .getContent ().get (name ).getExample () != null ) {
2306
+ examples .put (name , response .getContent ().get (name ).getExample ());
2307
+ }
2308
+ if (response .getContent ().get (name ).getExamples () != null ) {
2309
+
2310
+ for (String exampleName : response .getContent ().get (name ).getExamples ().keySet ()) {
2311
+ examples .put (exampleName , response .getContent ().get (name ).getExamples ().get (exampleName ).getValue ());
2312
+ }
2313
+ }
2314
+ }
2315
+ }
2316
+ codegenResponse .examples = toExamples (examples );
2317
+ }
2318
+
2294
2319
codegenResponse .jsonSchema = Json .pretty (response );
2295
2320
if (response .getExtensions () != null && !response .getExtensions ().isEmpty ()) {
2296
2321
codegenResponse .vendorExtensions .putAll (response .getExtensions ());
@@ -2697,7 +2722,9 @@ else if (schema instanceof ArraySchema) {
2697
2722
if (codegenProperty .complexType != null ) {
2698
2723
imports .add (codegenProperty .complexType );
2699
2724
}
2700
- imports .add (codegenProperty .baseType );
2725
+ if (codegenParameter .baseType != null ) {
2726
+ imports .add (codegenProperty .baseType );
2727
+ }
2701
2728
CodegenProperty innerCp = codegenProperty ;
2702
2729
while (innerCp != null ) {
2703
2730
if (innerCp .complexType != null ) {
@@ -2717,7 +2744,9 @@ else if (schema instanceof ArraySchema) {
2717
2744
setParameterNullable (codegenParameter , codegenProperty );
2718
2745
2719
2746
while (codegenProperty != null ) {
2720
- imports .add (codegenProperty .baseType );
2747
+ if (codegenProperty .baseType != null ) {
2748
+ imports .add (codegenProperty .baseType );
2749
+ }
2721
2750
codegenProperty = codegenProperty .items ;
2722
2751
}
2723
2752
}
@@ -3837,7 +3866,7 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {
3837
3866
}
3838
3867
3839
3868
// put "enumVars" map into `allowableValues", including `name` and `value`
3840
- List <Map <String , String >> enumVars = new ArrayList <Map < String , String > >();
3869
+ List <Map <String , String >> enumVars = new ArrayList <>();
3841
3870
String commonPrefix = findCommonPrefixOfVars (values );
3842
3871
int truncateIdx = commonPrefix .length ();
3843
3872
for (Object value : values ) {
@@ -3853,6 +3882,24 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {
3853
3882
}
3854
3883
allowableValues .put ("enumVars" , enumVars );
3855
3884
3885
+ // check repeated enum var names
3886
+ if (enumVars != null & !enumVars .isEmpty ()) {
3887
+ for (int i = 0 ; i < enumVars .size (); i ++) {
3888
+ final Map <String , String > enumVarList = enumVars .get (i );
3889
+ final String enumVarName = enumVarList .get ("name" );
3890
+ for (int j = 0 ; j < enumVars .size (); j ++) {
3891
+ if (i == j ) {
3892
+ continue ;
3893
+ }
3894
+ final Map <String , String > enumVarToCheckList = enumVars .get (j );
3895
+ final String enumVarNameToCheck = enumVarToCheckList .get ("name" );
3896
+ if (enumVarName .equals (enumVarNameToCheck )) {
3897
+ enumVarToCheckList .put ("name" , enumVarName + "_" + j );
3898
+ }
3899
+ }
3900
+ }
3901
+ }
3902
+
3856
3903
// handle default value for enum, e.g. available => StatusEnum.AVAILABLE
3857
3904
if (var .defaultValue != null ) {
3858
3905
String enumName = null ;
@@ -4313,6 +4360,7 @@ protected void addParameters(CodegenContent codegenContent, List<CodegenParamete
4313
4360
protected void addCodegenContentParameters (CodegenOperation codegenOperation , List <CodegenContent > codegenContents ) {
4314
4361
for (CodegenContent content : codegenContents ) {
4315
4362
addParameters (content , codegenOperation .bodyParams );
4363
+ addParameters (content , codegenOperation .formParams );
4316
4364
addParameters (content , codegenOperation .headerParams );
4317
4365
addParameters (content , codegenOperation .queryParams );
4318
4366
addParameters (content , codegenOperation .pathParams );
0 commit comments