@@ -1798,12 +1798,15 @@ public String toOneOfName(List<String> names, ComposedSchema composedSchema) {
1798
1798
* @return the string representation of the schema type.
1799
1799
*/
1800
1800
private String getSingleSchemaType (Schema schema ) {
1801
- Schema unaliasSchema = ModelUtils .unaliasSchema (this .openAPI , schema );
1801
+ Schema unaliasSchema = ModelUtils .unaliasSchema (this .openAPI , schema , importMapping );
1802
1802
1803
1803
if (StringUtils .isNotBlank (unaliasSchema .get$ref ())) { // reference to another definition/schema
1804
1804
// get the schema/model name from $ref
1805
1805
String schemaName = ModelUtils .getSimpleRef (unaliasSchema .get$ref ());
1806
1806
if (StringUtils .isNotEmpty (schemaName )) {
1807
+ if (importMapping .containsKey (schemaName )) {
1808
+ return schemaName ;
1809
+ }
1807
1810
return getAlias (schemaName );
1808
1811
} else {
1809
1812
LOGGER .warn ("Error obtaining the datatype from ref:" + unaliasSchema .get$ref () + ". Default to 'object'" );
@@ -1903,7 +1906,6 @@ public String lowerCamelCase(String name) {
1903
1906
return (name .length () > 0 ) ? (Character .toLowerCase (name .charAt (0 )) + name .substring (1 )) : "" ;
1904
1907
}
1905
1908
1906
-
1907
1909
/**
1908
1910
* Output the type declaration of a given name
1909
1911
*
@@ -2021,7 +2023,7 @@ public CodegenModel fromModel(String name, Schema schema) {
2021
2023
}
2022
2024
2023
2025
// unalias schema
2024
- schema = ModelUtils .unaliasSchema (this .openAPI , schema );
2026
+ schema = ModelUtils .unaliasSchema (this .openAPI , schema , importMapping );
2025
2027
if (schema == null ) {
2026
2028
LOGGER .warn ("Schema {} not found" , name );
2027
2029
return null ;
@@ -2372,7 +2374,7 @@ public CodegenProperty fromProperty(String name, Schema p) {
2372
2374
LOGGER .debug ("debugging fromProperty for " + name + " : " + p );
2373
2375
2374
2376
// unalias schema
2375
- p = ModelUtils .unaliasSchema (this .openAPI , p );
2377
+ p = ModelUtils .unaliasSchema (this .openAPI , p , importMapping );
2376
2378
2377
2379
CodegenProperty property = CodegenModelFactory .newInstance (CodegenModelType .PROPERTY );
2378
2380
@@ -2526,12 +2528,13 @@ public CodegenProperty fromProperty(String name, Schema p) {
2526
2528
} else if (ModelUtils .isArraySchema (p )) {
2527
2529
// default to string if inner item is undefined
2528
2530
ArraySchema arraySchema = (ArraySchema ) p ;
2529
- Schema innerSchema = ModelUtils .unaliasSchema (this .openAPI , getSchemaItems (arraySchema ));
2531
+ Schema innerSchema = ModelUtils .unaliasSchema (this .openAPI , getSchemaItems (arraySchema ), importMapping );
2530
2532
if (arraySchema .getItems () == null ) {
2531
2533
arraySchema .setItems (innerSchema );
2532
2534
}
2533
2535
} else if (ModelUtils .isMapSchema (p )) {
2534
- Schema innerSchema = ModelUtils .unaliasSchema (this .openAPI , ModelUtils .getAdditionalProperties (p ));
2536
+ Schema innerSchema = ModelUtils .unaliasSchema (this .openAPI , ModelUtils .getAdditionalProperties (p ),
2537
+ importMapping );
2535
2538
if (innerSchema == null ) {
2536
2539
LOGGER .error ("Undefined map inner type for `{}`. Default to String." , p .getName ());
2537
2540
innerSchema = new StringSchema ().description ("//TODO automatically added by openapi-generator due to undefined type" );
@@ -2607,7 +2610,7 @@ public CodegenProperty fromProperty(String name, Schema p) {
2607
2610
itemName = property .name ;
2608
2611
}
2609
2612
ArraySchema arraySchema = (ArraySchema ) p ;
2610
- Schema innerSchema = ModelUtils .unaliasSchema (this .openAPI , getSchemaItems (arraySchema ));
2613
+ Schema innerSchema = ModelUtils .unaliasSchema (this .openAPI , getSchemaItems (arraySchema ), importMapping );
2611
2614
if (arraySchema .getItems () == null ) {
2612
2615
arraySchema .setItems (innerSchema );
2613
2616
}
@@ -2622,7 +2625,8 @@ public CodegenProperty fromProperty(String name, Schema p) {
2622
2625
property .maxItems = p .getMaxProperties ();
2623
2626
2624
2627
// handle inner property
2625
- Schema innerSchema = ModelUtils .unaliasSchema (this .openAPI , ModelUtils .getAdditionalProperties (p ));
2628
+ Schema innerSchema = ModelUtils .unaliasSchema (this .openAPI , ModelUtils .getAdditionalProperties (p ),
2629
+ importMapping );
2626
2630
if (innerSchema == null ) {
2627
2631
LOGGER .error ("Undefined map inner type for `{}`. Default to String." , p .getName ());
2628
2632
innerSchema = new StringSchema ().description ("//TODO automatically added by openapi-generator due to undefined type" );
@@ -2841,7 +2845,24 @@ protected void handleMethodResponse(Operation operation,
2841
2845
Map <String , Schema > schemas ,
2842
2846
CodegenOperation op ,
2843
2847
ApiResponse methodResponse ) {
2844
- Schema responseSchema = ModelUtils .unaliasSchema (this .openAPI , ModelUtils .getSchemaFromResponse (methodResponse ));
2848
+ handleMethodResponse (operation , schemas , op , methodResponse , Collections .<String , String >emptyMap ());
2849
+ }
2850
+
2851
+ /**
2852
+ * Set op's returnBaseType, returnType, examples etc.
2853
+ *
2854
+ * @param operation endpoint Operation
2855
+ * @param schemas a map of the schemas in the openapi spec
2856
+ * @param op endpoint CodegenOperation
2857
+ * @param methodResponse the default ApiResponse for the endpoint
2858
+ * @param importMappings mappings of external types to be omitted by unaliasing
2859
+ */
2860
+ protected void handleMethodResponse (Operation operation ,
2861
+ Map <String , Schema > schemas ,
2862
+ CodegenOperation op ,
2863
+ ApiResponse methodResponse ,
2864
+ Map <String , String > importMappings ) {
2865
+ Schema responseSchema = ModelUtils .unaliasSchema (this .openAPI , ModelUtils .getSchemaFromResponse (methodResponse ), importMappings );
2845
2866
2846
2867
if (responseSchema != null ) {
2847
2868
CodegenProperty cm = fromProperty ("response" , responseSchema );
@@ -2996,7 +3017,7 @@ public CodegenOperation fromOperation(String path,
2996
3017
op .responses .get (op .responses .size () - 1 ).hasMore = false ;
2997
3018
2998
3019
if (methodResponse != null ) {
2999
- handleMethodResponse (operation , schemas , op , methodResponse );
3020
+ handleMethodResponse (operation , schemas , op , methodResponse , importMapping );
3000
3021
}
3001
3022
}
3002
3023
@@ -3130,9 +3151,12 @@ public CodegenOperation fromOperation(String path,
3130
3151
Collections .sort (allParams , new Comparator <CodegenParameter >() {
3131
3152
@ Override
3132
3153
public int compare (CodegenParameter one , CodegenParameter another ) {
3133
- if (one .required == another .required ) return 0 ;
3134
- else if (one .required ) return -1 ;
3135
- else return 1 ;
3154
+ if (one .required == another .required )
3155
+ return 0 ;
3156
+ else if (one .required )
3157
+ return -1 ;
3158
+ else
3159
+ return 1 ;
3136
3160
}
3137
3161
});
3138
3162
}
@@ -3211,7 +3235,8 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
3211
3235
}
3212
3236
Schema responseSchema ;
3213
3237
if (this .openAPI != null && this .openAPI .getComponents () != null ) {
3214
- responseSchema = ModelUtils .unaliasSchema (this .openAPI , ModelUtils .getSchemaFromResponse (response ));
3238
+ responseSchema = ModelUtils .unaliasSchema (this .openAPI , ModelUtils .getSchemaFromResponse (response ),
3239
+ importMapping );
3215
3240
} else { // no model/alias defined
3216
3241
responseSchema = ModelUtils .getSchemaFromResponse (response );
3217
3242
}
@@ -3443,7 +3468,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
3443
3468
}
3444
3469
3445
3470
if (s != null ) {
3446
- Schema parameterSchema = ModelUtils .unaliasSchema (this .openAPI , s );
3471
+ Schema parameterSchema = ModelUtils .unaliasSchema (this .openAPI , s , importMapping );
3447
3472
if (parameterSchema == null ) {
3448
3473
LOGGER .warn ("warning! Schema not found for parameter \" " + parameter .getName () + "\" , using String" );
3449
3474
parameterSchema = new StringSchema ().description ("//TODO automatically added by openapi-generator due to missing type definition." );
@@ -4047,7 +4072,7 @@ protected void addImport(CodegenModel m, String type) {
4047
4072
private Map <String , Schema > unaliasPropertySchema (Map <String , Schema > properties ) {
4048
4073
if (properties != null ) {
4049
4074
for (String key : properties .keySet ()) {
4050
- properties .put (key , ModelUtils .unaliasSchema (this .openAPI , properties .get (key )));
4075
+ properties .put (key , ModelUtils .unaliasSchema (this .openAPI , properties .get (key ), importMapping () ));
4051
4076
4052
4077
}
4053
4078
}
@@ -5422,7 +5447,6 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S
5422
5447
codegenParameter .maxLength = codegenProperty .maxLength ;
5423
5448
codegenParameter .pattern = codegenProperty .pattern ;
5424
5449
5425
-
5426
5450
if (codegenProperty .complexType != null ) {
5427
5451
imports .add (codegenProperty .complexType );
5428
5452
}
0 commit comments