File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed
main/java/io/swagger/codegen/v3/generators
test/java/io/swagger/codegen/v3/generators/java Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -171,6 +171,7 @@ public abstract class DefaultCodegenConfig implements CodegenConfig {
171
171
protected String ignoreFilePathOverride ;
172
172
protected boolean useOas2 = false ;
173
173
protected boolean copyFistAllOfProperties = false ;
174
+ protected boolean ignoreImportMapping ;
174
175
175
176
public List <CliOption > cliOptions () {
176
177
return cliOptions ;
@@ -181,6 +182,12 @@ public void processOpts() {
181
182
this .setTemplateDir ((String ) additionalProperties .get (CodegenConstants .TEMPLATE_DIR ));
182
183
}
183
184
185
+ if (additionalProperties .get (CodegenConstants .IGNORE_IMPORT_MAPPING_OPTION ) != null ) {
186
+ setIgnoreImportMapping (Boolean .parseBoolean ( additionalProperties .get (CodegenConstants .IGNORE_IMPORT_MAPPING_OPTION ).toString ()));
187
+ } else {
188
+ setIgnoreImportMapping (defaultIgnoreImportMappingOption ());
189
+ }
190
+
184
191
if (additionalProperties .containsKey (CodegenConstants .TEMPLATE_VERSION )) {
185
192
this .setTemplateVersion ((String ) additionalProperties .get (CodegenConstants .TEMPLATE_VERSION ));
186
193
}
@@ -4264,7 +4271,15 @@ public void setUnflattenedOpenAPI(OpenAPI unflattenedOpenAPI) {
4264
4271
this .unflattenedOpenAPI = unflattenedOpenAPI ;
4265
4272
}
4266
4273
4267
- public boolean ignoreImportMapping () {
4274
+ public boolean getIgnoreImportMapping () {
4275
+ return ignoreImportMapping ;
4276
+ }
4277
+
4278
+ public void setIgnoreImportMapping (boolean ignoreImportMapping ) {
4279
+ this .ignoreImportMapping = ignoreImportMapping ;
4280
+ }
4281
+
4282
+ public boolean defaultIgnoreImportMappingOption () {
4268
4283
return false ;
4269
4284
}
4270
4285
}
Original file line number Diff line number Diff line change @@ -598,6 +598,13 @@ public String toParamName(String name) {
598
598
599
599
@ Override
600
600
public String toModelName (final String name ) {
601
+ // We need to check if import-mapping has a different model for this class, so we use it
602
+ // instead of the auto-generated one.
603
+ System .out .println ("getIgnoreImportMapping() => " + getIgnoreImportMapping ());
604
+
605
+ if (!getIgnoreImportMapping () && importMapping .containsKey (name )) {
606
+ return importMapping .get (name );
607
+ }
601
608
final String sanitizedName = sanitizeName (name );
602
609
603
610
String nameWithPrefixSuffix = sanitizedName ;
@@ -1445,7 +1452,7 @@ public void setLanguageArguments(List<CodegenArgument> languageArguments) {
1445
1452
}
1446
1453
1447
1454
@ Override
1448
- public boolean ignoreImportMapping () {
1455
+ public boolean defaultIgnoreImportMappingOption () {
1449
1456
return true ;
1450
1457
}
1451
1458
}
Original file line number Diff line number Diff line change @@ -272,6 +272,7 @@ public void customTemplates() throws Exception {
272
272
public void testModelNamedFile () {
273
273
final OpenAPI openAPI = getOpenAPI ("3_0_0/model_named_file.yaml" );
274
274
final CodegenConfig config = new JavaClientCodegen ();
275
+ config .setIgnoreImportMapping (true );
275
276
config .preprocessOpenAPI (openAPI );
276
277
277
278
final Schema modelFile = openAPI .getComponents ().getSchemas ().get ("File" );
@@ -285,7 +286,7 @@ public void testModelNamedFile() {
285
286
286
287
final List <CodegenProperty > codegenProperties = codegenModelSetting .getVars ();
287
288
288
- Assert .assertEquals (codegenProperties .size (), 2 );
289
+ Assert .assertEquals (codegenProperties .size (), 4 );
289
290
290
291
CodegenProperty fileProperty = codegenProperties .stream ().filter (property -> property .name .equals ("file" )).findAny ().get ();
291
292
You can’t perform that action at this time.
0 commit comments