@@ -142,6 +142,7 @@ public abstract class DefaultCodegenConfig implements CodegenConfig {
142
142
protected Map <String , String > modelDocTemplateFiles = new HashMap <String , String >();
143
143
protected Map <String , String > reservedWordsMappings = new HashMap <String , String >();
144
144
protected String templateDir ;
145
+ protected String customTemplateDir ;
145
146
protected String templateVersion ;
146
147
protected String embeddedTemplateDir ;
147
148
protected String commonTemplateDir = "_common" ;
@@ -181,8 +182,9 @@ public List<CliOption> cliOptions() {
181
182
182
183
public void processOpts () {
183
184
if (additionalProperties .containsKey (CodegenConstants .TEMPLATE_DIR )) {
184
- this .setTemplateDir (( String ) additionalProperties .get (CodegenConstants .TEMPLATE_DIR ));
185
+ this .customTemplateDir = additionalProperties .get (CodegenConstants .TEMPLATE_DIR ). toString ( );
185
186
}
187
+ this .embeddedTemplateDir = this .templateDir = getTemplateDir ();
186
188
187
189
if (additionalProperties .get (CodegenConstants .IGNORE_IMPORT_MAPPING_OPTION ) != null ) {
188
190
setIgnoreImportMapping (Boolean .parseBoolean ( additionalProperties .get (CodegenConstants .IGNORE_IMPORT_MAPPING_OPTION ).toString ()));
@@ -266,13 +268,17 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> processedMod
266
268
allModels .put (modelName , codegenModel );
267
269
}
268
270
}
271
+ postProcessAllCodegenModels (allModels );
272
+ return processedModels ;
273
+ }
274
+
275
+ protected void postProcessAllCodegenModels (Map <String , CodegenModel > allModels ) {
269
276
if (supportsInheritance ) {
270
277
for (String name : allModels .keySet ()) {
271
278
final CodegenModel codegenModel = allModels .get (name );
272
279
fixUpParentAndInterfaces (codegenModel , allModels );
273
280
}
274
281
}
275
- return processedModels ;
276
282
}
277
283
278
284
/**
@@ -582,6 +588,10 @@ public String embeddedTemplateDir() {
582
588
}
583
589
}
584
590
591
+ public String customTemplateDir () {
592
+ return this .customTemplateDir ;
593
+ }
594
+
585
595
public String getCommonTemplateDir () {
586
596
return this .commonTemplateDir ;
587
597
}
@@ -1414,9 +1424,20 @@ else if (schema instanceof ComposedSchema) {
1414
1424
}
1415
1425
}
1416
1426
}
1427
+
1428
+ final List <Schema > oneOf = composed .getOneOf ();
1429
+ if (oneOf != null && !oneOf .isEmpty ()) {
1430
+ if (schema .getDiscriminator () != null ) {
1431
+ codegenModel .discriminator = schema .getDiscriminator ();
1432
+ if (codegenModel .discriminator != null && codegenModel .discriminator .getPropertyName () != null ) {
1433
+ codegenModel .discriminator .setPropertyName (toVarName (codegenModel .discriminator .getPropertyName ()));
1434
+ }
1435
+ }
1436
+ }
1437
+
1417
1438
if (parent != null ) {
1418
1439
codegenModel .parentSchema = parentName ;
1419
- codegenModel .parent = toModelName (parentName );
1440
+ codegenModel .parent = typeMapping . containsKey ( parentName ) ? typeMapping . get ( parentName ): toModelName (parentName );
1420
1441
addImport (codegenModel , codegenModel .parent );
1421
1442
if (allDefinitions != null ) {
1422
1443
if (supportsInheritance ) {
@@ -2144,8 +2165,6 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
2144
2165
requiredParams .add (formParameter .copy ());
2145
2166
}
2146
2167
allParams .add (formParameter );
2147
-
2148
- codegenContent .getParameters ().add (formParameter .copy ());
2149
2168
}
2150
2169
codegenContents .add (codegenContent );
2151
2170
}
@@ -2167,7 +2186,6 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
2167
2186
}
2168
2187
}
2169
2188
foundSchemas .add (schema );
2170
- codegenContent .getParameters ().add (bodyParam .copy ());
2171
2189
codegenContents .add (codegenContent );
2172
2190
}
2173
2191
}
@@ -2399,8 +2417,11 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
2399
2417
codegenParameter .vendorExtensions .putAll (parameter .getExtensions ());
2400
2418
}
2401
2419
2402
- if (parameter .getSchema () != null ) {
2403
- Schema parameterSchema = parameter .getSchema ();
2420
+ Schema parameterSchema = parameter .getSchema ();
2421
+ if (parameterSchema == null ) {
2422
+ parameterSchema = getSchemaFromParameter (parameter );
2423
+ }
2424
+ if (parameterSchema != null ) {
2404
2425
String collectionFormat = null ;
2405
2426
if (parameterSchema instanceof ArraySchema ) { // for array parameter
2406
2427
final ArraySchema arraySchema = (ArraySchema ) parameterSchema ;
@@ -2410,6 +2431,9 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
2410
2431
inner = new StringSchema ().description ("//TODO automatically added by swagger-codegen" );
2411
2432
arraySchema .setItems (inner );
2412
2433
2434
+ } else if (isObjectSchema (inner )) {
2435
+ //fixme: codegenParameter.getVendorExtensions().put(CodegenConstants.HAS_INNER_OBJECT_NAME, Boolean.TRUE);
2436
+ codegenParameter .getVendorExtensions ().put ("x-has-inner-object" , Boolean .TRUE );
2413
2437
}
2414
2438
2415
2439
collectionFormat = getCollectionFormat (parameter );
@@ -2662,6 +2686,9 @@ else if (schema instanceof ArraySchema) {
2662
2686
if (inner == null ) {
2663
2687
inner = new StringSchema ().description ("//TODO automatically added by swagger-codegen" );
2664
2688
arraySchema .setItems (inner );
2689
+ } else if (isObjectSchema (inner )) {
2690
+ //fixme: codegenParameter.getVendorExtensions().put(CodegenConstants.HAS_INNER_OBJECT_NAME, Boolean.TRUE);
2691
+ codegenParameter .getVendorExtensions ().put ("x-has-inner-object" , Boolean .TRUE );
2665
2692
}
2666
2693
2667
2694
CodegenProperty codegenProperty = fromProperty ("property" , schema );
@@ -3051,7 +3078,7 @@ protected void addImport(CodegenModel m, String type) {
3051
3078
}
3052
3079
}
3053
3080
3054
- private void addVars (CodegenModel codegenModel , Map <String , Schema > properties , List <String > required ) {
3081
+ protected void addVars (CodegenModel codegenModel , Map <String , Schema > properties , List <String > required ) {
3055
3082
addVars (codegenModel , properties , required , null , null );
3056
3083
}
3057
3084
@@ -3962,6 +3989,21 @@ protected Schema getSchemaFromResponse(ApiResponse response) {
3962
3989
return schema ;
3963
3990
}
3964
3991
3992
+ protected Schema getSchemaFromParameter (Parameter parameter ) {
3993
+ if (parameter .getContent () == null || parameter .getContent ().isEmpty ()) {
3994
+ return null ;
3995
+ }
3996
+ Schema schema = null ;
3997
+ for (String contentType : parameter .getContent ().keySet ()) {
3998
+ schema = parameter .getContent ().get (contentType ).getSchema ();
3999
+ if (schema != null ) {
4000
+ schema .addExtension ("x-content-type" , contentType );
4001
+ }
4002
+ break ;
4003
+ }
4004
+ return schema ;
4005
+ }
4006
+
3965
4007
protected Parameter getParameterFromRef (String ref , OpenAPI openAPI ) {
3966
4008
String parameterName = ref .substring (ref .lastIndexOf ('/' ) + 1 );
3967
4009
Map <String , Parameter > parameterMap = openAPI .getComponents ().getParameters ();
@@ -4237,7 +4279,7 @@ protected void configuresParameterForMediaType(CodegenOperation codegenOperation
4237
4279
codegenOperation .getContents ().add (content );
4238
4280
return ;
4239
4281
}
4240
- this .addCodegenContentParemeters (codegenOperation , codegenContents );
4282
+ this .addCodegenContentParameters (codegenOperation , codegenContents );
4241
4283
for (CodegenContent content : codegenContents ) {
4242
4284
if (ensureUniqueParams ) {
4243
4285
ensureUniqueParameters (content .getParameters ());
@@ -4259,7 +4301,7 @@ protected void configuresParameterForMediaType(CodegenOperation codegenOperation
4259
4301
codegenOperation .getContents ().addAll (codegenContents );
4260
4302
}
4261
4303
4262
- protected void addParemeters (CodegenContent codegenContent , List <CodegenParameter > codegenParameters ) {
4304
+ protected void addParameters (CodegenContent codegenContent , List <CodegenParameter > codegenParameters ) {
4263
4305
if (codegenParameters == null || codegenParameters .isEmpty ()) {
4264
4306
return ;
4265
4307
}
@@ -4268,12 +4310,13 @@ protected void addParemeters(CodegenContent codegenContent, List<CodegenParamete
4268
4310
}
4269
4311
}
4270
4312
4271
- protected void addCodegenContentParemeters (CodegenOperation codegenOperation , List <CodegenContent > codegenContents ) {
4313
+ protected void addCodegenContentParameters (CodegenOperation codegenOperation , List <CodegenContent > codegenContents ) {
4272
4314
for (CodegenContent content : codegenContents ) {
4273
- addParemeters (content , codegenOperation .headerParams );
4274
- addParemeters (content , codegenOperation .queryParams );
4275
- addParemeters (content , codegenOperation .pathParams );
4276
- addParemeters (content , codegenOperation .cookieParams );
4315
+ addParameters (content , codegenOperation .bodyParams );
4316
+ addParameters (content , codegenOperation .headerParams );
4317
+ addParameters (content , codegenOperation .queryParams );
4318
+ addParameters (content , codegenOperation .pathParams );
4319
+ addParameters (content , codegenOperation .cookieParams );
4277
4320
}
4278
4321
}
4279
4322
0 commit comments