mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-10-14 00:13:50 +00:00
Autoset constants (Required fields having single valid enum value) Java (OkHttp) Implementation of #16547 (#16550)
* Autosets the parameters with the only value specified as enum if the parameter is also marked as required * Autosets the parameters with the only value specified as enum if the parameter is also marked as required * Autosets the parameters with the only value specified as enum if the parameter is also marked as required for Java default client. * Autosets the parameters with the only value specified as enum if the parameter is also marked as required for Java default client. * Autosets the parameters with the only value specified as enum if the parameter is also marked as required for Java default client. * Autosets the parameters with the only value specified as enum if the parameter is also marked as required for Java default client.
This commit is contained in:
parent
d671fe24ee
commit
4b87606665
@ -25,6 +25,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|apiPackage|package for generated api classes| |org.openapitools.api|
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-groovy|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -30,6 +30,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|async|use async Callable controllers| |false|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|basePackage|base package (invokerPackage) for generated code| |org.openapitools|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-java-client|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-java-server|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-inflector-server|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -30,6 +30,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|authorizationFilterPattern|Configure the authorization filter pattern for the client. Generally defined when generating clients from multiple specification files| |null|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|basePathSeparator|Configure the separator to use between the application name and base path when referencing the property| |-|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-micronaut|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|build|Specify for which build tool to generate files|<dl><dt>**gradle**</dt><dd>Gradle configuration is generated for the project</dd><dt>**all**</dt><dd>Both Gradle and Maven configurations are generated</dd><dt>**maven**</dt><dd>Maven configuration is generated for the project</dd></dl>|all|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-jaxrs-server|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |pkmst-microservice|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|basePackage|base package for java source code| |null|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-java-playframework|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|basePackage|base package for generated code| |org.openapitools|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-undertow-server|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-java-vertx-web-server|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0-SNAPSHOT|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-java-vertx-server|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0-SNAPSHOT|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -29,6 +29,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|asyncNative|If true, async handlers will be used, instead of the sync version| |false|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-jaxrs-cxf-cdi-server|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-jaxrs-client|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -28,6 +28,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-cxf-server|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -28,6 +28,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-cxf-server|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-jaxrs-server|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-jaxrs-resteasy-eap-server|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-jaxrs-resteasy-server|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-jaxrs-server|
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|
@ -30,6 +30,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|async|use async Callable controllers| |false|
|
||||
|autosetConstants|Automatically set Required Params having a Single enum value i.e. Constants in generated code| |false|
|
||||
|basePackage|base package (invokerPackage) for generated code| |org.openapitools|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|
@ -30,7 +30,7 @@ public class CodegenOperation {
|
||||
hasVersionHeaders = false, hasVersionQueryParams = false,
|
||||
isResponseBinary = false, isResponseFile = false, isResponseOptional = false, hasReference = false, defaultReturnType = false,
|
||||
isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
|
||||
isRestful, isDeprecated, isCallbackRequest, uniqueItems, hasDefaultResponse = false,
|
||||
isRestful, isDeprecated, isCallbackRequest, uniqueItems, hasDefaultResponse = false, hasConstantParams = false,
|
||||
hasErrorResponseObject; // if 4xx, 5xx responses have at least one error object defined
|
||||
public CodegenProperty returnProperty;
|
||||
public String path, operationId, returnType, returnFormat, httpMethod, returnBaseType,
|
||||
@ -45,6 +45,7 @@ public class CodegenOperation {
|
||||
public List<CodegenParameter> queryParams = new ArrayList<CodegenParameter>();
|
||||
public List<CodegenParameter> headerParams = new ArrayList<CodegenParameter>();
|
||||
public List<CodegenParameter> implicitHeadersParams = new ArrayList<CodegenParameter>();
|
||||
public List<CodegenParameter> constantParams = new ArrayList<CodegenParameter>();
|
||||
public List<CodegenParameter> formParams = new ArrayList<CodegenParameter>();
|
||||
public List<CodegenParameter> cookieParams = new ArrayList<CodegenParameter>();
|
||||
public List<CodegenParameter> requiredParams = new ArrayList<CodegenParameter>();
|
||||
@ -392,6 +393,7 @@ public class CodegenOperation {
|
||||
sb.append(", operationIdLowerCase='").append(operationIdLowerCase).append('\'');
|
||||
sb.append(", operationIdCamelCase='").append(operationIdCamelCase).append('\'');
|
||||
sb.append(", operationIdSnakeCase='").append(operationIdSnakeCase).append('\'');
|
||||
sb.append(", constantParams='").append(constantParams).append('\'');
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
@ -472,7 +474,8 @@ public class CodegenOperation {
|
||||
Objects.equals(operationIdOriginal, that.operationIdOriginal) &&
|
||||
Objects.equals(operationIdLowerCase, that.operationIdLowerCase) &&
|
||||
Objects.equals(operationIdCamelCase, that.operationIdCamelCase) &&
|
||||
Objects.equals(operationIdSnakeCase, that.operationIdSnakeCase);
|
||||
Objects.equals(operationIdSnakeCase, that.operationIdSnakeCase) &&
|
||||
Objects.equals(constantParams, that.constantParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -488,6 +491,6 @@ public class CodegenOperation {
|
||||
pathParams, queryParams, headerParams, formParams, cookieParams, requiredParams, returnProperty, optionalParams,
|
||||
authMethods, tags, responses, callbacks, imports, examples, requestBodyExamples, externalDocs,
|
||||
vendorExtensions, nickname, operationIdOriginal, operationIdLowerCase, operationIdCamelCase,
|
||||
operationIdSnakeCase, hasErrorResponseObject, requiredAndNotNullableParams, notNullableParams);
|
||||
operationIdSnakeCase, hasErrorResponseObject, requiredAndNotNullableParams, notNullableParams, constantParams);
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
public static final String TEST_OUTPUT = "testOutput";
|
||||
public static final String IMPLICIT_HEADERS = "implicitHeaders";
|
||||
public static final String IMPLICIT_HEADERS_REGEX = "implicitHeadersRegex";
|
||||
public static final String AUTOSET_CONSTANTS = "autosetConstants";
|
||||
public static final String JAVAX_PACKAGE = "javaxPackage";
|
||||
public static final String USE_JAKARTA_EE = "useJakartaEe";
|
||||
public static final String CONTAINER_DEFAULT_TO_NULL = "containerDefaultToNull";
|
||||
@ -137,6 +138,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
protected AnnotationLibrary annotationLibrary;
|
||||
protected boolean implicitHeaders = false;
|
||||
protected String implicitHeadersRegex = null;
|
||||
protected boolean autosetConstants = false;
|
||||
protected boolean camelCaseDollarSign = false;
|
||||
protected boolean useJakartaEe = false;
|
||||
protected boolean containerDefaultToNull = false;
|
||||
@ -277,6 +279,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
cliOptions.add(CliOption.newBoolean(OPENAPI_NULLABLE, "Enable OpenAPI Jackson Nullable library", this.openApiNullable));
|
||||
cliOptions.add(CliOption.newBoolean(IMPLICIT_HEADERS, "Skip header parameters in the generated API methods using @ApiImplicitParams annotation.", implicitHeaders));
|
||||
cliOptions.add(CliOption.newString(IMPLICIT_HEADERS_REGEX, "Skip header parameters that matches given regex in the generated API methods using @ApiImplicitParams annotation. Note: this parameter is ignored when implicitHeaders=true"));
|
||||
cliOptions.add(CliOption.newBoolean(AUTOSET_CONSTANTS, "Automatically set Required Params having a Single enum value i.e. Constants in generated code", autosetConstants));
|
||||
cliOptions.add(CliOption.newBoolean(CAMEL_CASE_DOLLAR_SIGN, "Fix camelCase when starting with $ sign. when true : $Value when false : $value"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_JAKARTA_EE, "whether to use Jakarta EE namespace instead of javax"));
|
||||
cliOptions.add(CliOption.newBoolean(CONTAINER_DEFAULT_TO_NULL, "Set containers (array, set, map) default to null"));
|
||||
@ -563,6 +566,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
this.setImplicitHeadersRegex(additionalProperties.get(IMPLICIT_HEADERS_REGEX).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(AUTOSET_CONSTANTS)) {
|
||||
this.setAutosetConstants(Boolean.parseBoolean(additionalProperties.get(AUTOSET_CONSTANTS).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CAMEL_CASE_DOLLAR_SIGN)) {
|
||||
this.setCamelCaseDollarSign(Boolean.parseBoolean(additionalProperties.get(CAMEL_CASE_DOLLAR_SIGN).toString()));
|
||||
}
|
||||
@ -1578,6 +1585,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
op.vendorExtensions.put("x-java-import", operationImports);
|
||||
|
||||
handleImplicitHeaders(op);
|
||||
handleConstantParams(op);
|
||||
}
|
||||
|
||||
return objs;
|
||||
@ -2052,6 +2060,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
this.implicitHeadersRegex = implicitHeadersRegex;
|
||||
}
|
||||
|
||||
public void setAutosetConstants(boolean autosetConstants) {
|
||||
this.autosetConstants = autosetConstants;
|
||||
}
|
||||
|
||||
public void setCamelCaseDollarSign(boolean camelCaseDollarSign) {
|
||||
this.camelCaseDollarSign = camelCaseDollarSign;
|
||||
}
|
||||
@ -2294,6 +2306,45 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
operation.hasParams = !operation.allParams.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method removes all constant Query, Header and Cookie Params from allParams and sets them as constantParams in the CodegenOperation.
|
||||
* The definition of constant is single valued required enum params.
|
||||
* The constantParams in the the generated code should be hardcoded to the constantValue if autosetConstants feature is enabled.
|
||||
*
|
||||
* @param operation - operation to be processed
|
||||
*/
|
||||
protected void handleConstantParams(CodegenOperation operation) {
|
||||
if (!autosetConstants || operation.allParams.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final ArrayList<CodegenParameter> copy = new ArrayList<>(operation.allParams);
|
||||
// Remove all params from Params, Non constant params will be added back later.
|
||||
operation.allParams.clear();
|
||||
|
||||
// Finds all constant params, removes them from allParams and adds them to constant params.
|
||||
// Also, adds back non constant params to allParams.
|
||||
for (CodegenParameter p : copy) {
|
||||
if (p.isEnum && p.required && p._enum != null && p._enum.size() == 1) {
|
||||
// Add to constantParams for use in the code generation templates.
|
||||
operation.constantParams.add(p);
|
||||
if(p.isQueryParam) {
|
||||
operation.queryParams.removeIf(param -> param.baseName.equals(p.baseName));
|
||||
}
|
||||
if(p.isHeaderParam) {
|
||||
operation.headerParams.removeIf(param -> param.baseName.equals(p.baseName));
|
||||
}
|
||||
if(p.isCookieParam) {
|
||||
operation.cookieParams.removeIf(param -> param.baseName.equals(p.baseName));
|
||||
}
|
||||
LOGGER.info("Update operation [{}]. Remove parameter [{}] because it can only have a fixed value of [{}]", operation.operationId, p.baseName, p._enum.get(0));
|
||||
} else {
|
||||
// Add back to allParams as the param is not a constant.
|
||||
operation.allParams.add(p);
|
||||
}
|
||||
}
|
||||
operation.hasParams = !operation.allParams.isEmpty();
|
||||
}
|
||||
|
||||
private boolean shouldBeImplicitHeader(CodegenParameter parameter) {
|
||||
return StringUtils.isNotBlank(implicitHeadersRegex) && parameter.baseName.matches(implicitHeadersRegex);
|
||||
}
|
||||
|
@ -172,18 +172,39 @@ public class {{classname}} {
|
||||
}
|
||||
|
||||
{{/queryParams}}
|
||||
{{#constantParams}}
|
||||
{{#isQueryParam}}
|
||||
// Set client side default value of Query Param "{{baseName}}".
|
||||
localVarCollectionQueryParams.add(new Pair("{{baseName}}", {{#_enum}}"{{{.}}}"{{/_enum}}));
|
||||
|
||||
{{/isQueryParam}}
|
||||
{{/constantParams}}
|
||||
{{#headerParams}}
|
||||
if ({{paramName}} != null) {
|
||||
localVarHeaderParams.put("{{baseName}}", localVarApiClient.parameterToString({{paramName}}));
|
||||
}
|
||||
|
||||
{{/headerParams}}
|
||||
{{#constantParams}}
|
||||
{{#isHeaderParam}}
|
||||
// Set client side default value of Header Param "{{baseName}}".
|
||||
localVarHeaderParams.put("{{baseName}}", {{#_enum}}"{{{.}}}"{{/_enum}});
|
||||
|
||||
{{/isHeaderParam}}
|
||||
{{/constantParams}}
|
||||
{{#cookieParams}}
|
||||
if ({{paramName}} != null) {
|
||||
localVarCookieParams.put("{{baseName}}", localVarApiClient.parameterToString({{paramName}}));
|
||||
}
|
||||
|
||||
{{/cookieParams}}
|
||||
{{#constantParams}}
|
||||
{{#isCookieParam}}
|
||||
// Set client side default value of Cookie Param "{{baseName}}".
|
||||
localVarCookieParams.put("{{baseName}}", {{#_enum}}"{{{.}}}"{{/_enum}});
|
||||
|
||||
{{/isCookieParam}}
|
||||
{{/constantParams}}
|
||||
{{/dynamicOperations}}
|
||||
{{#dynamicOperations}}
|
||||
localVarPath = localVarApiClient.fillParametersFromOperation(operation, paramMap, localVarPath, localVarQueryParams, localVarCollectionQueryParams, localVarHeaderParams, localVarCookieParams);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,42 @@
|
||||
openapi: 3.0.3
|
||||
info:
|
||||
title: Example Hello API
|
||||
description: ''
|
||||
version: v1
|
||||
servers:
|
||||
- url: http://localhost
|
||||
description: Global Endpoint
|
||||
paths:
|
||||
/v1/hello/{name}:
|
||||
get:
|
||||
tags:
|
||||
- hello_example
|
||||
operationId: Hello
|
||||
description: Say Hello
|
||||
parameters:
|
||||
- name: X-CUSTOM_CONSTANT_HEADER
|
||||
in: header
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
enum:
|
||||
- CONSTANT_VALUE
|
||||
- name: name
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
default:
|
||||
description: Successful operation
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/HelloResponse'
|
||||
components:
|
||||
schemas:
|
||||
HelloResponse:
|
||||
type: object
|
||||
properties:
|
||||
message:
|
||||
type: string
|
Loading…
x
Reference in New Issue
Block a user