Skip to content

Commit

Permalink
Fix prefix/suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
sschnabe committed Sep 18, 2024
1 parent 7a8170f commit ca23b00
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.validation.Validated
public interface DefaultApi {
public interface ApiPrefixDefaultApiSuffix {

@io.micronaut.http.annotation.Get("/doIt")
io.micronaut.http.HttpResponse<Object> doIt();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package issue._414;

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
public enum ModelEnumModelSuffix {
public enum ModelPrefixModelEnumModelSuffix {

FOO("foo"),
BAR("bar");
Expand All @@ -11,16 +11,16 @@ public enum ModelEnumModelSuffix {

private final java.lang.String value;

private ModelEnumModelSuffix(java.lang.String value) {
private ModelPrefixModelEnumModelSuffix(java.lang.String value) {
this.value = value;
}

@com.fasterxml.jackson.annotation.JsonCreator
public static ModelEnumModelSuffix toEnum(java.lang.String value) {
public static ModelPrefixModelEnumModelSuffix toEnum(java.lang.String value) {
return toOptional(value).orElseThrow(() -> new IllegalArgumentException("Unknown value '" + value + "'."));
}

public static java.util.Optional<ModelEnumModelSuffix> toOptional(java.lang.String value) {
public static java.util.Optional<ModelPrefixModelEnumModelSuffix> toOptional(java.lang.String value) {
return java.util.Arrays
.stream(values())
.filter(e -> e.value.equals(value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.serde.annotation.Serdeable
public class ModelObjectModelSuffix {
public class ModelPrefixModelObjectModelSuffix {

@com.fasterxml.jackson.annotation.JsonProperty("a")
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
Expand All @@ -18,7 +18,7 @@ public boolean equals(Object object) {
if (object == null || getClass() != object.getClass()) {
return false;
}
ModelObjectModelSuffix other = (ModelObjectModelSuffix) object;
ModelPrefixModelObjectModelSuffix other = (ModelPrefixModelObjectModelSuffix) object;
return java.util.Objects.equals(a, other.a);
}

Expand All @@ -30,15 +30,15 @@ public int hashCode() {
@Override
public java.lang.String toString() {
return new java.lang.StringBuilder()
.append("ModelObjectModelSuffix[")
.append("ModelPrefixModelObjectModelSuffix[")
.append("a=").append(a)
.append("]")
.toString();
}

// fluent

public ModelObjectModelSuffix a(java.lang.String newA) {
public ModelPrefixModelObjectModelSuffix a(java.lang.String newA) {
this.a = newA;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package issue._414;

/** Test client for {@link DefaultApi}. **/
/** Test client for {@link ApiPrefixDefaultApiSuffix}. **/
@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
@io.micronaut.http.client.annotation.Client("${micronaut.http.services.test.clientId:/}")
public interface DefaultApiTestClient {
public interface ApiPrefixDefaultApiSuffixTestClient {

@io.micronaut.http.annotation.Get("/doIt")
io.micronaut.http.HttpResponse<?> doIt();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package issue._414;

/** Test for {@link DefaultApi}. */
/** Test for {@link ApiPrefixDefaultApiSuffix}. */
@jakarta.annotation.Generated("org.openapitools.codegen.languages.MicronautCodegen")
public interface DefaultApiTestSpec {
public interface ApiPrefixDefaultApiSuffixTestSpec {

// doIt

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package org.openapitools.codegen.languages;

import static org.openapitools.codegen.CodegenConstants.API_NAME_PREFIX;
import static org.openapitools.codegen.CodegenConstants.API_NAME_PREFIX_DESC;
import static org.openapitools.codegen.CodegenConstants.API_NAME_SUFFIX;
import static org.openapitools.codegen.CodegenConstants.API_NAME_SUFFIX_DESC;
import static org.openapitools.codegen.CodegenConstants.GENERATE_API_TESTS;
import static org.openapitools.codegen.CodegenConstants.MODEL_NAME_PREFIX;
import static org.openapitools.codegen.CodegenConstants.MODEL_NAME_PREFIX_DESC;
import static org.openapitools.codegen.CodegenConstants.MODEL_NAME_SUFFIX;
import static org.openapitools.codegen.CodegenConstants.MODEL_NAME_SUFFIX_DESC;
import static org.openapitools.codegen.CodegenConstants.REMOVE_ENUM_VALUE_PREFIX;
import static org.openapitools.codegen.CodegenConstants.REMOVE_ENUM_VALUE_PREFIX_DESC;
import static org.openapitools.codegen.CodegenConstants.SOURCE_FOLDER;
Expand Down Expand Up @@ -104,6 +111,10 @@ public MicronautCodegen() {
cliOptions.add(CliOption.newString(CLIENT_ID, "ClientId to use."));
cliOptions.add(CliOption.newString(SOURCE_FOLDER, SOURCE_FOLDER_DESC));
cliOptions.add(CliOption.newString("testFolder", "test folder for generated code"));
cliOptions.add(CliOption.newString(API_NAME_PREFIX, API_NAME_PREFIX_DESC));
cliOptions.add(CliOption.newString(API_NAME_SUFFIX, API_NAME_SUFFIX_DESC));
cliOptions.add(CliOption.newString(MODEL_NAME_PREFIX, MODEL_NAME_PREFIX_DESC));
cliOptions.add(CliOption.newString(MODEL_NAME_SUFFIX, MODEL_NAME_SUFFIX_DESC));
cliOptions.add(
CliOption.newBoolean(REMOVE_ENUM_VALUE_PREFIX, REMOVE_ENUM_VALUE_PREFIX_DESC, removeEnumValuePrefix));

Expand Down Expand Up @@ -197,6 +208,8 @@ public void postProcess() {}

@Override
public void processOpts() {
super.useCodegenAsMustacheParentContext();

BiFunction<String, String, String> getOrDefault = (key,
defaultValue) -> (String) additionalProperties.computeIfAbsent(key, k -> defaultValue);

Expand All @@ -210,15 +223,6 @@ public void processOpts() {

// process flags - this class

if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
useBeanValidation = convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION);
}
if (additionalProperties.containsKey(USE_GENERIC_RESPONSE)) {
useGenericResponse = convertPropertyToBooleanAndWriteBack(USE_GENERIC_RESPONSE);
}
if (additionalProperties.containsKey(USE_OPTIONAL)) {
useOptional = convertPropertyToBooleanAndWriteBack(USE_OPTIONAL);
}
if (additionalProperties.containsKey(SERDEABLE)) {
serdeable = convertPropertyToBooleanAndWriteBack(SERDEABLE);
}
Expand All @@ -234,15 +238,9 @@ public void processOpts() {
if (additionalProperties.containsKey(RECORD)) {
record = convertPropertyToBooleanAndWriteBack(RECORD);
}
if (additionalProperties.containsKey(SUPPORT_ASYNC)) {
supportAsync = convertPropertyToBooleanAndWriteBack(SUPPORT_ASYNC);
}
if (additionalProperties.containsKey(GENERATE_API_TESTS)) {
generateApiTests = convertPropertyToBooleanAndWriteBack(GENERATE_API_TESTS);
}
if (additionalProperties.containsKey(OPENAPI_NULLABLE)) {
openApiNullable = convertPropertyToBooleanAndWriteBack(OPENAPI_NULLABLE);
}
if (additionalProperties.containsKey(GENERATE_AUTHENTICATION)) {
generateAuthentication = convertPropertyToBooleanAndWriteBack(GENERATE_AUTHENTICATION);
}
Expand All @@ -252,9 +250,19 @@ record = convertPropertyToBooleanAndWriteBack(RECORD);
if (additionalProperties.containsKey(GENERATE_CONSTANTS)) {
generateConstants = convertPropertyToBooleanAndWriteBack(GENERATE_CONSTANTS);
}
if (additionalProperties.containsKey(REMOVE_ENUM_VALUE_PREFIX)) {
removeEnumValuePrefix = convertPropertyToBooleanAndWriteBack(REMOVE_ENUM_VALUE_PREFIX);
}

// generic properties

convertPropertyToStringAndWriteBack(API_NAME_PREFIX, this::setApiNamePrefix);
convertPropertyToStringAndWriteBack(API_NAME_SUFFIX, this::setApiNameSuffix);
convertPropertyToStringAndWriteBack(MODEL_NAME_PREFIX, this::setModelNamePrefix);
convertPropertyToStringAndWriteBack(MODEL_NAME_SUFFIX, this::setModelNameSuffix);
convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION, this::setUseBeanValidation);
convertPropertyToBooleanAndWriteBack(USE_GENERIC_RESPONSE, this::setUseGenericResponse);
convertPropertyToBooleanAndWriteBack(USE_OPTIONAL, this::setUseOptional);
convertPropertyToBooleanAndWriteBack(REMOVE_ENUM_VALUE_PREFIX, this::setRemoveEnumValuePrefix);
convertPropertyToBooleanAndWriteBack(OPENAPI_NULLABLE, this::setOpenApiNullable);
convertPropertyToBooleanAndWriteBack(SUPPORT_ASYNC, this::setSupportAsync);

// we do not generate projects, only api, set source and test folder

Expand All @@ -263,7 +271,6 @@ record = convertPropertyToBooleanAndWriteBack(RECORD);
projectTestFolder = getOrDefault.apply("projectTestFolder", "generated-test-sources");
sourceFolder = getOrDefault.apply(SOURCE_FOLDER, projectFolder + File.separator + "openapi");
testFolder = getOrDefault.apply("testFolder", projectTestFolder + File.separator + "openapi");
modelNameSuffix = getOrDefault.apply(MODEL_NAME_SUFFIX, modelNameSuffix);

// add files to generate

Expand Down

0 comments on commit ca23b00

Please sign in to comment.