Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix method naming for openapi normalizer, openapi ignore list option #18348

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/configs/java-okhttp-gson-swagger1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ additionalProperties:
useOneOfDiscriminatorLookup: "true"
disallowAdditionalPropertiesIfNotPresent: false
annotationLibrary: "swagger1"

openapiNormalizer:
SET_TAGS_FOR_ALL_OPERATIONS: common
2 changes: 1 addition & 1 deletion bin/configs/kotlin-model-prefix-type-mapping-echo-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ additionalProperties:
enumPropertyNaming: UPPERCASE
serializationLibrary: gson
openapiNormalizer:
SIMPLIFY_ONEOF_ANYOF=false
SIMPLIFY_ONEOF_ANYOF: false
2 changes: 1 addition & 1 deletion bin/configs/kotlin-model-prefix-type-mapping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ additionalProperties:
enumPropertyNaming: UPPERCASE
serializationLibrary: gson
openapiNormalizer:
SIMPLIFY_ONEOF_ANYOF=false
SIMPLIFY_ONEOF_ANYOF: false
2 changes: 2 additions & 0 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ You can use also `config.yml` with following equivalent example:
apiPackage: "petstore"
```

Another example of config file can be found in [modules/openapi-generator/src/test/resources/sampleConfig.json](https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/sampleConfig.json)

Supported config options can be different per language. Running `config-help -g {lang}` will show available options.
**These options are applied via configuration file (e.g. config.json or config.yml) or by passing them with `-p {optionName}={optionValue}`**. (If `-p {optionName}` does not work, please open a [ticket](https://github.com/openapitools/openapi-generator/issues/new) and we'll look into it)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,11 @@ public void execute() {
applyModelNameMappingsKvpList(modelNameMappings, configurator);
applyEnumNameMappingsKvpList(enumNameMappings, configurator);
applyOperationIdNameMappingsKvpList(operationIdNameMappings, configurator);
applyOpenAPINormalizerKvpList(openapiNormalizer, configurator);
applyOpenapiNormalizerKvpList(openapiNormalizer, configurator);
applyTypeMappingsKvpList(typeMappings, configurator);
applyAdditionalPropertiesKvpList(additionalProperties, configurator);
applyLanguageSpecificPrimitivesCsvList(languageSpecificPrimitives, configurator);
applyOpenAPIGeneratorIgnoreListCsvList(openapiGeneratorIgnoreList, configurator);
applyOpenapiGeneratorIgnoreListCsvList(openapiGeneratorIgnoreList, configurator);
applyReservedWordsMappingsKvpList(reservedWordsMappings, configurator);
applyServerVariablesKvpList(serverVariableOverrides, configurator);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public Map<String, String> getOperationIdNameMappings() {
*
* @return a map of rules
*/
public Map<String, String> getOpenAPINormalizer() {
public Map<String, String> getOpenapiNormalizer() {
return openapiNormalizer;
}

Expand All @@ -346,7 +346,7 @@ public Set<String> getLanguageSpecificPrimitives() {
*
* @return the openapi generator ignore list
*/
public Set<String> getOpenAPIGeneratorIgnoreList() {
public Set<String> getOpenapiGeneratorIgnoreList() {
return openapiGeneratorIgnoreList;
}

Expand Down Expand Up @@ -614,14 +614,14 @@ public static Builder newBuilder(GeneratorSettings copy) {
if (copy.getOperationIdNameMappings() != null) {
builder.operationIdNameMappings.putAll(copy.getOperationIdNameMappings());
}
if (copy.getOpenAPINormalizer() != null) {
builder.openapiNormalizer.putAll(copy.getOpenAPINormalizer());
if (copy.getOpenapiNormalizer() != null) {
builder.openapiNormalizer.putAll(copy.getOpenapiNormalizer());
}
if (copy.getLanguageSpecificPrimitives() != null) {
builder.languageSpecificPrimitives.addAll(copy.getLanguageSpecificPrimitives());
}
if (copy.getOpenAPIGeneratorIgnoreList() != null) {
builder.openapiGeneratorIgnoreList.addAll(copy.getOpenAPIGeneratorIgnoreList());
if (copy.getOpenapiGeneratorIgnoreList() != null) {
builder.openapiGeneratorIgnoreList.addAll(copy.getOpenapiGeneratorIgnoreList());
}
if (copy.getReservedWordsMappings() != null) {
builder.reservedWordsMappings.putAll(copy.getReservedWordsMappings());
Expand Down Expand Up @@ -1152,7 +1152,7 @@ public Builder withOperationIdNameMapping(String key, String value) {
* @param openapiNormalizer the {@code openapiNormalizer} to set
* @return a reference to this Builder
*/
public Builder withOpenAPINormalizer(Map<String, String> openapiNormalizer) {
public Builder withOpenapiNormalizer(Map<String, String> openapiNormalizer) {
this.openapiNormalizer = openapiNormalizer;
return this;
}
Expand All @@ -1164,7 +1164,7 @@ public Builder withOpenAPINormalizer(Map<String, String> openapiNormalizer) {
* @param value The value of the OpenAPI normalizer rule
* @return a reference to this Builder
*/
public Builder withOpenAPINormalizer(String key, String value) {
public Builder withOpenapiNormalizer(String key, String value) {
if (this.openapiNormalizer == null) {
this.openapiNormalizer = new HashMap<>();
}
Expand Down Expand Up @@ -1203,7 +1203,7 @@ public Builder withLanguageSpecificPrimitive(String value) {
* @param openapiGeneratorIgnoreList the {@code openapiGeneratorIgnoreList} to set
* @return a reference to this Builder
*/
public Builder withOpenAPIGeneratorIgnoreList(Set<String> openapiGeneratorIgnoreList) {
public Builder withOpenapiGeneratorIgnoreList(Set<String> openapiGeneratorIgnoreList) {
this.openapiGeneratorIgnoreList = openapiGeneratorIgnoreList;
return this;
}
Expand All @@ -1214,7 +1214,7 @@ public Builder withOpenAPIGeneratorIgnoreList(Set<String> openapiGeneratorIgnore
* @param value The value of entry to set
* @return a reference to this Builder
*/
public Builder withOpenAPIGeneratorIgnoreList(String value) {
public Builder withOpenapiGeneratorIgnoreList(String value) {
if (this.openapiGeneratorIgnoreList == null) {
this.openapiGeneratorIgnoreList = new HashSet<>();
}
Expand Down Expand Up @@ -1390,9 +1390,9 @@ public boolean equals(Object o) {
Objects.equals(getModelNameMappings(), that.getModelNameMappings()) &&
Objects.equals(getEnumNameMappings(), that.getEnumNameMappings()) &&
Objects.equals(getOperationIdNameMappings(), that.getOperationIdNameMappings()) &&
Objects.equals(getOpenAPINormalizer(), that.getOpenAPINormalizer()) &&
Objects.equals(getOpenapiNormalizer(), that.getOpenapiNormalizer()) &&
Objects.equals(getLanguageSpecificPrimitives(), that.getLanguageSpecificPrimitives()) &&
Objects.equals(getOpenAPIGeneratorIgnoreList(), that.getOpenAPIGeneratorIgnoreList()) &&
Objects.equals(getOpenapiGeneratorIgnoreList(), that.getOpenapiGeneratorIgnoreList()) &&
Objects.equals(getReservedWordsMappings(), that.getReservedWordsMappings()) &&
Objects.equals(getGitHost(), that.getGitHost()) &&
Objects.equals(getGitUserId(), that.getGitUserId()) &&
Expand Down Expand Up @@ -1428,9 +1428,9 @@ public int hashCode() {
getModelNameMappings(),
getEnumNameMappings(),
getOperationIdNameMappings(),
getOpenAPINormalizer(),
getOpenapiNormalizer(),
getLanguageSpecificPrimitives(),
getOpenAPIGeneratorIgnoreList(),
getOpenapiGeneratorIgnoreList(),
getReservedWordsMappings(),
getGitHost(),
getGitUserId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac

if (openapiNormalizer.isPresent) {
openapiNormalizer.get().forEach { entry ->
configurator.addOpenAPINormalizer(entry.key, entry.value)
configurator.addOpenapiNormalizer(entry.key, entry.value)
}
}

Expand Down Expand Up @@ -917,7 +917,7 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac

if (openapiGeneratorIgnoreList.isPresent) {
openapiGeneratorIgnoreList.get().forEach {
configurator.addOpenAPIGeneratorIgnoreList(it)
configurator.addOpenapiGeneratorIgnoreList(it)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ public void execute() throws MojoExecutionException {

// Retained for backwards-compatibility with configOptions -> openapi-normalizer
if (openapiNormalizer == null && configOptions.containsKey("openapi-normalizer")) {
applyOpenAPINormalizerKvp(configOptions.get("openapi-normalizer").toString(),
applyOpenapiNormalizerKvp(configOptions.get("openapi-normalizer").toString(),
configurator);
}

Expand All @@ -846,7 +846,7 @@ public void execute() throws MojoExecutionException {

// Retained for backwards-compatibility with configOptions -> openapi-generator-ignore-list
if (openapiGeneratorIgnoreList == null && configOptions.containsKey("openapi-generator-ignore-list")) {
applyOpenAPIGeneratorIgnoreListCsv(configOptions
applyOpenapiGeneratorIgnoreListCsv(configOptions
.get("openapi-generator-ignore-list").toString(), configurator);
}

Expand Down Expand Up @@ -919,7 +919,7 @@ public void execute() throws MojoExecutionException {

// Apply OpenAPI normalizer rules
if (openapiNormalizer != null && (configOptions == null || !configOptions.containsKey("openapi-normalizer"))) {
applyOpenAPINormalizerKvpList(openapiNormalizer, configurator);
applyOpenapiNormalizerKvpList(openapiNormalizer, configurator);
}

// Apply Type Mappings
Expand All @@ -936,7 +936,7 @@ public void execute() throws MojoExecutionException {
// Apply Language Specific Primitives
if (openapiGeneratorIgnoreList != null
&& (configOptions == null || !configOptions.containsKey("openapi-generator-ignore-list"))) {
applyOpenAPIGeneratorIgnoreListCsvList(openapiGeneratorIgnoreList, configurator);
applyOpenapiGeneratorIgnoreListCsvList(openapiGeneratorIgnoreList, configurator);
}

// Apply Additional Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ public interface CodegenConfig {

boolean getAddSuffixToDuplicateOperationNicknames();

boolean getUseOpenAPINormalizer();
boolean getUseOpenapiNormalizer();

Set<String> getOpenAPIGeneratorIgnoreList();
Set<String> getOpenapiGeneratorIgnoreList();

}
Original file line number Diff line number Diff line change
Expand Up @@ -8475,10 +8475,10 @@ public List<VendorExtension> getSupportedVendorExtensions() {
public boolean getUseInlineModelResolver() { return true; }

@Override
public boolean getUseOpenAPINormalizer() { return true; }
public boolean getUseOpenapiNormalizer() { return true; }

@Override
public Set<String> getOpenAPIGeneratorIgnoreList() {
public Set<String> getOpenapiGeneratorIgnoreList() {
return openapiGeneratorIgnoreList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void configureGeneratorProperties() {

// normalize the spec
try {
if (config.getUseOpenAPINormalizer()) {
if (config.getUseOpenapiNormalizer()) {
SemVer version = new SemVer(openAPI.getOpenapi());
if (version.atLeast("3.1.0")) {
config.openapiNormalizer().put("NORMALIZE_31SPEC", "true");
Expand Down Expand Up @@ -929,8 +929,8 @@ private boolean apiFilePreCheck(String filename, String generator, String templa
/*
* Generate .openapi-generator-ignore if the option openapiGeneratorIgnoreFile is enabled.
*/
private void generateOpenAPIGeneratorIgnoreFile() {
if (config.getOpenAPIGeneratorIgnoreList() == null || config.getOpenAPIGeneratorIgnoreList().isEmpty()) {
private void generateOpenapiGeneratorIgnoreFile() {
if (config.getOpenapiGeneratorIgnoreList() == null || config.getOpenapiGeneratorIgnoreList().isEmpty()) {
return;
}

Expand Down Expand Up @@ -982,7 +982,7 @@ private void generateOpenAPIGeneratorIgnoreFile() {
Writer fileWriter = Files.newBufferedWriter(ignoreFile.toPath(), StandardCharsets.UTF_8);
fileWriter.write(header);
// add entries provided by the users
for (String entry : config.getOpenAPIGeneratorIgnoreList()) {
for (String entry : config.getOpenapiGeneratorIgnoreList()) {
fileWriter.write(entry);
fileWriter.write("\n");
}
Expand Down Expand Up @@ -1219,7 +1219,7 @@ public List<File> generate() {
processUserDefinedTemplates();

// generate .openapi-generator-ignore if the option openapiGeneratorIgnoreFile is enabled
generateOpenAPIGeneratorIgnoreFile();
generateOpenapiGeneratorIgnoreFile();

List<File> files = new ArrayList<>();
// models
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ public static CodegenConfigurator fromFile(String configFile, Module... modules)
if(generatorSettings.getOperationIdNameMappings() != null) {
configurator.operationIdNameMappings.putAll(generatorSettings.getOperationIdNameMappings());
}
if(generatorSettings.getOpenAPINormalizer() != null) {
configurator.openapiNormalizer.putAll(generatorSettings.getOpenAPINormalizer());
if(generatorSettings.getOpenapiNormalizer() != null) {
configurator.openapiNormalizer.putAll(generatorSettings.getOpenapiNormalizer());
}
if(generatorSettings.getLanguageSpecificPrimitives() != null) {
configurator.languageSpecificPrimitives.addAll(generatorSettings.getLanguageSpecificPrimitives());
}
if(generatorSettings.getOpenAPIGeneratorIgnoreList() != null) {
configurator.openapiGeneratorIgnoreList.addAll(generatorSettings.getOpenAPIGeneratorIgnoreList());
if(generatorSettings.getOpenapiGeneratorIgnoreList() != null) {
configurator.openapiGeneratorIgnoreList.addAll(generatorSettings.getOpenapiGeneratorIgnoreList());
}
if(generatorSettings.getReservedWordsMappings() != null) {
configurator.reservedWordsMappings.putAll(generatorSettings.getReservedWordsMappings());
Expand Down Expand Up @@ -268,9 +268,9 @@ public CodegenConfigurator addOperationIdNameMapping(String key, String value) {
return this;
}

public CodegenConfigurator addOpenAPINormalizer(String key, String value) {
public CodegenConfigurator addOpenapiNormalizer(String key, String value) {
this.openapiNormalizer.put(key, value);
generatorSettingsBuilder.withOpenAPINormalizer(key, value);
generatorSettingsBuilder.withOpenapiNormalizer(key, value);
return this;
}

Expand All @@ -286,9 +286,9 @@ public CodegenConfigurator addLanguageSpecificPrimitive(String value) {
return this;
}

public CodegenConfigurator addOpenAPIGeneratorIgnoreList(String value) {
public CodegenConfigurator addOpenapiGeneratorIgnoreList(String value) {
this.openapiGeneratorIgnoreList.add(value);
generatorSettingsBuilder.withOpenAPIGeneratorIgnoreList(value);
generatorSettingsBuilder.withOpenapiGeneratorIgnoreList(value);
return this;
}

Expand Down Expand Up @@ -482,9 +482,9 @@ public CodegenConfigurator setOperationIdNameMappings(Map<String, String> operat
return this;
}

public CodegenConfigurator setOpenAPINormalizer(Map<String, String> openapiNormalizer) {
public CodegenConfigurator setOpenapiNormalizer(Map<String, String> openapiNormalizer) {
this.openapiNormalizer = openapiNormalizer;
generatorSettingsBuilder.withOpenAPINormalizer(openapiNormalizer);
generatorSettingsBuilder.withOpenapiNormalizer(openapiNormalizer);
return this;
}

Expand Down Expand Up @@ -515,10 +515,10 @@ public CodegenConfigurator setLanguageSpecificPrimitives(
return this;
}

public CodegenConfigurator setOpenAPIGeneratorIgnoreList(
public CodegenConfigurator setOpenapiGeneratorIgnoreList(
Set<String> openapiGeneratorIgnoreList) {
this.openapiGeneratorIgnoreList = openapiGeneratorIgnoreList;
generatorSettingsBuilder.withOpenAPIGeneratorIgnoreList(openapiGeneratorIgnoreList);
generatorSettingsBuilder.withOpenapiGeneratorIgnoreList(openapiGeneratorIgnoreList);
return this;
}

Expand Down Expand Up @@ -779,9 +779,9 @@ public ClientOptInput toClientOptInput() {
config.modelNameMapping().putAll(generatorSettings.getModelNameMappings());
config.enumNameMapping().putAll(generatorSettings.getEnumNameMappings());
config.operationIdNameMapping().putAll(generatorSettings.getOperationIdNameMappings());
config.openapiNormalizer().putAll(generatorSettings.getOpenAPINormalizer());
config.openapiNormalizer().putAll(generatorSettings.getOpenapiNormalizer());
config.languageSpecificPrimitives().addAll(generatorSettings.getLanguageSpecificPrimitives());
config.openapiGeneratorIgnoreList().addAll(generatorSettings.getOpenAPIGeneratorIgnoreList());
config.openapiGeneratorIgnoreList().addAll(generatorSettings.getOpenapiGeneratorIgnoreList());
config.reservedWordsMappings().putAll(generatorSettings.getReservedWordsMappings());
config.additionalProperties().putAll(generatorSettings.getAdditionalProperties());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,16 @@ public static void applyOperationIdNameMappingsKvp(String operationIdNameMapping
}
}

public static void applyOpenAPINormalizerKvpList(List<String> openapiNormalizer, CodegenConfigurator configurator) {
public static void applyOpenapiNormalizerKvpList(List<String> openapiNormalizer, CodegenConfigurator configurator) {
for (String propString : openapiNormalizer) {
applyOpenAPINormalizerKvp(propString, configurator);
applyOpenapiNormalizerKvp(propString, configurator);
}
}

public static void applyOpenAPINormalizerKvp(String openapiNormalizer, CodegenConfigurator configurator) {
public static void applyOpenapiNormalizerKvp(String openapiNormalizer, CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(openapiNormalizer);
for (Map.Entry<String, String> entry : map.entrySet()) {
configurator.addOpenAPINormalizer(entry.getKey().trim(), entry.getValue().trim());
configurator.addOpenapiNormalizer(entry.getKey().trim(), entry.getValue().trim());
}
}

Expand Down Expand Up @@ -250,16 +250,16 @@ public static void applyLanguageSpecificPrimitivesCsv(String languageSpecificPri
}
}

public static void applyOpenAPIGeneratorIgnoreListCsvList(List<String> openapiGeneratorIgnoreList, CodegenConfigurator configurator) {
public static void applyOpenapiGeneratorIgnoreListCsvList(List<String> openapiGeneratorIgnoreList, CodegenConfigurator configurator) {
for (String propString : openapiGeneratorIgnoreList) {
applyOpenAPIGeneratorIgnoreListCsv(propString, configurator);
applyOpenapiGeneratorIgnoreListCsv(propString, configurator);
}
}

public static void applyOpenAPIGeneratorIgnoreListCsv(String openapiGeneratorIgnoreList, CodegenConfigurator configurator) {
public static void applyOpenapiGeneratorIgnoreListCsv(String openapiGeneratorIgnoreList, CodegenConfigurator configurator) {
final Set<String> set = createSetFromCsvList(openapiGeneratorIgnoreList);
for (String item : set) {
configurator.addOpenAPIGeneratorIgnoreList(item);
configurator.addOpenapiGeneratorIgnoreList(item);
}
}

Expand Down
Loading
Loading