diff --git a/docs/customization.md b/docs/customization.md index f7148019196..8b368b1695d 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -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 ``` -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. - -There are 2 special values: -- `SKIP_SCHEMA_REUSE=true` is a special value to skip reusing inline schemas. +- `ARRAY_ITEM_SUFFIX` sets the array item suffix +- `MAP_ITEM_SUFFIX` set the map item suffix +- `SKIP_SCHEMA_REUSE=true` is a special value to skip reusing inline schemas during refactoring - `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 diff --git a/modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/ConfigHelp.java b/modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/ConfigHelp.java index 25c1d3cd61c..95a94832fb9 100644 --- a/modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/ConfigHelp.java +++ b/modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/ConfigHelp.java @@ -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)") private Boolean inlineSchemaNameMappings; - @Option(name = {"--inline-schema-name-defaults"}, title = "inline schema name defaults", description = "default values used when naming inline schema name") - private Boolean inlineSchemaNameDefaults; + @Option(name = {"--inline-schema-options"}, title = "inline schema options", description = "options for handling inline schemas in inline model resolver") + private Boolean inlineSchemaOptions; @Option(name = {"--openapi-normalizer"}, title = "openapi normalizer rules", description = "displays the OpenAPI normalizer rules (none)") private Boolean openapiNormalizer; @@ -485,15 +485,15 @@ public class ConfigHelp extends OpenApiGeneratorCommand { sb.append(newline); } - if (Boolean.TRUE.equals(inlineSchemaNameDefaults)) { - sb.append(newline).append("INLINE SCHEMA NAME DEFAULTS").append(newline).append(newline); - Map map = config.inlineSchemaNameDefault() + if (Boolean.TRUE.equals(inlineSchemaOptions)) { + sb.append(newline).append("INLINE SCHEMA OPTIONS").append(newline).append(newline); + Map map = config.inlineSchemaOption() .entrySet() .stream() .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)); }, 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); } diff --git a/modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/Generate.java b/modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/Generate.java index 4bfca92f02b..3cb6ed516fb 100644 --- a/modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/Generate.java +++ b/modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/Generate.java @@ -182,11 +182,10 @@ public class Generate extends OpenApiGeneratorCommand { private List inlineSchemaNameMappings = new ArrayList<>(); @Option( - name = {"--inline-schema-name-defaults"}, - title = "inline schema name defaults", - description = "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.") - private List inlineSchemaNameDefaults = new ArrayList<>(); + name = {"--inline-schema-optionss"}, + title = "inline schema options", + description = "specifies the options for handling inline schemas in the inline model resolver.") + private List inlineSchemaOptions = new ArrayList<>(); @Option( name = {"--openapi-normalizer"}, @@ -467,7 +466,7 @@ public class Generate extends OpenApiGeneratorCommand { applyImportMappingsKvpList(importMappings, configurator); applySchemaMappingsKvpList(schemaMappings, configurator); applyInlineSchemaNameMappingsKvpList(inlineSchemaNameMappings, configurator); - applyInlineSchemaNameDefaultsKvpList(inlineSchemaNameDefaults, configurator); + applyInlineSchemaOptionsKvpList(inlineSchemaOptions, configurator); applyOpenAPINormalizerKvpList(openapiNormalizer, configurator); applyTypeMappingsKvpList(typeMappings, configurator); applyAdditionalPropertiesKvpList(additionalProperties, configurator); diff --git a/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/config/GeneratorSettings.java b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/config/GeneratorSettings.java index 40ea3ccece0..9d3bfec6449 100644 --- a/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/config/GeneratorSettings.java +++ b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/config/GeneratorSettings.java @@ -52,7 +52,7 @@ public final class GeneratorSettings implements Serializable { private final Map importMappings; private final Map schemaMappings; private final Map inlineSchemaNameMappings; - private final Map inlineSchemaNameDefaults; + private final Map inlineSchemaOptions; private final Map openapiNormalizer; private final Set languageSpecificPrimitives; private final Map 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 getInlineSchemaNameDefaults() { - return inlineSchemaNameDefaults; + public Map getInlineSchemaOptions() { + return inlineSchemaOptions; } /** @@ -391,7 +391,7 @@ public final class GeneratorSettings implements Serializable { importMappings = Collections.unmodifiableMap(builder.importMappings); schemaMappings = Collections.unmodifiableMap(builder.schemaMappings); inlineSchemaNameMappings = Collections.unmodifiableMap(builder.inlineSchemaNameMappings); - inlineSchemaNameDefaults = Collections.unmodifiableMap(builder.inlineSchemaNameDefaults); + inlineSchemaOptions = Collections.unmodifiableMap(builder.inlineSchemaOptions); openapiNormalizer = Collections.unmodifiableMap(builder.openapiNormalizer); languageSpecificPrimitives = Collections.unmodifiableSet(builder.languageSpecificPrimitives); reservedWordsMappings = Collections.unmodifiableMap(builder.reservedWordsMappings); @@ -465,7 +465,7 @@ public final class GeneratorSettings implements Serializable { importMappings = Collections.unmodifiableMap(new HashMap<>(0)); schemaMappings = 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)); languageSpecificPrimitives = Collections.unmodifiableSet(new HashSet<>(0)); reservedWordsMappings = Collections.unmodifiableMap(new HashMap<>(0)); @@ -524,8 +524,8 @@ public final class GeneratorSettings implements Serializable { if (copy.getInlineSchemaNameMappings() != null) { builder.inlineSchemaNameMappings.putAll(copy.getInlineSchemaNameMappings()); } - if (copy.getInlineSchemaNameDefaults() != null) { - builder.inlineSchemaNameDefaults.putAll(copy.getInlineSchemaNameDefaults()); + if (copy.getInlineSchemaOptions() != null) { + builder.inlineSchemaOptions.putAll(copy.getInlineSchemaOptions()); } if (copy.getOpenAPINormalizer() != null) { builder.openapiNormalizer.putAll(copy.getOpenAPINormalizer()); @@ -571,7 +571,7 @@ public final class GeneratorSettings implements Serializable { private Map importMappings; private Map schemaMappings; private Map inlineSchemaNameMappings; - private Map inlineSchemaNameDefaults; + private Map inlineSchemaOptions; private Map openapiNormalizer; private Set languageSpecificPrimitives; private Map reservedWordsMappings; @@ -592,7 +592,7 @@ public final class GeneratorSettings implements Serializable { importMappings = new HashMap<>(); schemaMappings = new HashMap<>(); inlineSchemaNameMappings = new HashMap<>(); - inlineSchemaNameDefaults = new HashMap<>(); + inlineSchemaOptions = new HashMap<>(); openapiNormalizer = new HashMap<>(); languageSpecificPrimitives = new HashSet<>(); 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 */ - public Builder withInlineSchemaNameDefaults(Map inlineSchemaNameDefaults) { - this.inlineSchemaNameDefaults = inlineSchemaNameDefaults; + public Builder withInlineSchemaOptions(Map inlineSchemaOptions) { + this.inlineSchemaOptions = inlineSchemaOptions; 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 * @return a reference to this Builder */ - public Builder withInlineSchemaNameDefault(String key, String value) { - if (this.inlineSchemaNameDefaults == null) { - this.inlineSchemaNameDefaults = new HashMap<>(); + public Builder withInlineSchemaOption(String key, String value) { + if (this.inlineSchemaOptions == null) { + this.inlineSchemaOptions = new HashMap<>(); } - this.inlineSchemaNameDefaults.put(key, value); + this.inlineSchemaOptions.put(key, value); return this; } @@ -1127,7 +1127,7 @@ public final class GeneratorSettings implements Serializable { Objects.equals(getImportMappings(), that.getImportMappings()) && Objects.equals(getSchemaMappings(), that.getSchemaMappings()) && Objects.equals(getInlineSchemaNameMappings(), that.getInlineSchemaNameMappings()) && - Objects.equals(getInlineSchemaNameDefaults(), that.getInlineSchemaNameDefaults()) && + Objects.equals(getInlineSchemaOptions(), that.getInlineSchemaOptions()) && Objects.equals(getOpenAPINormalizer(), that.getOpenAPINormalizer()) && Objects.equals(getLanguageSpecificPrimitives(), that.getLanguageSpecificPrimitives()) && Objects.equals(getReservedWordsMappings(), that.getReservedWordsMappings()) && @@ -1159,7 +1159,7 @@ public final class GeneratorSettings implements Serializable { getImportMappings(), getSchemaMappings(), getInlineSchemaNameMappings(), - getInlineSchemaNameDefaults(), + getInlineSchemaOptions(), getOpenAPINormalizer(), getLanguageSpecificPrimitives(), getReservedWordsMappings(), diff --git a/modules/openapi-generator-gradle-plugin/README.adoc b/modules/openapi-generator-gradle-plugin/README.adoc index a59450bc03d..6088f97b7b6 100644 --- a/modules/openapi-generator-gradle-plugin/README.adoc +++ b/modules/openapi-generator-gradle-plugin/README.adoc @@ -244,10 +244,10 @@ apply plugin: 'org.openapi.generator' |None |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) |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 |Map(String,Any) diff --git a/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/OpenApiGeneratorPlugin.kt b/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/OpenApiGeneratorPlugin.kt index 08f92166d31..41da31505fb 100644 --- a/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/OpenApiGeneratorPlugin.kt +++ b/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/OpenApiGeneratorPlugin.kt @@ -118,7 +118,7 @@ class OpenApiGeneratorPlugin : Plugin { importMappings.set(generate.importMappings) schemaMappings.set(generate.schemaMappings) inlineSchemaNameMappings.set(generate.inlineSchemaNameMappings) - inlineSchemaNameDefaults.set(generate.inlineSchemaNameDefaults) + inlineSchemaOptions.set(generate.inlineSchemaOptions) openapiNormalizer.set(generate.openapiNormalizer) invokerPackage.set(generate.invokerPackage) groupId.set(generate.groupId) diff --git a/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorGenerateExtension.kt b/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorGenerateExtension.kt index 0bee2e89881..831e67e3dbf 100644 --- a/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorGenerateExtension.kt +++ b/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorGenerateExtension.kt @@ -163,9 +163,9 @@ open class OpenApiGeneratorGenerateExtension(project: Project) { val inlineSchemaNameMappings = project.objects.mapProperty() /** - * Specifies default values for inline schema naming convention + * Specifies options for inline schemas */ - val inlineSchemaNameDefaults = project.objects.mapProperty() + val inlineSchemaOptions = project.objects.mapProperty() /** * Specifies mappings (rules) in OpenAPI normalizer diff --git a/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt b/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt index 8b3b082d827..ee1995d1ed5 100644 --- a/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt +++ b/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt @@ -266,11 +266,11 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac val inlineSchemaNameMappings = project.objects.mapProperty() /** - * Specifies default values for inline schema naming convention + * Specifies options for inline schemas */ @Optional @Input - val inlineSchemaNameDefaults = project.objects.mapProperty() + val inlineSchemaOptions = project.objects.mapProperty() /** * Specifies mappings (rules) in OpenAPI normalizer @@ -801,9 +801,9 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac } } - if (inlineSchemaNameDefaults.isPresent) { - inlineSchemaNameDefaults.get().forEach { entry -> - configurator.addInlineSchemaNameDefault(entry.key, entry.value) + if (inlineSchemaOptions.isPresent) { + inlineSchemaOptions.get().forEach { entry -> + configurator.addInlineSchemaOption(entry.key, entry.value) } } diff --git a/modules/openapi-generator-maven-plugin/README.md b/modules/openapi-generator-maven-plugin/README.md index 4a0f9293398..02341e78ee4 100644 --- a/modules/openapi-generator-maven-plugin/README.md +++ b/modules/openapi-generator-maven-plugin/README.md @@ -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`. | `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. -| `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 | `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 diff --git a/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java b/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java index f6b31f8f610..a7d091b371b 100644 --- a/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java +++ b/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java @@ -327,10 +327,10 @@ public class CodeGenMojo extends AbstractMojo { private List 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") - private List inlineSchemaNameDefaults; + @Parameter(name = "inlineSchemaOptions", property = "openapi.generator.maven.plugin.inlineSchemaOptions") + private List inlineSchemaOptions; /** * A set of rules for OpenAPI normalizer @@ -736,9 +736,9 @@ public class CodeGenMojo extends AbstractMojo { configurator); } - // Retained for backwards-compatibility with configOptions -> inline-schema-name-defaults - if (inlineSchemaNameDefaults == null && configOptions.containsKey("inline-schema-name-defaults")) { - applyInlineSchemaNameDefaultsKvp(configOptions.get("inline-schema-name-defaults").toString(), + // Retained for backwards-compatibility with configOptions -> inline-schema-options + if (inlineSchemaOptions == null && configOptions.containsKey("inline-schema-options")) { + applyInlineSchemaOptionsKvp(configOptions.get("inline-schema-options").toString(), configurator); } @@ -796,9 +796,9 @@ public class CodeGenMojo extends AbstractMojo { applyInlineSchemaNameMappingsKvpList(inlineSchemaNameMappings, configurator); } - // Apply Inline Schema Name Defaults - if (inlineSchemaNameDefaults != null && (configOptions == null || !configOptions.containsKey("inline-schema-name-defaults"))) { - applyInlineSchemaNameDefaultsKvpList(inlineSchemaNameDefaults, configurator); + // Apply Inline Schema Options + if (inlineSchemaOptions != null && (configOptions == null || !configOptions.containsKey("inline-schema-options"))) { + applyInlineSchemaOptionsKvpList(inlineSchemaOptions, configurator); } // Apply OpenAPI normalizer rules diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java index 9b448b01e66..c3a8832357e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java @@ -145,7 +145,7 @@ public interface CodegenConfig { Map inlineSchemaNameMapping(); - Map inlineSchemaNameDefault(); + Map inlineSchemaOption(); Map openapiNormalizer(); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 67f53af71ff..75fdf38e387 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -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 protected Map inlineSchemaNameMapping = new HashMap<>(); // a map to store the inline schema naming conventions - protected Map inlineSchemaNameDefault = new HashMap<>(); + protected Map inlineSchemaOption = new HashMap<>(); // a map to store the rules in OpenAPI Normalizer protected Map openapiNormalizer = new HashMap<>(); protected String modelPackage = "", apiPackage = "", fileSuffix; @@ -1194,8 +1194,8 @@ public class DefaultCodegen implements CodegenConfig { } @Override - public Map inlineSchemaNameDefault() { - return inlineSchemaNameDefault; + public Map inlineSchemaOption() { + return inlineSchemaOption; } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java index e59f83a47ce..c3083e2462c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java @@ -269,7 +269,7 @@ public class DefaultGenerator implements Generator { if (config.getUseInlineModelResolver()) { InlineModelResolver inlineModelResolver = new InlineModelResolver(); inlineModelResolver.setInlineSchemaNameMapping(config.inlineSchemaNameMapping()); - inlineModelResolver.setInlineSchemaNameDefaults(config.inlineSchemaNameDefault()); + inlineModelResolver.setInlineSchemaOptions(config.inlineSchemaOption()); inlineModelResolver.flatten(openAPI); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java index 17535f024ce..f1f13591903 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java @@ -41,7 +41,7 @@ public class InlineModelResolver { private Map addedModels = new HashMap<>(); private Map generatedSignature = new HashMap<>(); private Map inlineSchemaNameMapping = new HashMap<>(); - private Map inlineSchemaNameDefaults = new HashMap<>(); + private Map inlineSchemaOptions = new HashMap<>(); private Set inlineSchemaNameMappingValues = new HashSet<>(); public boolean resolveInlineEnums = false; 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); public InlineModelResolver() { - this.inlineSchemaNameDefaults.put("arrayItemSuffix", "_inner"); - this.inlineSchemaNameDefaults.put("mapItemSuffix", "_value"); + this.inlineSchemaOptions.put("ARRAY_ITEM_SUFFIX", "_inner"); + this.inlineSchemaOptions.put("MAP_ITEM_SUFFIX", "_value"); } public void setInlineSchemaNameMapping(Map inlineSchemaNameMapping) { @@ -72,22 +72,22 @@ public class InlineModelResolver { this.inlineSchemaNameMappingValues = new HashSet<>(inlineSchemaNameMapping.values()); } - public void setInlineSchemaNameDefaults(Map inlineSchemaNameDefaults) { - this.inlineSchemaNameDefaults.putAll(inlineSchemaNameDefaults); + public void setInlineSchemaOptions(Map inlineSchemaOptions) { + this.inlineSchemaOptions.putAll(inlineSchemaOptions); if ("true".equalsIgnoreCase( - this.inlineSchemaNameDefaults.getOrDefault("SKIP_SCHEMA_REUSE", "false"))) { + this.inlineSchemaOptions.getOrDefault("SKIP_SCHEMA_REUSE", "false"))) { this.skipSchemaReuse = true; } - if (this.inlineSchemaNameDefaults.containsKey("REFACTOR_ALLOF_INLINE_SCHEMAS")) { - this.refactorAllOfInlineSchemas = Boolean.valueOf(this.inlineSchemaNameDefaults.get("REFACTOR_ALLOF_INLINE_SCHEMAS")); + if (this.inlineSchemaOptions.containsKey("REFACTOR_ALLOF_INLINE_SCHEMAS")) { + this.refactorAllOfInlineSchemas = Boolean.valueOf(this.inlineSchemaOptions.get("REFACTOR_ALLOF_INLINE_SCHEMAS")); } else { // not set so default to null; } - if (this.inlineSchemaNameDefaults.containsKey("RESOLVE_INLINE_ENUMS")) { - this.resolveInlineEnums = Boolean.valueOf(this.inlineSchemaNameDefaults.get("RESOLVE_INLINE_ENUMS")); + if (this.inlineSchemaOptions.containsKey("RESOLVE_INLINE_ENUMS")) { + this.resolveInlineEnums = Boolean.valueOf(this.inlineSchemaOptions.get("RESOLVE_INLINE_ENUMS")); } else { // not set so default to null; } @@ -306,7 +306,7 @@ public class InlineModelResolver { if (schema.getAdditionalProperties() != null) { if (schema.getAdditionalProperties() instanceof Schema) { 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 gatherInlineModels(inner, schemaName); if (isModelNeeded(inner)) { @@ -341,7 +341,7 @@ public class InlineModelResolver { " items must be defined for array schemas:\n " + schema.toString()); 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 gatherInlineModels(items, schemaName); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfigurator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfigurator.java index 8b984a23bed..4c9cb06de1b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfigurator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfigurator.java @@ -70,7 +70,7 @@ public class CodegenConfigurator { private Map importMappings = new HashMap<>(); private Map schemaMappings = new HashMap<>(); private Map inlineSchemaNameMappings = new HashMap<>(); - private Map inlineSchemaNameDefaults = new HashMap<>(); + private Map inlineSchemaOptions = new HashMap<>(); private Map openapiNormalizer = new HashMap<>(); private Set languageSpecificPrimitives = new HashSet<>(); private Map reservedWordsMappings = new HashMap<>(); @@ -121,8 +121,8 @@ public class CodegenConfigurator { if(generatorSettings.getInlineSchemaNameMappings() != null) { configurator.inlineSchemaNameMappings.putAll(generatorSettings.getInlineSchemaNameMappings()); } - if(generatorSettings.getInlineSchemaNameDefaults() != null) { - configurator.inlineSchemaNameDefaults.putAll(generatorSettings.getInlineSchemaNameDefaults()); + if(generatorSettings.getInlineSchemaOptions() != null) { + configurator.inlineSchemaOptions.putAll(generatorSettings.getInlineSchemaOptions()); } if(generatorSettings.getOpenAPINormalizer() != null) { configurator.openapiNormalizer.putAll(generatorSettings.getOpenAPINormalizer()); @@ -208,9 +208,9 @@ public class CodegenConfigurator { return this; } - public CodegenConfigurator addInlineSchemaNameDefault(String key, String value) { - this.inlineSchemaNameDefaults.put(key, value); - generatorSettingsBuilder.withInlineSchemaNameDefault(key, value); + public CodegenConfigurator addInlineSchemaOption(String key, String value) { + this.inlineSchemaOptions.put(key, value); + generatorSettingsBuilder.withInlineSchemaOption(key, value); return this; } @@ -386,9 +386,9 @@ public class CodegenConfigurator { return this; } - public CodegenConfigurator setInlineSchemaNameDefaults(Map inlineSchemaNameDefaults) { - this.inlineSchemaNameDefaults = inlineSchemaNameDefaults; - generatorSettingsBuilder.withInlineSchemaNameDefaults(inlineSchemaNameDefaults); + public CodegenConfigurator setInlineSchemaOptions(Map inlineSchemaOptions) { + this.inlineSchemaOptions = inlineSchemaOptions; + generatorSettingsBuilder.withInlineSchemaOptions(inlineSchemaOptions); return this; } @@ -676,7 +676,7 @@ public class CodegenConfigurator { config.importMapping().putAll(generatorSettings.getImportMappings()); config.schemaMapping().putAll(generatorSettings.getSchemaMappings()); config.inlineSchemaNameMapping().putAll(generatorSettings.getInlineSchemaNameMappings()); - config.inlineSchemaNameDefault().putAll(generatorSettings.getInlineSchemaNameDefaults()); + config.inlineSchemaOption().putAll(generatorSettings.getInlineSchemaOptions()); config.openapiNormalizer().putAll(generatorSettings.getOpenAPINormalizer()); config.languageSpecificPrimitives().addAll(generatorSettings.getLanguageSpecificPrimitives()); config.reservedWordsMappings().putAll(generatorSettings.getReservedWordsMappings()); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfiguratorUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfiguratorUtils.java index 5a0b40d3a42..35d6f101286 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfiguratorUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfiguratorUtils.java @@ -107,16 +107,16 @@ public final class CodegenConfiguratorUtils { } } - public static void applyInlineSchemaNameDefaultsKvpList(List inlineSchemaNameDefaults, CodegenConfigurator configurator) { - for (String propString : inlineSchemaNameDefaults) { - applyInlineSchemaNameDefaultsKvp(propString, configurator); + public static void applyInlineSchemaOptionsKvpList(List inlineSchemaOptions, CodegenConfigurator configurator) { + for (String propString : inlineSchemaOptions) { + applyInlineSchemaOptionsKvp(propString, configurator); } } - public static void applyInlineSchemaNameDefaultsKvp(String inlineSchemaNameDefaults, CodegenConfigurator configurator) { - final Map map = createMapFromKeyValuePairs(inlineSchemaNameDefaults); + public static void applyInlineSchemaOptionsKvp(String inlineSchemaOptions, CodegenConfigurator configurator) { + final Map map = createMapFromKeyValuePairs(inlineSchemaOptions); for (Map.Entry entry : map.entrySet()) { - configurator.addInlineSchemaNameDefault(entry.getKey().trim(), entry.getValue().trim()); + configurator.addInlineSchemaOption(entry.getKey().trim(), entry.getValue().trim()); } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java index 99f9e21f9fb..69d04cf3da8 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java @@ -1040,12 +1040,12 @@ public class InlineModelResolverTest { } @Test - public void testInlineSchemaNameDefault() { + public void testInlineSchemaOptions() { OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml"); InlineModelResolver resolver = new InlineModelResolver(); - Map inlineSchemaNameDefaults = new HashMap<>(); - inlineSchemaNameDefaults.put("arrayItemSuffix", "_something"); - resolver.setInlineSchemaNameDefaults(inlineSchemaNameDefaults); + Map inlineSchemaOptions= new HashMap<>(); + inlineSchemaOptions.put("ARRAY_ITEM_SUFFIX", "_something"); + resolver.setInlineSchemaOptions(inlineSchemaOptions); resolver.flatten(openAPI); Schema schema = openAPI.getComponents().getSchemas().get("resolveInlineArrayRequestBody_request_something"); @@ -1060,9 +1060,9 @@ public class InlineModelResolverTest { public void testInlineSchemaSkipReuseSetToFalse() { OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml"); InlineModelResolver resolver = new InlineModelResolver(); - Map inlineSchemaNameDefaults = new HashMap<>(); - //inlineSchemaNameDefaults.put("SKIP_SCHEMA_REUSE", "false"); // default is false - resolver.setInlineSchemaNameDefaults(inlineSchemaNameDefaults); + Map inlineSchemaOptions = new HashMap<>(); + //inlineSchemaOptions.put("SKIP_SCHEMA_REUSE", "false"); // default is false + resolver.setInlineSchemaOptions(inlineSchemaOptions); resolver.flatten(openAPI); Schema schema = openAPI.getComponents().getSchemas().get("meta_200_response"); @@ -1078,9 +1078,9 @@ public class InlineModelResolverTest { public void testInlineSchemaSkipReuseSetToTrue() { OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml"); InlineModelResolver resolver = new InlineModelResolver(); - Map inlineSchemaNameDefaults = new HashMap<>(); - inlineSchemaNameDefaults.put("SKIP_SCHEMA_REUSE", "true"); - resolver.setInlineSchemaNameDefaults(inlineSchemaNameDefaults); + Map inlineSchemaOptions = new HashMap<>(); + inlineSchemaOptions.put("SKIP_SCHEMA_REUSE", "true"); + resolver.setInlineSchemaOptions(inlineSchemaOptions); resolver.flatten(openAPI); Schema schema = openAPI.getComponents().getSchemas().get("meta_200_response"); @@ -1138,9 +1138,9 @@ public class InlineModelResolverTest { assertNull(((ArraySchema) parameter.getSchema()).getItems().get$ref() ); InlineModelResolver resolver = new InlineModelResolver(); - Map inlineSchemaNameDefaults = new HashMap<>(); - inlineSchemaNameDefaults.put("RESOLVE_INLINE_ENUMS", "true"); - resolver.setInlineSchemaNameDefaults(inlineSchemaNameDefaults); + Map inlineSchemaOptions = new HashMap<>(); + inlineSchemaOptions.put("RESOLVE_INLINE_ENUMS", "true"); + resolver.setInlineSchemaOptions(inlineSchemaOptions); resolver.flatten(openAPI); Parameter parameter2 = openAPI.getPaths().get("/resolve_parameter_inline_enum").getGet().getParameters().get(0); @@ -1156,9 +1156,9 @@ public class InlineModelResolverTest { assertNull(requestBody.get$ref()); InlineModelResolver resolver = new InlineModelResolver(); - Map inlineSchemaNameDefaults = new HashMap<>(); - inlineSchemaNameDefaults.put("RESOLVE_INLINE_ENUMS", "true"); - resolver.setInlineSchemaNameDefaults(inlineSchemaNameDefaults); + Map inlineSchemaOptions = new HashMap<>(); + inlineSchemaOptions.put("RESOLVE_INLINE_ENUMS", "true"); + resolver.setInlineSchemaOptions(inlineSchemaOptions); resolver.flatten(openAPI); Schema requestBody2 = openAPI.getPaths().get("/resolve_parameter_inline_enum_form_parameters").getPost().getRequestBody().getContent().get("application/x-www-form-urlencoded").getSchema();