Skip to content

Commit

Permalink
[java] Intro openApiNullable property to enable/disable OpenAPI Jacks…
Browse files Browse the repository at this point in the history
…on Nullable library (#6154)

* Add option to prevent usage of jackson-nullable (#2901)

Add a option for all java client and server to prevent
usage of third party library (jackson-databind-nullable)
which may be forbidden in some company

Add samples for Vertx, Spring MVC, Spring Cloud, Feign and Play

Upgrade dependencies for org.openapitools:jackson-databind-nullable

* Samples - Remove dependency org.openapitools:jackson-databind-nullable (#2901)

* Fix generation of gradle file for vertx (#2901)

* Regenerate samples (#2901)

* Fix documentation and up to date (#2901)

* Fix forgotten regeneration of vertx after dependency integration (#2901)

* Regenerate template after rebase (#2901)

* Use yaml config files introduce in #6509 to manage samples (#2901)

* Regenerate template using the config (#2901)

* Fix bad version during testing generated samples (#2901)

* Regenerate template after fix bad version (#2901)

* Fix merge, allow for set importing on codegen model

Co-authored-by: Jim Schubert <james.schubert@gmail.com>
  • Loading branch information
Patouche and jimschubert authored Aug 31, 2020
1 parent 7032c40 commit b9662dc
Show file tree
Hide file tree
Showing 688 changed files with 68,382 additions and 388 deletions.
11 changes: 11 additions & 0 deletions bin/configs/java-feign-no-nullable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
generatorName: java
outputDir: samples/client/petstore/java/feign-no-nullable
library: feign
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/Java
additionalProperties:
booleanGetterPrefix: is
artifactId: petstore-feign-no-nullable
hideGenerationTimestamp: "true"
additionalModelTypeAnnotations: '@javax.annotation.concurrent.Immutable'
openApiNullable: "false"
7 changes: 7 additions & 0 deletions bin/configs/java-play-framework-no-nullable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
generatorName: java-play-framework
outputDir: samples/server/petstore/java-play-framework-no-nullable
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaPlayFramework
additionalProperties:
hideGenerationTimestamp: "true"
openApiNullable: "false"
9 changes: 9 additions & 0 deletions bin/configs/java-vertx-no-nullable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
generatorName: java
outputDir: samples/client/petstore/java/vertx-no-nullable
library: vertx
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/Java
additionalProperties:
artifactId: petstore-vertx-no-nullable
hideGenerationTimestamp: "true"
openApiNullable: "false"
11 changes: 11 additions & 0 deletions bin/configs/spring-boot-beanvalidation-no-nullable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
generatorName: spring
outputDir: samples/server/petstore/springboot-beanvalidation-no-nullable
library: spring-boot
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
java8: "false"
useBeanValidation: true
artifactId: spring-boot-beanvalidation-no-nullable
hideGenerationTimestamp: "true"
openApiNullable: "false"
10 changes: 10 additions & 0 deletions bin/configs/spring-cloud-no-nullable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
generatorName: spring
outputDir: samples/client/petstore/spring-cloud-no-nullable
library: spring-cloud
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud
additionalProperties:
artifactId: petstore-spring-cloud-no-nullable
responseWrapper: HystrixCommand
hideGenerationTimestamp: "true"
openApiNullable: "false"
10 changes: 10 additions & 0 deletions bin/configs/spring-mvc-no-nullable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
generatorName: spring
outputDir: samples/server/petstore/spring-mvc-no-nullable
library: spring-mvc
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
artifactId: spring-mvc-server-no-nullable
openApiNullable: "false"
serverPort: "8002"
hideGenerationTimestamp: "true"
1 change: 1 addition & 0 deletions docs/generators/groovy.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sidebar_label: groovy
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |org.openapitools.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/java-inflector.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sidebar_label: java-inflector
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |org.openapitools.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/java-msf4j.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ sidebar_label: java-msf4j
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |org.openapitools.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/java-pkmst.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ sidebar_label: java-pkmst
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |com.prokarma.pkmst.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/java-play-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ sidebar_label: java-play-framework
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |apimodels|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/java-undertow-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sidebar_label: java-undertow-server
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |null|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/java-vertx-web.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sidebar_label: java-vertx-web
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |org.openapitools.vertxweb.server.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/java-vertx.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sidebar_label: java-vertx
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |org.openapitools.server.api.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ sidebar_label: java
|licenseUrl|The URL of the license| |http://unlicense.org|
|microprofileFramework|Framework for microprofile. Possible values &quot;kumuluzee&quot;| |null|
|modelPackage|package for generated models| |org.openapitools.client.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parcelableModel|Whether to generate models for Android that implement Parcelable with the okhttp-gson library.| |false|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/jaxrs-cxf-cdi.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ sidebar_label: jaxrs-cxf-cdi
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |org.openapitools.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|openApiSpecFileLocation|Location where the file containing the spec will be generated in the output folder. No file generated when set to null or empty string.| |null|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/jaxrs-cxf-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sidebar_label: jaxrs-cxf-client
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |org.openapitools.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/jaxrs-cxf-extended.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ sidebar_label: jaxrs-cxf-extended
|licenseUrl|The URL of the license| |http://unlicense.org|
|loadTestDataFromFile|Load test data from a generated JSON file| |false|
|modelPackage|package for generated models| |org.openapitools.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/jaxrs-cxf.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ sidebar_label: jaxrs-cxf
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |org.openapitools.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/jaxrs-jersey.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ sidebar_label: jaxrs-jersey
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |org.openapitools.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/jaxrs-resteasy-eap.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ sidebar_label: jaxrs-resteasy-eap
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |org.openapitools.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/jaxrs-resteasy.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ sidebar_label: jaxrs-resteasy
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |org.openapitools.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/jaxrs-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ sidebar_label: jaxrs-spec
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |org.openapitools.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|openApiSpecFileLocation|Location where the file containing the spec will be generated in the output folder. No file generated when set to null or empty string.| |null|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ sidebar_label: spring
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |org.openapitools.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
public static final String BOOLEAN_GETTER_PREFIX = "booleanGetterPrefix";
public static final String ADDITIONAL_MODEL_TYPE_ANNOTATIONS = "additionalModelTypeAnnotations";
public static final String DISCRIMINATOR_CASE_SENSITIVE = "discriminatorCaseSensitive";
public static final String OPENAPI_NULLABLE = "openApiNullable";

protected String dateLibrary = "threetenbp";
protected boolean supportAsync = false;
Expand Down Expand Up @@ -100,6 +101,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
protected String parentVersion = "";
protected boolean parentOverridden = false;
protected List<String> additionalModelTypeAnnotations = new LinkedList<>();
protected boolean openApiNullable = true;

public AbstractJavaCodegen() {
super();
Expand Down Expand Up @@ -218,6 +220,7 @@ public AbstractJavaCodegen() {
cliOptions.add(CliOption.newBoolean(DISABLE_HTML_ESCAPING, "Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)", disableHtmlEscaping));
cliOptions.add(CliOption.newString(BOOLEAN_GETTER_PREFIX, "Set booleanGetterPrefix").defaultValue(this.getBooleanGetterPrefix()));
cliOptions.add(CliOption.newString(ADDITIONAL_MODEL_TYPE_ANNOTATIONS, "Additional annotations for model type(class level annotations)"));
cliOptions.add(CliOption.newBoolean(OPENAPI_NULLABLE, "Enable OpenAPI Jackson Nullable library", this.openApiNullable));

cliOptions.add(CliOption.newString(CodegenConstants.PARENT_GROUP_ID, CodegenConstants.PARENT_GROUP_ID_DESC));
cliOptions.add(CliOption.newString(CodegenConstants.PARENT_ARTIFACT_ID, CodegenConstants.PARENT_ARTIFACT_ID_DESC));
Expand Down Expand Up @@ -412,6 +415,11 @@ public void processOpts() {
}
additionalProperties.put(WITH_XML, withXml);

if (additionalProperties.containsKey(OPENAPI_NULLABLE)) {
this.setOpenApiNullable(Boolean.valueOf(additionalProperties.get(OPENAPI_NULLABLE).toString()));
}
additionalProperties.put(OPENAPI_NULLABLE, openApiNullable);

if (additionalProperties.containsKey(CodegenConstants.PARENT_GROUP_ID)) {
this.setParentGroupId((String) additionalProperties.get(CodegenConstants.PARENT_GROUP_ID));
}
Expand Down Expand Up @@ -1507,6 +1515,14 @@ public void setBooleanGetterPrefix(String booleanGetterPrefix) {
this.booleanGetterPrefix = booleanGetterPrefix;
}

public boolean isOpenApiNullable() {
return openApiNullable;
}

public void setOpenApiNullable(final boolean openApiNullable) {
this.openApiNullable = openApiNullable;
}

@Override
public String escapeQuotationMark(String input) {
// remove " to avoid code injection
Expand Down
Loading

0 comments on commit b9662dc

Please sign in to comment.