|
20 | 20 | import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyLanguageSpecificPrimitivesCsv;
|
21 | 21 | import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyTypeMappingsKvp;
|
22 | 22 | import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyReservedWordsMappingsKvp;
|
| 23 | +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyAdditionalPropertiesKvpList; |
| 24 | +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyImportMappingsKvpList; |
| 25 | +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyInstantiationTypesKvpList; |
| 26 | +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyLanguageSpecificPrimitivesCsvList; |
| 27 | +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyTypeMappingsKvpList; |
| 28 | +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyReservedWordsMappingsKvpList; |
23 | 29 | import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
24 | 30 |
|
25 | 31 | import java.io.File;
|
@@ -178,9 +184,42 @@ public class CodeGenMojo extends AbstractMojo {
|
178 | 184 | @Parameter(name = "configOptions")
|
179 | 185 | private Map<?, ?> configOptions;
|
180 | 186 |
|
| 187 | + /** |
| 188 | + * A map of types and the types they should be instantiated as |
| 189 | + */ |
| 190 | + @Parameter(name = "instantiationTypes") |
| 191 | + private List<String> instantiationTypes; |
| 192 | + |
| 193 | + /** |
| 194 | + * A map of classes and the import that should be used for that class |
| 195 | + */ |
181 | 196 | @Parameter(name = "importMappings")
|
182 | 197 | private List<String> importMappings;
|
183 | 198 |
|
| 199 | + /** |
| 200 | + * A map of swagger spec types and the generated code types to use for them |
| 201 | + */ |
| 202 | + @Parameter(name = "typeMappings") |
| 203 | + private List<String> typeMappings; |
| 204 | + |
| 205 | + /** |
| 206 | + * A map of additional language specific primitive types |
| 207 | + */ |
| 208 | + @Parameter(name = "languageSpecificPrimitives") |
| 209 | + private List<String> languageSpecificPrimitives; |
| 210 | + |
| 211 | + /** |
| 212 | + * A map of additional properties that can be referenced by the mustache templates |
| 213 | + */ |
| 214 | + @Parameter(name = "additionalProperties") |
| 215 | + private List<String> additionalProperties; |
| 216 | + |
| 217 | + /** |
| 218 | + * A map of reserved names and how they should be escaped |
| 219 | + */ |
| 220 | + @Parameter(name = "reservedWordsMappings") |
| 221 | + private List<String> reservedWordsMappings; |
| 222 | + |
184 | 223 | /**
|
185 | 224 | * Generate the apis
|
186 | 225 | */
|
@@ -390,42 +429,70 @@ public void execute() throws MojoExecutionException {
|
390 | 429 | System.setProperty("withXml", withXml.toString());
|
391 | 430 |
|
392 | 431 | if (configOptions != null) {
|
393 |
| - |
394 |
| - if (configOptions.containsKey("instantiation-types")) { |
| 432 | + // Retained for backwards-compataibility with configOptions -> instantiation-types |
| 433 | + if (instantiationTypes == null && configOptions.containsKey("instantiation-types")) { |
395 | 434 | applyInstantiationTypesKvp(configOptions.get("instantiation-types").toString(),
|
396 | 435 | configurator);
|
397 | 436 | }
|
398 | 437 |
|
| 438 | + // Retained for backwards-compataibility with configOptions -> import-mappings |
399 | 439 | if (importMappings == null && configOptions.containsKey("import-mappings")) {
|
400 | 440 | applyImportMappingsKvp(configOptions.get("import-mappings").toString(),
|
401 | 441 | configurator);
|
402 | 442 | }
|
403 | 443 |
|
404 |
| - if (configOptions.containsKey("type-mappings")) { |
| 444 | + // Retained for backwards-compataibility with configOptions -> type-mappings |
| 445 | + if (typeMappings == null && configOptions.containsKey("type-mappings")) { |
405 | 446 | applyTypeMappingsKvp(configOptions.get("type-mappings").toString(), configurator);
|
406 | 447 | }
|
407 | 448 |
|
408 |
| - if (configOptions.containsKey("language-specific-primitives")) { |
| 449 | + // Retained for backwards-compataibility with configOptions -> language-specific-primitives |
| 450 | + if (languageSpecificPrimitives == null && configOptions.containsKey("language-specific-primitives")) { |
409 | 451 | applyLanguageSpecificPrimitivesCsv(configOptions
|
410 | 452 | .get("language-specific-primitives").toString(), configurator);
|
411 | 453 | }
|
412 | 454 |
|
413 |
| - if (configOptions.containsKey("additional-properties")) { |
| 455 | + // Retained for backwards-compataibility with configOptions -> additional-properties |
| 456 | + if (additionalProperties == null && configOptions.containsKey("additional-properties")) { |
414 | 457 | applyAdditionalPropertiesKvp(configOptions.get("additional-properties").toString(),
|
415 | 458 | configurator);
|
416 | 459 | }
|
417 | 460 |
|
418 |
| - if (configOptions.containsKey("reserved-words-mappings")) { |
| 461 | + // Retained for backwards-compataibility with configOptions -> reserved-words-mappings |
| 462 | + if (reservedWordsMappings == null && configOptions.containsKey("reserved-words-mappings")) { |
419 | 463 | applyReservedWordsMappingsKvp(configOptions.get("reserved-words-mappings")
|
420 | 464 | .toString(), configurator);
|
421 | 465 | }
|
422 | 466 | }
|
423 | 467 |
|
| 468 | + //Apply Instantiation Types |
| 469 | + if (instantiationTypes != null && !configOptions.containsKey("instantiation-types")) { |
| 470 | + applyInstantiationTypesKvpList(instantiationTypes, configurator); |
| 471 | + } |
| 472 | + |
| 473 | + //Apply Import Mappings |
424 | 474 | if (importMappings != null && !configOptions.containsKey("import-mappings")) {
|
425 |
| - String importMappingsAsString = importMappings.toString(); |
426 |
| - applyImportMappingsKvp( |
427 |
| - importMappingsAsString.substring(0, importMappingsAsString.length() - 1), |
428 |
| - configurator); |
| 475 | + applyImportMappingsKvpList(importMappings, configurator); |
| 476 | + } |
| 477 | + |
| 478 | + //Apply Type Mappings |
| 479 | + if (typeMappings != null && !configOptions.containsKey("type-mappings")) { |
| 480 | + applyTypeMappingsKvpList(typeMappings, configurator); |
| 481 | + } |
| 482 | + |
| 483 | + //Apply Language Specific Primitives |
| 484 | + if (languageSpecificPrimitives != null && !configOptions.containsKey("language-specific-primitives")) { |
| 485 | + applyLanguageSpecificPrimitivesCsvList(languageSpecificPrimitives, configurator); |
| 486 | + } |
| 487 | + |
| 488 | + //Apply Additional Properties |
| 489 | + if (additionalProperties != null && !configOptions.containsKey("additional-properties")) { |
| 490 | + applyAdditionalPropertiesKvpList(additionalProperties, configurator); |
| 491 | + } |
| 492 | + |
| 493 | + //Apply Reserved Words Mappings |
| 494 | + if (reservedWordsMappings != null && !configOptions.containsKey("reserved-words-mappings")) { |
| 495 | + applyReservedWordsMappingsKvpList(reservedWordsMappings, configurator); |
429 | 496 | }
|
430 | 497 |
|
431 | 498 | if (environmentVariables != null) {
|
|
0 commit comments