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
```
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

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)")
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<String, String> map = config.inlineSchemaNameDefault()
if (Boolean.TRUE.equals(inlineSchemaOptions)) {
sb.append(newline).append("INLINE SCHEMA OPTIONS").append(newline).append(newline);
Map<String, String> 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);
}

View File

@ -182,11 +182,10 @@ public class Generate extends OpenApiGeneratorCommand {
private List<String> 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<String> 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<String> 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);

View File

@ -52,7 +52,7 @@ public final class GeneratorSettings implements Serializable {
private final Map<String, String> importMappings;
private final Map<String, String> schemaMappings;
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 Set<String> languageSpecificPrimitives;
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() {
return inlineSchemaNameDefaults;
public Map<String, String> 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<String, String> importMappings;
private Map<String, String> schemaMappings;
private Map<String, String> inlineSchemaNameMappings;
private Map<String, String> inlineSchemaNameDefaults;
private Map<String, String> inlineSchemaOptions;
private Map<String, String> openapiNormalizer;
private Set<String> languageSpecificPrimitives;
private Map<String, String> 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<String, String> inlineSchemaNameDefaults) {
this.inlineSchemaNameDefaults = inlineSchemaNameDefaults;
public Builder withInlineSchemaOptions(Map<String, String> 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(),

View File

@ -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)

View File

@ -118,7 +118,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
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)

View File

@ -163,9 +163,9 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
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

View File

@ -266,11 +266,11 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
val inlineSchemaNameMappings = project.objects.mapProperty<String, String>()
/**
* Specifies default values for inline schema naming convention
* Specifies options for inline schemas
*/
@Optional
@Input
val inlineSchemaNameDefaults = project.objects.mapProperty<String, String>()
val inlineSchemaOptions = project.objects.mapProperty<String, String>()
/**
* 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)
}
}

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`.
| `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

View File

@ -327,10 +327,10 @@ public class CodeGenMojo extends AbstractMojo {
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")
private List<String> inlineSchemaNameDefaults;
@Parameter(name = "inlineSchemaOptions", property = "openapi.generator.maven.plugin.inlineSchemaOptions")
private List<String> 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

View File

@ -145,7 +145,7 @@ public interface CodegenConfig {
Map<String, String> inlineSchemaNameMapping();
Map<String, String> inlineSchemaNameDefault();
Map<String, String> inlineSchemaOption();
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
protected Map<String, String> inlineSchemaNameMapping = new HashMap<>();
// 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
protected Map<String, String> openapiNormalizer = new HashMap<>();
protected String modelPackage = "", apiPackage = "", fileSuffix;
@ -1194,8 +1194,8 @@ public class DefaultCodegen implements CodegenConfig {
}
@Override
public Map<String, String> inlineSchemaNameDefault() {
return inlineSchemaNameDefault;
public Map<String, String> inlineSchemaOption() {
return inlineSchemaOption;
}
@Override

View File

@ -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);
}

View File

@ -41,7 +41,7 @@ public class InlineModelResolver {
private Map<String, Schema> addedModels = new HashMap<>();
private Map<String, String> generatedSignature = 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<>();
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);

View File

@ -70,7 +70,7 @@ public class CodegenConfigurator {
private Map<String, String> importMappings = new HashMap<>();
private Map<String, String> schemaMappings = 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 Set<String> languageSpecificPrimitives = new HashSet<>();
private Map<String, String> 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<String, String> inlineSchemaNameDefaults) {
this.inlineSchemaNameDefaults = inlineSchemaNameDefaults;
generatorSettingsBuilder.withInlineSchemaNameDefaults(inlineSchemaNameDefaults);
public CodegenConfigurator setInlineSchemaOptions(Map<String, String> 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());

View File

@ -107,16 +107,16 @@ public final class CodegenConfiguratorUtils {
}
}
public static void applyInlineSchemaNameDefaultsKvpList(List<String> inlineSchemaNameDefaults, CodegenConfigurator configurator) {
for (String propString : inlineSchemaNameDefaults) {
applyInlineSchemaNameDefaultsKvp(propString, configurator);
public static void applyInlineSchemaOptionsKvpList(List<String> inlineSchemaOptions, CodegenConfigurator configurator) {
for (String propString : inlineSchemaOptions) {
applyInlineSchemaOptionsKvp(propString, configurator);
}
}
public static void applyInlineSchemaNameDefaultsKvp(String inlineSchemaNameDefaults, CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(inlineSchemaNameDefaults);
public static void applyInlineSchemaOptionsKvp(String inlineSchemaOptions, CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(inlineSchemaOptions);
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
public void testInlineSchemaNameDefault() {
public void testInlineSchemaOptions() {
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
InlineModelResolver resolver = new InlineModelResolver();
Map<String, String> inlineSchemaNameDefaults = new HashMap<>();
inlineSchemaNameDefaults.put("arrayItemSuffix", "_something");
resolver.setInlineSchemaNameDefaults(inlineSchemaNameDefaults);
Map<String, String> 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<String, String> inlineSchemaNameDefaults = new HashMap<>();
//inlineSchemaNameDefaults.put("SKIP_SCHEMA_REUSE", "false"); // default is false
resolver.setInlineSchemaNameDefaults(inlineSchemaNameDefaults);
Map<String, String> 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<String, String> inlineSchemaNameDefaults = new HashMap<>();
inlineSchemaNameDefaults.put("SKIP_SCHEMA_REUSE", "true");
resolver.setInlineSchemaNameDefaults(inlineSchemaNameDefaults);
Map<String, String> 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<String, String> inlineSchemaNameDefaults = new HashMap<>();
inlineSchemaNameDefaults.put("RESOLVE_INLINE_ENUMS", "true");
resolver.setInlineSchemaNameDefaults(inlineSchemaNameDefaults);
Map<String, String> 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<String, String> inlineSchemaNameDefaults = new HashMap<>();
inlineSchemaNameDefaults.put("RESOLVE_INLINE_ENUMS", "true");
resolver.setInlineSchemaNameDefaults(inlineSchemaNameDefaults);
Map<String, String> 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();