Rename inlineSchemaNameDefaults to inlineSchemaOptions (#16048)

* rename InlineSchemaNameDefaults to InlineSchemaOptions

* update doc

* rename options
This commit is contained in:
William Cheng 2023-07-11 18:07:09 +08:00 committed by GitHub
parent 7b3681af47
commit 0a6671044f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 108 additions and 110 deletions

View File

@ -445,15 +445,14 @@ For example, to name the inline schema `meta_200_response` as `MetaObject`, use
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/3_0/inline_model_resolver.yaml -o /tmp/java3/ --skip-validate-spec --inline-schema-name-mappings meta_200_response=MetaObject,arbitraryObjectRequestBodyProperty_request=ArbitraryRequest java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/3_0/inline_model_resolver.yaml -o /tmp/java3/ --skip-validate-spec --inline-schema-name-mappings meta_200_response=MetaObject,arbitraryObjectRequestBodyProperty_request=ArbitraryRequest
``` ```
Another useful option is `inlineSchemaNameDefaults`, which allows you to customize the suffix of the auto-generated inline schema name, e.g. in CLI Another useful option is `inlineSchemaOptions`, which allows you to customize how inline schemas are handled or named
``` ```
--inline-schema-name-defaults arrayItemSuffix=_array_item,mapItemSuffix=_map_item --inline-schema-options ARRAY_ITEM_SUFFIX=_array_item,MAP_ITEM_SUFFIX=_map_item,RESOLVE_INLINE_ENUMS=true
``` ```
Note: Only arrayItemSuffix, mapItemSuffix are supported at the moment. - `ARRAY_ITEM_SUFFIX` sets the array item suffix
- `MAP_ITEM_SUFFIX` set the map item suffix
There are 2 special values: - `SKIP_SCHEMA_REUSE=true` is a special value to skip reusing inline schemas during refactoring
- `SKIP_SCHEMA_REUSE=true` is a special value to skip reusing inline schemas.
- `REFACTOR_ALLOF_INLINE_SCHEMAS=true` will restore the 6.x (or below) behaviour to refactor allOf inline schemas into $ref. (v7.0.0 will skip the refactoring of these allOf inline schmeas by default) - `REFACTOR_ALLOF_INLINE_SCHEMAS=true` will restore the 6.x (or below) behaviour to refactor allOf inline schemas into $ref. (v7.0.0 will skip the refactoring of these allOf inline schmeas by default)
- `RESOLVE_INLINE_ENUMS=true` will refactor inline enum definitions into $ref - `RESOLVE_INLINE_ENUMS=true` will refactor inline enum definitions into $ref

View File

@ -77,8 +77,8 @@ public class ConfigHelp extends OpenApiGeneratorCommand {
@Option(name = {"--inline-schema-name-mappings"}, title = "inline schema name mappings", description = "displays the inline schema name mappings (none)") @Option(name = {"--inline-schema-name-mappings"}, title = "inline schema name mappings", description = "displays the inline schema name mappings (none)")
private Boolean inlineSchemaNameMappings; private Boolean inlineSchemaNameMappings;
@Option(name = {"--inline-schema-name-defaults"}, title = "inline schema name defaults", description = "default values used when naming inline schema name") @Option(name = {"--inline-schema-options"}, title = "inline schema options", description = "options for handling inline schemas in inline model resolver")
private Boolean inlineSchemaNameDefaults; private Boolean inlineSchemaOptions;
@Option(name = {"--openapi-normalizer"}, title = "openapi normalizer rules", description = "displays the OpenAPI normalizer rules (none)") @Option(name = {"--openapi-normalizer"}, title = "openapi normalizer rules", description = "displays the OpenAPI normalizer rules (none)")
private Boolean openapiNormalizer; private Boolean openapiNormalizer;
@ -485,15 +485,15 @@ public class ConfigHelp extends OpenApiGeneratorCommand {
sb.append(newline); sb.append(newline);
} }
if (Boolean.TRUE.equals(inlineSchemaNameDefaults)) { if (Boolean.TRUE.equals(inlineSchemaOptions)) {
sb.append(newline).append("INLINE SCHEMA NAME DEFAULTS").append(newline).append(newline); sb.append(newline).append("INLINE SCHEMA OPTIONS").append(newline).append(newline);
Map<String, String> map = config.inlineSchemaNameDefault() Map<String, String> map = config.inlineSchemaOption()
.entrySet() .entrySet()
.stream() .stream()
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> { .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> {
throw new IllegalStateException(String.format(Locale.ROOT, "Duplicated options! %s and %s", a, b)); throw new IllegalStateException(String.format(Locale.ROOT, "Duplicated options! %s and %s", a, b));
}, TreeMap::new)); }, TreeMap::new));
writePlainTextFromMap(sb, map, optIndent, optNestedIndent, "Inline scheme naming convention", "Defaulted to"); writePlainTextFromMap(sb, map, optIndent, optNestedIndent, "Inline scheme options", "Defaulted to");
sb.append(newline); sb.append(newline);
} }

View File

@ -182,11 +182,10 @@ public class Generate extends OpenApiGeneratorCommand {
private List<String> inlineSchemaNameMappings = new ArrayList<>(); private List<String> inlineSchemaNameMappings = new ArrayList<>();
@Option( @Option(
name = {"--inline-schema-name-defaults"}, name = {"--inline-schema-optionss"},
title = "inline schema name defaults", title = "inline schema options",
description = "specifies the default values used when naming inline schema as such array items in the format of arrayItemSuffix=_inner,mapItemSuffix=_value. " description = "specifies the options for handling inline schemas in the inline model resolver.")
+ " ONLY arrayItemSuffix, mapItemSuffix are supported at the moment. `SKIP_SCHEMA_REUSE=true` is a special value to skip reusing inline schemas.") private List<String> inlineSchemaOptions = new ArrayList<>();
private List<String> inlineSchemaNameDefaults = new ArrayList<>();
@Option( @Option(
name = {"--openapi-normalizer"}, name = {"--openapi-normalizer"},
@ -467,7 +466,7 @@ public class Generate extends OpenApiGeneratorCommand {
applyImportMappingsKvpList(importMappings, configurator); applyImportMappingsKvpList(importMappings, configurator);
applySchemaMappingsKvpList(schemaMappings, configurator); applySchemaMappingsKvpList(schemaMappings, configurator);
applyInlineSchemaNameMappingsKvpList(inlineSchemaNameMappings, configurator); applyInlineSchemaNameMappingsKvpList(inlineSchemaNameMappings, configurator);
applyInlineSchemaNameDefaultsKvpList(inlineSchemaNameDefaults, configurator); applyInlineSchemaOptionsKvpList(inlineSchemaOptions, configurator);
applyOpenAPINormalizerKvpList(openapiNormalizer, configurator); applyOpenAPINormalizerKvpList(openapiNormalizer, configurator);
applyTypeMappingsKvpList(typeMappings, configurator); applyTypeMappingsKvpList(typeMappings, configurator);
applyAdditionalPropertiesKvpList(additionalProperties, configurator); applyAdditionalPropertiesKvpList(additionalProperties, configurator);

View File

@ -52,7 +52,7 @@ public final class GeneratorSettings implements Serializable {
private final Map<String, String> importMappings; private final Map<String, String> importMappings;
private final Map<String, String> schemaMappings; private final Map<String, String> schemaMappings;
private final Map<String, String> inlineSchemaNameMappings; private final Map<String, String> inlineSchemaNameMappings;
private final Map<String, String> inlineSchemaNameDefaults; private final Map<String, String> inlineSchemaOptions;
private final Map<String, String> openapiNormalizer; private final Map<String, String> openapiNormalizer;
private final Set<String> languageSpecificPrimitives; private final Set<String> languageSpecificPrimitives;
private final Map<String, String> reservedWordsMappings; private final Map<String, String> reservedWordsMappings;
@ -257,12 +257,12 @@ public final class GeneratorSettings implements Serializable {
} }
/** /**
* Gets inline schema name defaults between an inline schema naming convention and the default values. * Gets inline schema options
* *
* @return the inline schema name defaults * @return the inline schema options
*/ */
public Map<String, String> getInlineSchemaNameDefaults() { public Map<String, String> getInlineSchemaOptions() {
return inlineSchemaNameDefaults; return inlineSchemaOptions;
} }
/** /**
@ -391,7 +391,7 @@ public final class GeneratorSettings implements Serializable {
importMappings = Collections.unmodifiableMap(builder.importMappings); importMappings = Collections.unmodifiableMap(builder.importMappings);
schemaMappings = Collections.unmodifiableMap(builder.schemaMappings); schemaMappings = Collections.unmodifiableMap(builder.schemaMappings);
inlineSchemaNameMappings = Collections.unmodifiableMap(builder.inlineSchemaNameMappings); inlineSchemaNameMappings = Collections.unmodifiableMap(builder.inlineSchemaNameMappings);
inlineSchemaNameDefaults = Collections.unmodifiableMap(builder.inlineSchemaNameDefaults); inlineSchemaOptions = Collections.unmodifiableMap(builder.inlineSchemaOptions);
openapiNormalizer = Collections.unmodifiableMap(builder.openapiNormalizer); openapiNormalizer = Collections.unmodifiableMap(builder.openapiNormalizer);
languageSpecificPrimitives = Collections.unmodifiableSet(builder.languageSpecificPrimitives); languageSpecificPrimitives = Collections.unmodifiableSet(builder.languageSpecificPrimitives);
reservedWordsMappings = Collections.unmodifiableMap(builder.reservedWordsMappings); reservedWordsMappings = Collections.unmodifiableMap(builder.reservedWordsMappings);
@ -465,7 +465,7 @@ public final class GeneratorSettings implements Serializable {
importMappings = Collections.unmodifiableMap(new HashMap<>(0)); importMappings = Collections.unmodifiableMap(new HashMap<>(0));
schemaMappings = Collections.unmodifiableMap(new HashMap<>(0)); schemaMappings = Collections.unmodifiableMap(new HashMap<>(0));
inlineSchemaNameMappings = Collections.unmodifiableMap(new HashMap<>(0)); inlineSchemaNameMappings = Collections.unmodifiableMap(new HashMap<>(0));
inlineSchemaNameDefaults = Collections.unmodifiableMap(new HashMap<>(0)); inlineSchemaOptions = Collections.unmodifiableMap(new HashMap<>(0));
openapiNormalizer = Collections.unmodifiableMap(new HashMap<>(0)); openapiNormalizer = Collections.unmodifiableMap(new HashMap<>(0));
languageSpecificPrimitives = Collections.unmodifiableSet(new HashSet<>(0)); languageSpecificPrimitives = Collections.unmodifiableSet(new HashSet<>(0));
reservedWordsMappings = Collections.unmodifiableMap(new HashMap<>(0)); reservedWordsMappings = Collections.unmodifiableMap(new HashMap<>(0));
@ -524,8 +524,8 @@ public final class GeneratorSettings implements Serializable {
if (copy.getInlineSchemaNameMappings() != null) { if (copy.getInlineSchemaNameMappings() != null) {
builder.inlineSchemaNameMappings.putAll(copy.getInlineSchemaNameMappings()); builder.inlineSchemaNameMappings.putAll(copy.getInlineSchemaNameMappings());
} }
if (copy.getInlineSchemaNameDefaults() != null) { if (copy.getInlineSchemaOptions() != null) {
builder.inlineSchemaNameDefaults.putAll(copy.getInlineSchemaNameDefaults()); builder.inlineSchemaOptions.putAll(copy.getInlineSchemaOptions());
} }
if (copy.getOpenAPINormalizer() != null) { if (copy.getOpenAPINormalizer() != null) {
builder.openapiNormalizer.putAll(copy.getOpenAPINormalizer()); builder.openapiNormalizer.putAll(copy.getOpenAPINormalizer());
@ -571,7 +571,7 @@ public final class GeneratorSettings implements Serializable {
private Map<String, String> importMappings; private Map<String, String> importMappings;
private Map<String, String> schemaMappings; private Map<String, String> schemaMappings;
private Map<String, String> inlineSchemaNameMappings; private Map<String, String> inlineSchemaNameMappings;
private Map<String, String> inlineSchemaNameDefaults; private Map<String, String> inlineSchemaOptions;
private Map<String, String> openapiNormalizer; private Map<String, String> openapiNormalizer;
private Set<String> languageSpecificPrimitives; private Set<String> languageSpecificPrimitives;
private Map<String, String> reservedWordsMappings; private Map<String, String> reservedWordsMappings;
@ -592,7 +592,7 @@ public final class GeneratorSettings implements Serializable {
importMappings = new HashMap<>(); importMappings = new HashMap<>();
schemaMappings = new HashMap<>(); schemaMappings = new HashMap<>();
inlineSchemaNameMappings = new HashMap<>(); inlineSchemaNameMappings = new HashMap<>();
inlineSchemaNameDefaults = new HashMap<>(); inlineSchemaOptions = new HashMap<>();
openapiNormalizer = new HashMap<>(); openapiNormalizer = new HashMap<>();
languageSpecificPrimitives = new HashSet<>(); languageSpecificPrimitives = new HashSet<>();
reservedWordsMappings = new HashMap<>(); reservedWordsMappings = new HashMap<>();
@ -863,28 +863,28 @@ public final class GeneratorSettings implements Serializable {
} }
/** /**
* Sets the {@code inlineSchemaNameDefaults} and returns a reference to this Builder so that the methods can be chained together. * Sets the {@code inlineSchemaOptions} and returns a reference to this Builder so that the methods can be chained together.
* *
* @param inlineSchemaNameDefaults the {@code inlineSchemaNameDefaults} to set * @param inlineSchemaOptions the {@code inlineSchemaOptions} to set
* @return a reference to this Builder * @return a reference to this Builder
*/ */
public Builder withInlineSchemaNameDefaults(Map<String, String> inlineSchemaNameDefaults) { public Builder withInlineSchemaOptions(Map<String, String> inlineSchemaOptions) {
this.inlineSchemaNameDefaults = inlineSchemaNameDefaults; this.inlineSchemaOptions = inlineSchemaOptions;
return this; return this;
} }
/** /**
* Sets a single {@code inlineSchemaNameDefaults} and returns a reference to this Builder so that the methods can be chained together. * Sets a single {@code inlineSchemaOptions} and returns a reference to this Builder so that the methods can be chained together.
* *
* @param key Default naming convention * @param key Inline schema option
* @param value The value * @param value The value
* @return a reference to this Builder * @return a reference to this Builder
*/ */
public Builder withInlineSchemaNameDefault(String key, String value) { public Builder withInlineSchemaOption(String key, String value) {
if (this.inlineSchemaNameDefaults == null) { if (this.inlineSchemaOptions == null) {
this.inlineSchemaNameDefaults = new HashMap<>(); this.inlineSchemaOptions = new HashMap<>();
} }
this.inlineSchemaNameDefaults.put(key, value); this.inlineSchemaOptions.put(key, value);
return this; return this;
} }
@ -1127,7 +1127,7 @@ public final class GeneratorSettings implements Serializable {
Objects.equals(getImportMappings(), that.getImportMappings()) && Objects.equals(getImportMappings(), that.getImportMappings()) &&
Objects.equals(getSchemaMappings(), that.getSchemaMappings()) && Objects.equals(getSchemaMappings(), that.getSchemaMappings()) &&
Objects.equals(getInlineSchemaNameMappings(), that.getInlineSchemaNameMappings()) && Objects.equals(getInlineSchemaNameMappings(), that.getInlineSchemaNameMappings()) &&
Objects.equals(getInlineSchemaNameDefaults(), that.getInlineSchemaNameDefaults()) && Objects.equals(getInlineSchemaOptions(), that.getInlineSchemaOptions()) &&
Objects.equals(getOpenAPINormalizer(), that.getOpenAPINormalizer()) && Objects.equals(getOpenAPINormalizer(), that.getOpenAPINormalizer()) &&
Objects.equals(getLanguageSpecificPrimitives(), that.getLanguageSpecificPrimitives()) && Objects.equals(getLanguageSpecificPrimitives(), that.getLanguageSpecificPrimitives()) &&
Objects.equals(getReservedWordsMappings(), that.getReservedWordsMappings()) && Objects.equals(getReservedWordsMappings(), that.getReservedWordsMappings()) &&
@ -1159,7 +1159,7 @@ public final class GeneratorSettings implements Serializable {
getImportMappings(), getImportMappings(),
getSchemaMappings(), getSchemaMappings(),
getInlineSchemaNameMappings(), getInlineSchemaNameMappings(),
getInlineSchemaNameDefaults(), getInlineSchemaOptions(),
getOpenAPINormalizer(), getOpenAPINormalizer(),
getLanguageSpecificPrimitives(), getLanguageSpecificPrimitives(),
getReservedWordsMappings(), getReservedWordsMappings(),

View File

@ -244,10 +244,10 @@ apply plugin: 'org.openapi.generator'
|None |None
|specifies mappings between the inline schema name and the new name in the format of inline_object_2=Cat,inline_object_5=Bird. |specifies mappings between the inline schema name and the new name in the format of inline_object_2=Cat,inline_object_5=Bird.
|inlineSchemaNameDefaults |inlineSchemaOptions
|Map(String,String) |Map(String,String)
|None |None
|specifies the default values used when naming inline schema as such array items in the format of arrayItemSuffix=_inner,mapItemSuffix=_value. ONLY arrayItemSuffix, mapItemSuffix are supported at the moment. `SKIP_SCHEMA_REUSE=true` is a special value to skip reusing inline schemas. |specifies the options used when handling inline schema in inline model resolver
|additionalProperties |additionalProperties
|Map(String,Any) |Map(String,Any)

View File

@ -118,7 +118,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
importMappings.set(generate.importMappings) importMappings.set(generate.importMappings)
schemaMappings.set(generate.schemaMappings) schemaMappings.set(generate.schemaMappings)
inlineSchemaNameMappings.set(generate.inlineSchemaNameMappings) inlineSchemaNameMappings.set(generate.inlineSchemaNameMappings)
inlineSchemaNameDefaults.set(generate.inlineSchemaNameDefaults) inlineSchemaOptions.set(generate.inlineSchemaOptions)
openapiNormalizer.set(generate.openapiNormalizer) openapiNormalizer.set(generate.openapiNormalizer)
invokerPackage.set(generate.invokerPackage) invokerPackage.set(generate.invokerPackage)
groupId.set(generate.groupId) groupId.set(generate.groupId)

View File

@ -163,9 +163,9 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
val inlineSchemaNameMappings = project.objects.mapProperty<String, String>() val inlineSchemaNameMappings = project.objects.mapProperty<String, String>()
/** /**
* Specifies default values for inline schema naming convention * Specifies options for inline schemas
*/ */
val inlineSchemaNameDefaults = project.objects.mapProperty<String, String>() val inlineSchemaOptions = project.objects.mapProperty<String, String>()
/** /**
* Specifies mappings (rules) in OpenAPI normalizer * Specifies mappings (rules) in OpenAPI normalizer

View File

@ -266,11 +266,11 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
val inlineSchemaNameMappings = project.objects.mapProperty<String, String>() val inlineSchemaNameMappings = project.objects.mapProperty<String, String>()
/** /**
* Specifies default values for inline schema naming convention * Specifies options for inline schemas
*/ */
@Optional @Optional
@Input @Input
val inlineSchemaNameDefaults = project.objects.mapProperty<String, String>() val inlineSchemaOptions = project.objects.mapProperty<String, String>()
/** /**
* Specifies mappings (rules) in OpenAPI normalizer * Specifies mappings (rules) in OpenAPI normalizer
@ -801,9 +801,9 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
} }
} }
if (inlineSchemaNameDefaults.isPresent) { if (inlineSchemaOptions.isPresent) {
inlineSchemaNameDefaults.get().forEach { entry -> inlineSchemaOptions.get().forEach { entry ->
configurator.addInlineSchemaNameDefault(entry.key, entry.value) configurator.addInlineSchemaOption(entry.key, entry.value)
} }
} }

View File

@ -87,7 +87,7 @@ mvn clean compile
| `typeMappings` | `openapi.generator.maven.plugin.typeMappings` | sets mappings between OpenAPI spec types and generated code types in the format of OpenAPIType=generatedType,OpenAPIType=generatedType. For example: `array=List,map=Map,string=String`. You can also have multiple occurrences of this option. To map a specified format, use type+format, e.g. string+password=EncryptedString will map `type: string, format: password` to `EncryptedString`. | `typeMappings` | `openapi.generator.maven.plugin.typeMappings` | sets mappings between OpenAPI spec types and generated code types in the format of OpenAPIType=generatedType,OpenAPIType=generatedType. For example: `array=List,map=Map,string=String`. You can also have multiple occurrences of this option. To map a specified format, use type+format, e.g. string+password=EncryptedString will map `type: string, format: password` to `EncryptedString`.
| `schemaMappings` | `openapi.generator.maven.plugin.schemaMappings` | specifies mappings between the schema and the new name in the format of schema_a=Cat,schema_b=Bird. https://openapi-generator.tech/docs/customization/#schema-mapping | `schemaMappings` | `openapi.generator.maven.plugin.schemaMappings` | specifies mappings between the schema and the new name in the format of schema_a=Cat,schema_b=Bird. https://openapi-generator.tech/docs/customization/#schema-mapping
| `inlineSchemaNameMappings` | `openapi.generator.maven.plugin.inlineSchemaNameMappings` | specifies mappings between the inline schema name and the new name in the format of inline_object_2=Cat,inline_object_5=Bird. | `inlineSchemaNameMappings` | `openapi.generator.maven.plugin.inlineSchemaNameMappings` | specifies mappings between the inline schema name and the new name in the format of inline_object_2=Cat,inline_object_5=Bird.
| `inlineSchemaNameDefaults` | `openapi.generator.maven.plugin.inlineSchemaNameDefaults` | specifies the default values used when naming inline schema as such array items in the format of arrayItemSuffix=_inner,mapItemSuffix=_value. ONLY arrayItemSuffix, mapItemSuffix are supported at the moment. `SKIP_SCHEMA_REUSE=true` is a special value to skip reusing inline schemas. | `inlineSchemaOptions` | `openapi.generator.maven.plugin.inlineSchemaOptions` | specifies the options used when naming inline schema in inline model resolver
| `languageSpecificPrimitives` | `openapi.generator.maven.plugin.languageSpecificPrimitives` | specifies additional language specific primitive types in the format of type1,type2,type3,type3. For example: `String,boolean,Boolean,Double`. You can also have multiple occurrences of this option | `languageSpecificPrimitives` | `openapi.generator.maven.plugin.languageSpecificPrimitives` | specifies additional language specific primitive types in the format of type1,type2,type3,type3. For example: `String,boolean,Boolean,Double`. You can also have multiple occurrences of this option
| `additionalProperties` | `openapi.generator.maven.plugin.additionalProperties` | sets additional properties that can be referenced by the mustache templates in the format of name=value,name=value. You can also have multiple occurrences of this option | `additionalProperties` | `openapi.generator.maven.plugin.additionalProperties` | sets additional properties that can be referenced by the mustache templates in the format of name=value,name=value. You can also have multiple occurrences of this option
| `serverVariableOverrides` | `openapi.generator.maven.plugin.serverVariableOverrides` | A map of server variable overrides for specs that support server URL templating | `serverVariableOverrides` | `openapi.generator.maven.plugin.serverVariableOverrides` | A map of server variable overrides for specs that support server URL templating

View File

@ -327,10 +327,10 @@ public class CodeGenMojo extends AbstractMojo {
private List<String> inlineSchemaNameMappings; private List<String> inlineSchemaNameMappings;
/** /**
* A map of inline scheme naming convention and the value * A map of inline scheme option and the value
*/ */
@Parameter(name = "inlineSchemaNameDefaults", property = "openapi.generator.maven.plugin.inlineSchemaNameDefaults") @Parameter(name = "inlineSchemaOptions", property = "openapi.generator.maven.plugin.inlineSchemaOptions")
private List<String> inlineSchemaNameDefaults; private List<String> inlineSchemaOptions;
/** /**
* A set of rules for OpenAPI normalizer * A set of rules for OpenAPI normalizer
@ -736,9 +736,9 @@ public class CodeGenMojo extends AbstractMojo {
configurator); configurator);
} }
// Retained for backwards-compatibility with configOptions -> inline-schema-name-defaults // Retained for backwards-compatibility with configOptions -> inline-schema-options
if (inlineSchemaNameDefaults == null && configOptions.containsKey("inline-schema-name-defaults")) { if (inlineSchemaOptions == null && configOptions.containsKey("inline-schema-options")) {
applyInlineSchemaNameDefaultsKvp(configOptions.get("inline-schema-name-defaults").toString(), applyInlineSchemaOptionsKvp(configOptions.get("inline-schema-options").toString(),
configurator); configurator);
} }
@ -796,9 +796,9 @@ public class CodeGenMojo extends AbstractMojo {
applyInlineSchemaNameMappingsKvpList(inlineSchemaNameMappings, configurator); applyInlineSchemaNameMappingsKvpList(inlineSchemaNameMappings, configurator);
} }
// Apply Inline Schema Name Defaults // Apply Inline Schema Options
if (inlineSchemaNameDefaults != null && (configOptions == null || !configOptions.containsKey("inline-schema-name-defaults"))) { if (inlineSchemaOptions != null && (configOptions == null || !configOptions.containsKey("inline-schema-options"))) {
applyInlineSchemaNameDefaultsKvpList(inlineSchemaNameDefaults, configurator); applyInlineSchemaOptionsKvpList(inlineSchemaOptions, configurator);
} }
// Apply OpenAPI normalizer rules // Apply OpenAPI normalizer rules

View File

@ -145,7 +145,7 @@ public interface CodegenConfig {
Map<String, String> inlineSchemaNameMapping(); Map<String, String> inlineSchemaNameMapping();
Map<String, String> inlineSchemaNameDefault(); Map<String, String> inlineSchemaOption();
Map<String, String> openapiNormalizer(); Map<String, String> openapiNormalizer();

View File

@ -163,7 +163,7 @@ public class DefaultCodegen implements CodegenConfig {
// a map to store the mapping between inline schema and the name provided by the user // a map to store the mapping between inline schema and the name provided by the user
protected Map<String, String> inlineSchemaNameMapping = new HashMap<>(); protected Map<String, String> inlineSchemaNameMapping = new HashMap<>();
// a map to store the inline schema naming conventions // a map to store the inline schema naming conventions
protected Map<String, String> inlineSchemaNameDefault = new HashMap<>(); protected Map<String, String> inlineSchemaOption = new HashMap<>();
// a map to store the rules in OpenAPI Normalizer // a map to store the rules in OpenAPI Normalizer
protected Map<String, String> openapiNormalizer = new HashMap<>(); protected Map<String, String> openapiNormalizer = new HashMap<>();
protected String modelPackage = "", apiPackage = "", fileSuffix; protected String modelPackage = "", apiPackage = "", fileSuffix;
@ -1194,8 +1194,8 @@ public class DefaultCodegen implements CodegenConfig {
} }
@Override @Override
public Map<String, String> inlineSchemaNameDefault() { public Map<String, String> inlineSchemaOption() {
return inlineSchemaNameDefault; return inlineSchemaOption;
} }
@Override @Override

View File

@ -269,7 +269,7 @@ public class DefaultGenerator implements Generator {
if (config.getUseInlineModelResolver()) { if (config.getUseInlineModelResolver()) {
InlineModelResolver inlineModelResolver = new InlineModelResolver(); InlineModelResolver inlineModelResolver = new InlineModelResolver();
inlineModelResolver.setInlineSchemaNameMapping(config.inlineSchemaNameMapping()); inlineModelResolver.setInlineSchemaNameMapping(config.inlineSchemaNameMapping());
inlineModelResolver.setInlineSchemaNameDefaults(config.inlineSchemaNameDefault()); inlineModelResolver.setInlineSchemaOptions(config.inlineSchemaOption());
inlineModelResolver.flatten(openAPI); inlineModelResolver.flatten(openAPI);
} }

View File

@ -41,7 +41,7 @@ public class InlineModelResolver {
private Map<String, Schema> addedModels = new HashMap<>(); private Map<String, Schema> addedModels = new HashMap<>();
private Map<String, String> generatedSignature = new HashMap<>(); private Map<String, String> generatedSignature = new HashMap<>();
private Map<String, String> inlineSchemaNameMapping = new HashMap<>(); private Map<String, String> inlineSchemaNameMapping = new HashMap<>();
private Map<String, String> inlineSchemaNameDefaults = new HashMap<>(); private Map<String, String> inlineSchemaOptions = new HashMap<>();
private Set<String> inlineSchemaNameMappingValues = new HashSet<>(); private Set<String> inlineSchemaNameMappingValues = new HashSet<>();
public boolean resolveInlineEnums = false; public boolean resolveInlineEnums = false;
public boolean skipSchemaReuse = false; // skip reusing inline schema if set to true public boolean skipSchemaReuse = false; // skip reusing inline schema if set to true
@ -63,8 +63,8 @@ public class InlineModelResolver {
final Logger LOGGER = LoggerFactory.getLogger(InlineModelResolver.class); final Logger LOGGER = LoggerFactory.getLogger(InlineModelResolver.class);
public InlineModelResolver() { public InlineModelResolver() {
this.inlineSchemaNameDefaults.put("arrayItemSuffix", "_inner"); this.inlineSchemaOptions.put("ARRAY_ITEM_SUFFIX", "_inner");
this.inlineSchemaNameDefaults.put("mapItemSuffix", "_value"); this.inlineSchemaOptions.put("MAP_ITEM_SUFFIX", "_value");
} }
public void setInlineSchemaNameMapping(Map inlineSchemaNameMapping) { public void setInlineSchemaNameMapping(Map inlineSchemaNameMapping) {
@ -72,22 +72,22 @@ public class InlineModelResolver {
this.inlineSchemaNameMappingValues = new HashSet<>(inlineSchemaNameMapping.values()); this.inlineSchemaNameMappingValues = new HashSet<>(inlineSchemaNameMapping.values());
} }
public void setInlineSchemaNameDefaults(Map inlineSchemaNameDefaults) { public void setInlineSchemaOptions(Map inlineSchemaOptions) {
this.inlineSchemaNameDefaults.putAll(inlineSchemaNameDefaults); this.inlineSchemaOptions.putAll(inlineSchemaOptions);
if ("true".equalsIgnoreCase( if ("true".equalsIgnoreCase(
this.inlineSchemaNameDefaults.getOrDefault("SKIP_SCHEMA_REUSE", "false"))) { this.inlineSchemaOptions.getOrDefault("SKIP_SCHEMA_REUSE", "false"))) {
this.skipSchemaReuse = true; this.skipSchemaReuse = true;
} }
if (this.inlineSchemaNameDefaults.containsKey("REFACTOR_ALLOF_INLINE_SCHEMAS")) { if (this.inlineSchemaOptions.containsKey("REFACTOR_ALLOF_INLINE_SCHEMAS")) {
this.refactorAllOfInlineSchemas = Boolean.valueOf(this.inlineSchemaNameDefaults.get("REFACTOR_ALLOF_INLINE_SCHEMAS")); this.refactorAllOfInlineSchemas = Boolean.valueOf(this.inlineSchemaOptions.get("REFACTOR_ALLOF_INLINE_SCHEMAS"));
} else { } else {
// not set so default to null; // not set so default to null;
} }
if (this.inlineSchemaNameDefaults.containsKey("RESOLVE_INLINE_ENUMS")) { if (this.inlineSchemaOptions.containsKey("RESOLVE_INLINE_ENUMS")) {
this.resolveInlineEnums = Boolean.valueOf(this.inlineSchemaNameDefaults.get("RESOLVE_INLINE_ENUMS")); this.resolveInlineEnums = Boolean.valueOf(this.inlineSchemaOptions.get("RESOLVE_INLINE_ENUMS"));
} else { } else {
// not set so default to null; // not set so default to null;
} }
@ -306,7 +306,7 @@ public class InlineModelResolver {
if (schema.getAdditionalProperties() != null) { if (schema.getAdditionalProperties() != null) {
if (schema.getAdditionalProperties() instanceof Schema) { if (schema.getAdditionalProperties() instanceof Schema) {
Schema inner = (Schema) schema.getAdditionalProperties(); Schema inner = (Schema) schema.getAdditionalProperties();
String schemaName = resolveModelName(schema.getTitle(), modelPrefix + this.inlineSchemaNameDefaults.get("mapItemSuffix")); String schemaName = resolveModelName(schema.getTitle(), modelPrefix + this.inlineSchemaOptions.get("MAP_ITEM_SUFFIX"));
// Recurse to create $refs for inner models // Recurse to create $refs for inner models
gatherInlineModels(inner, schemaName); gatherInlineModels(inner, schemaName);
if (isModelNeeded(inner)) { if (isModelNeeded(inner)) {
@ -341,7 +341,7 @@ public class InlineModelResolver {
" items must be defined for array schemas:\n " + schema.toString()); " items must be defined for array schemas:\n " + schema.toString());
return; return;
} }
String schemaName = resolveModelName(items.getTitle(), modelPrefix + this.inlineSchemaNameDefaults.get("arrayItemSuffix")); String schemaName = resolveModelName(items.getTitle(), modelPrefix + this.inlineSchemaOptions.get("ARRAY_ITEM_SUFFIX"));
// Recurse to create $refs for inner models // Recurse to create $refs for inner models
gatherInlineModels(items, schemaName); gatherInlineModels(items, schemaName);

View File

@ -70,7 +70,7 @@ public class CodegenConfigurator {
private Map<String, String> importMappings = new HashMap<>(); private Map<String, String> importMappings = new HashMap<>();
private Map<String, String> schemaMappings = new HashMap<>(); private Map<String, String> schemaMappings = new HashMap<>();
private Map<String, String> inlineSchemaNameMappings = new HashMap<>(); private Map<String, String> inlineSchemaNameMappings = new HashMap<>();
private Map<String, String> inlineSchemaNameDefaults = new HashMap<>(); private Map<String, String> inlineSchemaOptions = new HashMap<>();
private Map<String, String> openapiNormalizer = new HashMap<>(); private Map<String, String> openapiNormalizer = new HashMap<>();
private Set<String> languageSpecificPrimitives = new HashSet<>(); private Set<String> languageSpecificPrimitives = new HashSet<>();
private Map<String, String> reservedWordsMappings = new HashMap<>(); private Map<String, String> reservedWordsMappings = new HashMap<>();
@ -121,8 +121,8 @@ public class CodegenConfigurator {
if(generatorSettings.getInlineSchemaNameMappings() != null) { if(generatorSettings.getInlineSchemaNameMappings() != null) {
configurator.inlineSchemaNameMappings.putAll(generatorSettings.getInlineSchemaNameMappings()); configurator.inlineSchemaNameMappings.putAll(generatorSettings.getInlineSchemaNameMappings());
} }
if(generatorSettings.getInlineSchemaNameDefaults() != null) { if(generatorSettings.getInlineSchemaOptions() != null) {
configurator.inlineSchemaNameDefaults.putAll(generatorSettings.getInlineSchemaNameDefaults()); configurator.inlineSchemaOptions.putAll(generatorSettings.getInlineSchemaOptions());
} }
if(generatorSettings.getOpenAPINormalizer() != null) { if(generatorSettings.getOpenAPINormalizer() != null) {
configurator.openapiNormalizer.putAll(generatorSettings.getOpenAPINormalizer()); configurator.openapiNormalizer.putAll(generatorSettings.getOpenAPINormalizer());
@ -208,9 +208,9 @@ public class CodegenConfigurator {
return this; return this;
} }
public CodegenConfigurator addInlineSchemaNameDefault(String key, String value) { public CodegenConfigurator addInlineSchemaOption(String key, String value) {
this.inlineSchemaNameDefaults.put(key, value); this.inlineSchemaOptions.put(key, value);
generatorSettingsBuilder.withInlineSchemaNameDefault(key, value); generatorSettingsBuilder.withInlineSchemaOption(key, value);
return this; return this;
} }
@ -386,9 +386,9 @@ public class CodegenConfigurator {
return this; return this;
} }
public CodegenConfigurator setInlineSchemaNameDefaults(Map<String, String> inlineSchemaNameDefaults) { public CodegenConfigurator setInlineSchemaOptions(Map<String, String> inlineSchemaOptions) {
this.inlineSchemaNameDefaults = inlineSchemaNameDefaults; this.inlineSchemaOptions = inlineSchemaOptions;
generatorSettingsBuilder.withInlineSchemaNameDefaults(inlineSchemaNameDefaults); generatorSettingsBuilder.withInlineSchemaOptions(inlineSchemaOptions);
return this; return this;
} }
@ -676,7 +676,7 @@ public class CodegenConfigurator {
config.importMapping().putAll(generatorSettings.getImportMappings()); config.importMapping().putAll(generatorSettings.getImportMappings());
config.schemaMapping().putAll(generatorSettings.getSchemaMappings()); config.schemaMapping().putAll(generatorSettings.getSchemaMappings());
config.inlineSchemaNameMapping().putAll(generatorSettings.getInlineSchemaNameMappings()); config.inlineSchemaNameMapping().putAll(generatorSettings.getInlineSchemaNameMappings());
config.inlineSchemaNameDefault().putAll(generatorSettings.getInlineSchemaNameDefaults()); config.inlineSchemaOption().putAll(generatorSettings.getInlineSchemaOptions());
config.openapiNormalizer().putAll(generatorSettings.getOpenAPINormalizer()); config.openapiNormalizer().putAll(generatorSettings.getOpenAPINormalizer());
config.languageSpecificPrimitives().addAll(generatorSettings.getLanguageSpecificPrimitives()); config.languageSpecificPrimitives().addAll(generatorSettings.getLanguageSpecificPrimitives());
config.reservedWordsMappings().putAll(generatorSettings.getReservedWordsMappings()); config.reservedWordsMappings().putAll(generatorSettings.getReservedWordsMappings());

View File

@ -107,16 +107,16 @@ public final class CodegenConfiguratorUtils {
} }
} }
public static void applyInlineSchemaNameDefaultsKvpList(List<String> inlineSchemaNameDefaults, CodegenConfigurator configurator) { public static void applyInlineSchemaOptionsKvpList(List<String> inlineSchemaOptions, CodegenConfigurator configurator) {
for (String propString : inlineSchemaNameDefaults) { for (String propString : inlineSchemaOptions) {
applyInlineSchemaNameDefaultsKvp(propString, configurator); applyInlineSchemaOptionsKvp(propString, configurator);
} }
} }
public static void applyInlineSchemaNameDefaultsKvp(String inlineSchemaNameDefaults, CodegenConfigurator configurator) { public static void applyInlineSchemaOptionsKvp(String inlineSchemaOptions, CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(inlineSchemaNameDefaults); final Map<String, String> map = createMapFromKeyValuePairs(inlineSchemaOptions);
for (Map.Entry<String, String> entry : map.entrySet()) { for (Map.Entry<String, String> entry : map.entrySet()) {
configurator.addInlineSchemaNameDefault(entry.getKey().trim(), entry.getValue().trim()); configurator.addInlineSchemaOption(entry.getKey().trim(), entry.getValue().trim());
} }
} }

View File

@ -1040,12 +1040,12 @@ public class InlineModelResolverTest {
} }
@Test @Test
public void testInlineSchemaNameDefault() { public void testInlineSchemaOptions() {
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml"); OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
InlineModelResolver resolver = new InlineModelResolver(); InlineModelResolver resolver = new InlineModelResolver();
Map<String, String> inlineSchemaNameDefaults = new HashMap<>(); Map<String, String> inlineSchemaOptions= new HashMap<>();
inlineSchemaNameDefaults.put("arrayItemSuffix", "_something"); inlineSchemaOptions.put("ARRAY_ITEM_SUFFIX", "_something");
resolver.setInlineSchemaNameDefaults(inlineSchemaNameDefaults); resolver.setInlineSchemaOptions(inlineSchemaOptions);
resolver.flatten(openAPI); resolver.flatten(openAPI);
Schema schema = openAPI.getComponents().getSchemas().get("resolveInlineArrayRequestBody_request_something"); Schema schema = openAPI.getComponents().getSchemas().get("resolveInlineArrayRequestBody_request_something");
@ -1060,9 +1060,9 @@ public class InlineModelResolverTest {
public void testInlineSchemaSkipReuseSetToFalse() { public void testInlineSchemaSkipReuseSetToFalse() {
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml"); OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
InlineModelResolver resolver = new InlineModelResolver(); InlineModelResolver resolver = new InlineModelResolver();
Map<String, String> inlineSchemaNameDefaults = new HashMap<>(); Map<String, String> inlineSchemaOptions = new HashMap<>();
//inlineSchemaNameDefaults.put("SKIP_SCHEMA_REUSE", "false"); // default is false //inlineSchemaOptions.put("SKIP_SCHEMA_REUSE", "false"); // default is false
resolver.setInlineSchemaNameDefaults(inlineSchemaNameDefaults); resolver.setInlineSchemaOptions(inlineSchemaOptions);
resolver.flatten(openAPI); resolver.flatten(openAPI);
Schema schema = openAPI.getComponents().getSchemas().get("meta_200_response"); Schema schema = openAPI.getComponents().getSchemas().get("meta_200_response");
@ -1078,9 +1078,9 @@ public class InlineModelResolverTest {
public void testInlineSchemaSkipReuseSetToTrue() { public void testInlineSchemaSkipReuseSetToTrue() {
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml"); OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
InlineModelResolver resolver = new InlineModelResolver(); InlineModelResolver resolver = new InlineModelResolver();
Map<String, String> inlineSchemaNameDefaults = new HashMap<>(); Map<String, String> inlineSchemaOptions = new HashMap<>();
inlineSchemaNameDefaults.put("SKIP_SCHEMA_REUSE", "true"); inlineSchemaOptions.put("SKIP_SCHEMA_REUSE", "true");
resolver.setInlineSchemaNameDefaults(inlineSchemaNameDefaults); resolver.setInlineSchemaOptions(inlineSchemaOptions);
resolver.flatten(openAPI); resolver.flatten(openAPI);
Schema schema = openAPI.getComponents().getSchemas().get("meta_200_response"); Schema schema = openAPI.getComponents().getSchemas().get("meta_200_response");
@ -1138,9 +1138,9 @@ public class InlineModelResolverTest {
assertNull(((ArraySchema) parameter.getSchema()).getItems().get$ref() ); assertNull(((ArraySchema) parameter.getSchema()).getItems().get$ref() );
InlineModelResolver resolver = new InlineModelResolver(); InlineModelResolver resolver = new InlineModelResolver();
Map<String, String> inlineSchemaNameDefaults = new HashMap<>(); Map<String, String> inlineSchemaOptions = new HashMap<>();
inlineSchemaNameDefaults.put("RESOLVE_INLINE_ENUMS", "true"); inlineSchemaOptions.put("RESOLVE_INLINE_ENUMS", "true");
resolver.setInlineSchemaNameDefaults(inlineSchemaNameDefaults); resolver.setInlineSchemaOptions(inlineSchemaOptions);
resolver.flatten(openAPI); resolver.flatten(openAPI);
Parameter parameter2 = openAPI.getPaths().get("/resolve_parameter_inline_enum").getGet().getParameters().get(0); Parameter parameter2 = openAPI.getPaths().get("/resolve_parameter_inline_enum").getGet().getParameters().get(0);
@ -1156,9 +1156,9 @@ public class InlineModelResolverTest {
assertNull(requestBody.get$ref()); assertNull(requestBody.get$ref());
InlineModelResolver resolver = new InlineModelResolver(); InlineModelResolver resolver = new InlineModelResolver();
Map<String, String> inlineSchemaNameDefaults = new HashMap<>(); Map<String, String> inlineSchemaOptions = new HashMap<>();
inlineSchemaNameDefaults.put("RESOLVE_INLINE_ENUMS", "true"); inlineSchemaOptions.put("RESOLVE_INLINE_ENUMS", "true");
resolver.setInlineSchemaNameDefaults(inlineSchemaNameDefaults); resolver.setInlineSchemaOptions(inlineSchemaOptions);
resolver.flatten(openAPI); resolver.flatten(openAPI);
Schema requestBody2 = openAPI.getPaths().get("/resolve_parameter_inline_enum_form_parameters").getPost().getRequestBody().getContent().get("application/x-www-form-urlencoded").getSchema(); Schema requestBody2 = openAPI.getPaths().get("/resolve_parameter_inline_enum_form_parameters").getPost().getRequestBody().getContent().get("application/x-www-form-urlencoded").getSchema();