diff --git a/bin/configs/java-native-jackson3.yaml b/bin/configs/java-native-jackson3.yaml index 2be924aa84d4..cea9d7351c3e 100644 --- a/bin/configs/java-native-jackson3.yaml +++ b/bin/configs/java-native-jackson3.yaml @@ -10,3 +10,4 @@ additionalProperties: useReflectionEqualsHashCode: "true" useJackson3: "true" openApiNullable: "false" + generateJsonCreator: "true" diff --git a/docs/generators/java-microprofile.md b/docs/generators/java-microprofile.md index 537d276cb429..287ef1001887 100644 --- a/docs/generators/java-microprofile.md +++ b/docs/generators/java-microprofile.md @@ -58,6 +58,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |generateClientAsBean|For resttemplate, restclient and webclient, configure whether to create `ApiClient.java` and Apis clients as bean (with `@Component` annotation).| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| |generateInsecureTlsHook|Generate the hook that disables TLS certificate validation and trusts all certificates (default to true): ApiClient.disableCertificateValidation on jersey2/jersey3, ApiClient.setVerifyingSsl(false) on okhttp. Set to false to omit it, e.g. when static analysis flags the trust-all TrustManager it contains. Available on `jersey2`, `jersey3`, `okhttp` libraries.| |true| +|generateJsonCreator|Whether to generate a `@JsonCreator` constructor for required properties, so that deserialization fails when a required property is missing (native library only).| |false| |gradleProperties|Append additional Gradle properties to the gradle.properties file| |null| |groupId|groupId in generated pom.xml| |org.openapitools| |hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |false| diff --git a/docs/generators/java.md b/docs/generators/java.md index 53ab5ed323ac..8cc7f4a8da08 100644 --- a/docs/generators/java.md +++ b/docs/generators/java.md @@ -58,6 +58,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |generateClientAsBean|For resttemplate, restclient and webclient, configure whether to create `ApiClient.java` and Apis clients as bean (with `@Component` annotation).| |false| |generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false| |generateInsecureTlsHook|Generate the hook that disables TLS certificate validation and trusts all certificates (default to true): ApiClient.disableCertificateValidation on jersey2/jersey3, ApiClient.setVerifyingSsl(false) on okhttp. Set to false to omit it, e.g. when static analysis flags the trust-all TrustManager it contains. Available on `jersey2`, `jersey3`, `okhttp` libraries.| |true| +|generateJsonCreator|Whether to generate a `@JsonCreator` constructor for required properties, so that deserialization fails when a required property is missing (native library only).| |false| |gradleProperties|Append additional Gradle properties to the gradle.properties file| |null| |groupId|groupId in generated pom.xml| |org.openapitools| |hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |false| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index 74091aeb45c9..7be4baae2ab8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -125,6 +125,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen public static final String USE_SEALED_ONE_OF_INTERFACES = "useSealedOneOfInterfaces"; public static final String USE_UNARY_INTERCEPTOR = "useUnaryInterceptor"; public static final String USE_JACKSON_3 = "useJackson3"; + public static final String GENERATE_JSON_CREATOR = "generateJsonCreator"; // Internal configurations public static final String SINGLE_REQUEST_PARAMETER = "singleRequestParameter"; @@ -139,6 +140,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen private static final String JACKSON2_PACKAGE = "com.fasterxml.jackson"; private static final String JACKSON3_PACKAGE = "tools.jackson"; private static final String JACKSON_PACKAGE = "jacksonPackage"; + private static final String JSON_CREATOR_VARS = "x-java-json-creator-vars"; public static final String GENERATE_CLIENT_AS_BEAN = "generateClientAsBean"; @@ -176,6 +178,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen @Setter protected boolean useSealedOneOfInterfaces = false; @Setter protected boolean useUnaryInterceptor = false; @Getter @Setter protected boolean useJackson3 = false; + @Getter @Setter protected boolean generateJsonCreator = false; protected String authFolder; /** @@ -299,6 +302,7 @@ public JavaClientCodegen() { cliOptions.add(CliOption.newBoolean(USE_ENUM_CASE_INSENSITIVE, "Use `equalsIgnoreCase` when String for enum comparison", useEnumCaseInsensitive)); cliOptions.add(CliOption.newBoolean(FAIL_ON_UNKNOWN_PROPERTIES, "Fail Jackson de-serialization on unknown properties", this.failOnUnknownProperties)); cliOptions.add(CliOption.newBoolean(USE_JACKSON_3, "Use Jackson 3 instead of Jackson 2. Supported for 'native', 'apache-httpclient', 'jersey3', 'okhttp', and 'rest-assured' libraries (requires Java 17+) and for Spring 'resttemplate', 'webclient', and 'restclient' libraries (require useSpringBoot4=true).", this.useJackson3)); + cliOptions.add(CliOption.newBoolean(GENERATE_JSON_CREATOR, "Whether to generate a `@JsonCreator` constructor for required properties, so that deserialization fails when a required property is missing (native library only).", this.generateJsonCreator)); cliOptions.add(CliOption.newBoolean(SUPPORT_VERTX_FUTURE, "Also generate api methods that return a vertx Future instead of taking a callback. Only `vertx` supports this option. Requires vertx 4 or greater.", this.supportVertxFuture)); cliOptions.add(CliOption.newBoolean(USE_SEALED_ONE_OF_INTERFACES, "Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient, RestClient and Microprofile (with Jackson).", this.useSealedOneOfInterfaces)); cliOptions.add(CliOption.newBoolean(USE_UNARY_INTERCEPTOR, "If true it will generate ResponseInterceptors using a UnaryOperator. This can be usefull for manipulating the request before it gets passed, for example doing your own decryption", this.useUnaryInterceptor)); @@ -424,6 +428,7 @@ public void processOpts() { SERIALIZATION_LIBRARY_JACKSON.equals(additionalProperties.get(CodegenConstants.SERIALIZATION_LIBRARY)); convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, this::setUseOneOfDiscriminatorLookup); convertPropertyToBooleanAndWriteBack(USE_JACKSON_3, this::setUseJackson3); + convertPropertyToBooleanAndWriteBack(GENERATE_JSON_CREATOR, this::setGenerateJsonCreator); convertPropertyToBooleanAndWriteBack(USE_SPRING_BOOT4, this::setUseSpringBoot4); if (useJackson3 && (libRestClient || libRestTemplate || libWebClient) && !useSpringBoot4) { throw new IllegalArgumentException("useJackson3 for the restclient, resttemplate, and webclient libraries requires useSpringBoot4=true"); @@ -1411,6 +1416,18 @@ public Map postProcessAllModels(Map objs) if (isLibrary(OKHTTP)) { pruneUnusedOkHttpModelImports(objs); } + if (isLibrary(NATIVE) && this.jackson) { + // The native library deserializes models through their no-arg constructor, so required + // properties are not enforced by Jackson. A @JsonCreator constructor is needed to make + // deserialization fail when a required property is missing, which is what allows oneOf + // variants with different required properties to be told apart. + for (CodegenModel cm : getAllModels(objs).values()) { + if (cm.isEnum) { + continue; + } + addJsonCreatorVendorExtensions(cm); + } + } return objs; } @@ -1497,6 +1514,137 @@ private static boolean declaresPropertyOfType(CodegenModel cm, String simpleName || (v.datatypeWithEnum != null && type.matcher(v.datatypeWithEnum).find())); } + private void addJsonCreatorVendorExtensions(CodegenModel cm) { + if (generateJsonCreator && !canGenerateJsonCreator(cm)) { + if (hasIncompatibleOverride(cm)) { + LOGGER.warn("Skipping the @JsonCreator constructor for model '{}' because it overrides an inherited property with a different type", cm.name); + } else { + LOGGER.debug("Skipping the @JsonCreator constructor for model '{}' because an ancestor cannot generate one", cm.name); + } + return; + } + List creatorVars = getJsonCreatorVars(cm); + if (creatorVars.isEmpty()) { + return; + } + + Set ownNames = new HashSet<>(); + for (CodegenProperty property : cm.vars) { + ownNames.add(property.name); + } + List assignVars = new ArrayList<>(); + for (CodegenProperty property : creatorVars) { + if (ownNames.contains(property.name)) { + assignVars.add(property); + } + } + + String superCall; + if (generateJsonCreator && cm.getParentModel() != null) { + StringBuilder sb = new StringBuilder("super("); + boolean first = true; + for (CodegenProperty property : getJsonCreatorVars(cm.getParentModel())) { + if (!first) { + sb.append(", "); + } + sb.append(property.name); + first = false; + } + superCall = sb.append(")").toString(); + } else { + superCall = "this()"; + } + + cm.vendorExtensions.put("x-java-json-creator", true); + cm.vendorExtensions.put(JSON_CREATOR_VARS, creatorVars); + cm.vendorExtensions.put("x-java-json-creator-assign-vars", assignVars); + cm.vendorExtensions.put("x-java-json-creator-super-call", superCall); + } + + /** + * Returns true when a property defined by this model reuses the name of an inherited + * property with a different Java type. Such a model cannot have a constructor that both + * assigns the child field and calls the parent constructor, so no creator is generated and + * the model keeps its historical no-arg deserialization. + */ + private boolean hasIncompatibleOverride(CodegenModel cm) { + CodegenModel parent = cm.getParentModel(); + if (parent == null) { + return false; + } + Map inheritedTypes = new HashMap<>(); + for (CodegenProperty property : getJsonCreatorVars(parent)) { + inheritedTypes.put(property.name, property.datatypeWithEnum); + } + for (CodegenProperty property : cm.vars) { + String inheritedType = inheritedTypes.get(property.name); + if (inheritedType != null && !inheritedType.equals(property.datatypeWithEnum)) { + return true; + } + } + return false; + } + + /** + * Returns true when this model and all its ancestors can have a {@code @JsonCreator} + * constructor. If an ancestor cannot (because of an incompatible property override), its + * descendants must not call a non-existent parent constructor. + */ + private boolean canGenerateJsonCreator(CodegenModel cm) { + if (hasIncompatibleOverride(cm)) { + return false; + } + CodegenModel parent = cm.getParentModel(); + return parent == null || canGenerateJsonCreator(parent); + } + + /** + * Returns the constructor parameters for the {@code @JsonCreator} constructor of the given + * model, in the order they must be passed to the parent constructor. + */ + @SuppressWarnings("unchecked") + private List getJsonCreatorVars(CodegenModel cm) { + Object cached = cm.vendorExtensions.get(JSON_CREATOR_VARS); + if (cached instanceof List) { + return (List) cached; + } + + List vars = new ArrayList<>(); + Set names = new HashSet<>(); + + if (!generateJsonCreator) { + // Preserve the historical behaviour: a constructor holding the read-only properties only. + for (CodegenProperty property : cm.readOnlyVars) { + if (names.add(property.name)) { + vars.add(property); + } + } + return vars; + } + + CodegenModel parent = cm.getParentModel(); + if (parent != null) { + vars.addAll(getJsonCreatorVars(parent)); + } + for (CodegenProperty property : cm.vars) { + int index = -1; + for (int i = 0; i < vars.size(); i++) { + if (vars.get(i).name.equals(property.name)) { + index = i; + break; + } + } + if (index >= 0) { + // an overridden property keeps the slot of the inherited one, but uses the type of + // the child so the generated field assignment compiles + vars.set(index, property); + } else if (property.required || property.isReadOnly) { + vars.add(property); + } + } + return vars; + } + @Override public ModelsMap postProcessModelsEnum(ModelsMap objs) { objs = super.postProcessModelsEnum(objs); diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/build.gradle.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/build.gradle.mustache index d4653bd47540..460245d05e9d 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/native/build.gradle.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/build.gradle.mustache @@ -130,6 +130,20 @@ dependencies { implementation "org.openapitools:jackson-databind-nullable:0.2.13" {{/openApiNullable}} {{/useJackson3}} + {{#withXml}} + {{#useJackson3}} + implementation "tools.jackson.dataformat:jackson-dataformat-xml:$jackson3_version" + {{/useJackson3}} + {{^useJackson3}} + implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:$jackson_version" + {{/useJackson3}} + {{#useJakartaEe}} + implementation "jakarta.xml.bind:jakarta.xml.bind-api:4.0.0" + {{/useJakartaEe}} + {{^useJakartaEe}} + implementation "javax.xml.bind:jaxb-api:2.3.1" + {{/useJakartaEe}} + {{/withXml}} {{#useJspecify}} implementation "org.jspecify:jspecify:1.0.0" {{/useJspecify}} diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/model.mustache index de11a5bd86dd..2d776d6a23c1 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/native/model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/model.mustache @@ -33,11 +33,11 @@ import java.io.Serializable; {{#jackson}} import com.fasterxml.jackson.annotation.JsonPropertyOrder; {{#withXml}} -import com.fasterxml.jackson.dataformat.xml.annotation.*; +import {{jacksonPackage}}.dataformat.xml.annotation.*; {{/withXml}} -{{#vendorExtensions.x-has-readonly-properties}} +{{#vendorExtensions.x-java-json-creator}} import com.fasterxml.jackson.annotation.JsonCreator; -{{/vendorExtensions.x-has-readonly-properties}} +{{/vendorExtensions.x-java-json-creator}} {{/jackson}} {{#withXml}} import {{javaxPackage}}.xml.bind.annotation.*; diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/pojo.mustache index e983f0d8e211..527dbe903990 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/native/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/pojo.mustache @@ -85,19 +85,30 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens public {{classname}}() { {{#parent}}{{#parcelableModel}} super();{{/parcelableModel}}{{/parent}}{{#gson}}{{#discriminator}} this.{{{discriminatorName}}} = this.getClass().getSimpleName();{{/discriminator}}{{/gson}} - }{{#vendorExtensions.x-has-readonly-properties}}{{^withXml}} + }{{#vendorExtensions.x-java-json-creator}} - {{#jackson}}@JsonCreator{{/jackson}} + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public {{classname}}( - {{#readOnlyVars}} - @JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}}) {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}} - {{/readOnlyVars}} + {{#vendorExtensions.x-java-json-creator-vars}} + @JsonProperty(value = JSON_PROPERTY_{{nameInSnakeCase}}, required = {{required}}) + @JsonInclude({{#isMap}}{{#items.isNullable}}content = JsonInclude.Include.ALWAYS, {{/items.isNullable}}{{/isMap}}value = JsonInclude.Include.{{#required}}ALWAYS{{/required}}{{^required}}USE_DEFAULTS{{/required}}) +{{#withXml}} + @JacksonXmlProperty(localName = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#isXmlAttribute}}, isAttribute = true{{/isXmlAttribute}}{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}}) +{{#isContainer}} + @JacksonXmlElementWrapper({{#isXmlWrapped}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}", {{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}{{/isXmlWrapped}}useWrapping = {{isXmlWrapped}}) +{{/isContainer}} +{{/withXml}} + {{>nullableArgumentWithEnum}} {{name}}{{^-last}},{{/-last}} + {{/vendorExtensions.x-java-json-creator-vars}} ) { - this(); - {{#readOnlyVars}} + {{{vendorExtensions.x-java-json-creator-super-call}}}; + {{#vendorExtensions.x-java-json-creator-assign-vars}} this.{{name}} = {{#vendorExtensions.x-is-jackson-optional-nullable}}{{name}} == null ? JsonNullable.<{{{datatypeWithEnum}}}>undefined() : JsonNullable.of({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{name}}{{/vendorExtensions.x-is-jackson-optional-nullable}}; - {{/readOnlyVars}} - }{{/withXml}}{{/vendorExtensions.x-has-readonly-properties}} + {{/vendorExtensions.x-java-json-creator-assign-vars}} + }{{/vendorExtensions.x-java-json-creator}} {{#vars}} {{^isReadOnly}} diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/pom.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/pom.mustache index 89691d4111e8..91f33486c07b 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/native/pom.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/pom.mustache @@ -267,6 +267,37 @@ ${jackson-databind-nullable-version} {{/useJackson3}} + {{#withXml}} + + {{#useJackson3}} + + tools.jackson.dataformat + jackson-dataformat-xml + ${jackson3-version} + + {{/useJackson3}} + {{^useJackson3}} + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + ${jackson-version} + + {{/useJackson3}} + {{#useJakartaEe}} + + jakarta.xml.bind + jakarta.xml.bind-api + 4.0.0 + + {{/useJakartaEe}} + {{^useJakartaEe}} + + javax.xml.bind + jaxb-api + 2.3.1 + + {{/useJakartaEe}} + {{/withXml}} {{^useJspecify}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java index fa4b47e324ca..aa60f13a7e8d 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java @@ -952,6 +952,119 @@ public void testJdkHttpClientWithAndWithoutDiscriminator() { .contains("import xyz.abcdef.invoker.JSON;"); } + @Test + public void testNativeGenerateJsonCreatorForRequiredProperties() throws IOException { + final Path output = newTempFolder(); + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName(JAVA_GENERATOR) + .setLibrary(JavaClientCodegen.NATIVE) + .addAdditionalProperty(CodegenConstants.API_PACKAGE, "xyz.abcdef.api") + .addAdditionalProperty(CodegenConstants.MODEL_PACKAGE, "xyz.abcdef.model") + .addAdditionalProperty(JavaClientCodegen.USE_JACKSON_3, true) + .addAdditionalProperty(JavaClientCodegen.GENERATE_JSON_CREATOR, true) + .setInputSpec("src/test/resources/3_0/java/native/required-oneof.yaml") + .setOutputDir(output.toString().replace("\\", "/")); + + List files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate(); + + validateJavaSourceFiles(files); + + Path service = output.resolve("src/main/java/xyz/abcdef/model/CoreIntentAuthorService.java"); + assertThat(service).content().contains( + "@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)", + "public CoreIntentAuthorService(", + "@JsonProperty(value = JSON_PROPERTY_SUBJECT, required = true)", + "public CoreIntentAuthorService() {"); + assertThat(Files.readString(service)) + .containsOnlyOnce("@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)"); + + assertThat(output.resolve("src/main/java/xyz/abcdef/model/CoreIntentAuthorUser.java")).content().contains( + "public CoreIntentAuthorUser(", + "@JsonProperty(value = JSON_PROPERTY_ID, required = true)", + "@JsonProperty(value = JSON_PROPERTY_DOMAIN_ID, required = true)"); + + // inherited required properties are passed to the parent constructor + assertThat(output.resolve("src/main/java/xyz/abcdef/model/ChildModel.java")).content().contains( + "public class ChildModel extends BaseModel", + "public ChildModel(", + "super(baseId, kind);", + "@JsonProperty(value = JSON_PROPERTY_CHILD_ID, required = true)"); + + // a required property and a read-only property share a single creator + Path readOnlyModel = output.resolve("src/main/java/xyz/abcdef/model/ReadOnlyModel.java"); + assertThat(readOnlyModel).content().contains( + "@JsonProperty(value = JSON_PROPERTY_ID, required = true)", + "@JsonProperty(value = JSON_PROPERTY_CREATED_AT, required = false)"); + assertThat(Files.readString(readOnlyModel)) + .containsOnlyOnce("@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)"); + + // a required nullable property is still required, only its value may be null + assertThat(output.resolve("src/main/java/xyz/abcdef/model/NullableRequiredModel.java")).content().contains( + "@JsonProperty(value = JSON_PROPERTY_ID, required = true)", + "@JsonProperty(value = JSON_PROPERTY_LABEL, required = false)"); + + // a model overriding an inherited property with an incompatible type, and its descendants, + // fall back to the no-arg constructor instead of generating uncompilable code + assertThat(output.resolve("src/main/java/xyz/abcdef/model/OverrideBase.java")).content() + .contains("@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)"); + assertThat(output.resolve("src/main/java/xyz/abcdef/model/OverrideChild.java")).content() + .doesNotContain("@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)"); + assertThat(output.resolve("src/main/java/xyz/abcdef/model/OverrideGrandChild.java")).content() + .doesNotContain("@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)"); + } + + @Test + public void testNativeGenerateJsonCreatorWithXmlAndJackson3() { + final Path output = newTempFolder(); + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName(JAVA_GENERATOR) + .setLibrary(JavaClientCodegen.NATIVE) + .addAdditionalProperty(CodegenConstants.API_PACKAGE, "xyz.abcdef.api") + .addAdditionalProperty(CodegenConstants.MODEL_PACKAGE, "xyz.abcdef.model") + .addAdditionalProperty(CodegenConstants.WITH_XML, true) + .addAdditionalProperty(JavaClientCodegen.USE_JACKSON_3, true) + .addAdditionalProperty(JavaClientCodegen.GENERATE_JSON_CREATOR, true) + .setInputSpec("src/test/resources/3_0/java/native/required-oneof.yaml") + .setOutputDir(output.toString().replace("\\", "/")); + + List files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate(); + + validateJavaSourceFiles(files); + assertThat(output.resolve("pom.xml")).content().contains( + "tools.jackson.dataformat", + "jackson-dataformat-xml", + "javax.xml.bind", + "jaxb-api"); + assertThat(output.resolve("build.gradle")).content().contains( + "tools.jackson.dataformat:jackson-dataformat-xml", + "javax.xml.bind:jaxb-api"); + assertThat(output.resolve("src/main/java/xyz/abcdef/model/CoreIntentAuthorService.java")).content().contains( + // Jackson 3 XML annotations live in tools.jackson.dataformat + "import tools.jackson.dataformat.xml.annotation.*;", + "@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)", + "@JacksonXmlProperty(localName = \"subject\", isAttribute = true)", + "@JsonProperty(value = JSON_PROPERTY_SUBJECT, required = true)"); + } + + @Test + public void testNativeJsonCreatorDisabledByDefault() { + final Path output = newTempFolder(); + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName(JAVA_GENERATOR) + .setLibrary(JavaClientCodegen.NATIVE) + .addAdditionalProperty(CodegenConstants.API_PACKAGE, "xyz.abcdef.api") + .addAdditionalProperty(CodegenConstants.MODEL_PACKAGE, "xyz.abcdef.model") + .addAdditionalProperty(JavaClientCodegen.USE_JACKSON_3, true) + .setInputSpec("src/test/resources/3_0/java/native/required-oneof.yaml") + .setOutputDir(output.toString().replace("\\", "/")); + + List files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate(); + + validateJavaSourceFiles(files); + assertThat(output.resolve("src/main/java/xyz/abcdef/model/CoreIntentAuthorService.java")).content() + .doesNotContain("@JsonCreator"); + } + @Test public void testJdkHttpAsyncClient() { final Path output = newTempFolder(); diff --git a/modules/openapi-generator/src/test/resources/3_0/java/native/required-oneof.yaml b/modules/openapi-generator/src/test/resources/3_0/java/native/required-oneof.yaml new file mode 100644 index 000000000000..61c2b2662a66 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/java/native/required-oneof.yaml @@ -0,0 +1,117 @@ +openapi: 3.0.3 +info: + title: Required oneOf + version: 1.0.0 +paths: + /author: + get: + operationId: getAuthor + responses: + '200': + description: ok + content: + application/json: + schema: + $ref: '#/components/schemas/Core_IntentAuthor' +components: + schemas: + Core_IntentAuthor: + oneOf: + - $ref: '#/components/schemas/Core_IntentAuthor_Service' + - $ref: '#/components/schemas/Core_IntentAuthor_User' + Core_IntentAuthor_Service: + type: object + required: + - subject + properties: + subject: + type: string + xml: + attribute: true + Core_IntentAuthor_User: + type: object + required: + - id + - domainId + properties: + id: + type: string + xml: + attribute: true + domainId: + type: string + xml: + attribute: true + nickname: + type: string + BaseModel: + type: object + discriminator: + propertyName: kind + required: + - baseId + - kind + properties: + baseId: + type: string + kind: + type: string + ChildModel: + allOf: + - $ref: '#/components/schemas/BaseModel' + - type: object + required: + - childId + properties: + childId: + type: string + ReadOnlyModel: + type: object + required: + - id + properties: + id: + type: string + createdAt: + type: string + readOnly: true + NullableRequiredModel: + type: object + required: + - id + properties: + id: + type: string + nullable: true + label: + type: string + OverrideBase: + type: object + discriminator: + propertyName: kind + required: + - kind + - type + properties: + kind: + type: string + type: + type: string + OverrideChild: + allOf: + - $ref: '#/components/schemas/OverrideBase' + - type: object + properties: + type: + type: string + enum: + - WEBHOOK + OverrideGrandChild: + allOf: + - $ref: '#/components/schemas/OverrideChild' + - type: object + required: + - extra + properties: + extra: + type: string diff --git a/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/HasOnlyReadOnly.java b/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/HasOnlyReadOnly.java index 8402111e3cf5..c787c2d8ed54 100644 --- a/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/HasOnlyReadOnly.java +++ b/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/HasOnlyReadOnly.java @@ -49,12 +49,19 @@ public class HasOnlyReadOnly { public HasOnlyReadOnly() { } - @JsonCreator + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public HasOnlyReadOnly( - @JsonProperty(JSON_PROPERTY_BAR) String bar, - @JsonProperty(JSON_PROPERTY_FOO) String foo + @JsonProperty(value = JSON_PROPERTY_BAR, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable String bar, + @JsonProperty(value = JSON_PROPERTY_FOO, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable String foo ) { - this(); + this(); this.bar = bar; this.foo = foo; } diff --git a/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/Name.java b/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/Name.java index 534a7826109a..add0d7fc064b 100644 --- a/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/Name.java +++ b/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/Name.java @@ -59,12 +59,19 @@ public class Name { public Name() { } - @JsonCreator + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public Name( - @JsonProperty(JSON_PROPERTY_SNAKE_CASE) Integer snakeCase, - @JsonProperty(JSON_PROPERTY_123NUMBER) Integer _123number + @JsonProperty(value = JSON_PROPERTY_SNAKE_CASE, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable Integer snakeCase, + @JsonProperty(value = JSON_PROPERTY_123NUMBER, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable Integer _123number ) { - this(); + this(); this.snakeCase = snakeCase; this._123number = _123number; } diff --git a/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/ReadOnlyFirst.java b/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/ReadOnlyFirst.java index 4137901efa1a..0465da7caac6 100644 --- a/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/ReadOnlyFirst.java +++ b/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/ReadOnlyFirst.java @@ -49,11 +49,16 @@ public class ReadOnlyFirst { public ReadOnlyFirst() { } - @JsonCreator + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public ReadOnlyFirst( - @JsonProperty(JSON_PROPERTY_BAR) String bar + @JsonProperty(value = JSON_PROPERTY_BAR, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable String bar ) { - this(); + this(); this.bar = bar; } diff --git a/samples/client/petstore/java/native-jackson3-jspecify/src/main/java/org/openapitools/client/model/FileContent.java b/samples/client/petstore/java/native-jackson3-jspecify/src/main/java/org/openapitools/client/model/FileContent.java index 1c66f15f1e0e..305f1e7c725e 100644 --- a/samples/client/petstore/java/native-jackson3-jspecify/src/main/java/org/openapitools/client/model/FileContent.java +++ b/samples/client/petstore/java/native-jackson3-jspecify/src/main/java/org/openapitools/client/model/FileContent.java @@ -91,13 +91,22 @@ public static VirusScanEnum fromValue(String value) { public FileContent() { } - @JsonCreator + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public FileContent( - @JsonProperty(JSON_PROPERTY_NAME) String name, - @JsonProperty(JSON_PROPERTY_SIZE) Integer size, - @JsonProperty(JSON_PROPERTY_VIRUS_SCAN) VirusScanEnum virusScan + @JsonProperty(value = JSON_PROPERTY_NAME, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + String name, + @JsonProperty(value = JSON_PROPERTY_SIZE, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @Nullable Integer size, + @JsonProperty(value = JSON_PROPERTY_VIRUS_SCAN, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @Nullable VirusScanEnum virusScan ) { - this(); + this(); this.name = name; this.size = size; this.virusScan = virusScan; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Animal.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Animal.java index 4ba1d3520876..8921e6420d1f 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Animal.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Animal.java @@ -64,6 +64,19 @@ public class Animal { public Animal() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public Animal( + @JsonProperty(value = JSON_PROPERTY_CLASS_NAME, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String className + ) { + this(); + this.className = className; + } + public Animal className(@javax.annotation.Nonnull String className) { this.className = className; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/AppleReq.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/AppleReq.java index 1f844dc966ad..2a4955b52cb4 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/AppleReq.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/AppleReq.java @@ -51,6 +51,19 @@ public class AppleReq { public AppleReq() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public AppleReq( + @JsonProperty(value = JSON_PROPERTY_CULTIVAR, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String cultivar + ) { + this(); + this.cultivar = cultivar; + } + public AppleReq cultivar(@javax.annotation.Nonnull String cultivar) { this.cultivar = cultivar; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/BananaReq.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/BananaReq.java index 5db4beebe63a..c11e442aa14e 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/BananaReq.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/BananaReq.java @@ -52,6 +52,19 @@ public class BananaReq { public BananaReq() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public BananaReq( + @JsonProperty(value = JSON_PROPERTY_LENGTH_CM, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull BigDecimal lengthCm + ) { + this(); + this.lengthCm = lengthCm; + } + public BananaReq lengthCm(@javax.annotation.Nonnull BigDecimal lengthCm) { this.lengthCm = lengthCm; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/BasquePig.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/BasquePig.java index 7588236799e4..d7f7d4773815 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/BasquePig.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/BasquePig.java @@ -45,6 +45,19 @@ public class BasquePig { public BasquePig() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public BasquePig( + @JsonProperty(value = JSON_PROPERTY_CLASS_NAME, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String className + ) { + this(); + this.className = className; + } + public BasquePig className(@javax.annotation.Nonnull String className) { this.className = className; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Cat.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Cat.java index 81b4bf4b78b6..dd2fcb656642 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Cat.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Cat.java @@ -57,6 +57,18 @@ public class Cat extends Animal { public Cat() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public Cat( + @JsonProperty(value = JSON_PROPERTY_CLASS_NAME, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String className + ) { + super(className); + } + public Cat declawed(@javax.annotation.Nullable Boolean declawed) { this.declawed = declawed; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Category.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Category.java index ae94c2191761..e639efc91d7c 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Category.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Category.java @@ -50,6 +50,19 @@ public class Category { public Category() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public Category( + @JsonProperty(value = JSON_PROPERTY_NAME, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String name + ) { + this(); + this.name = name; + } + public Category id(@javax.annotation.Nullable Long id) { this.id = id; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ChildCat.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ChildCat.java index 814c506b6af8..f365e2755e93 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ChildCat.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ChildCat.java @@ -63,6 +63,19 @@ public class ChildCat extends ParentPet { public ChildCat() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public ChildCat( + @JsonProperty(value = JSON_PROPERTY_PET_TYPE, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable String petType + ) { + super(petType); + this.petType = petType; + } + public ChildCat name(@javax.annotation.Nullable String name) { this.name = name; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java index ffe3a2f1011e..220c3f488db6 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java @@ -50,6 +50,23 @@ public class ComplexQuadrilateral { public ComplexQuadrilateral() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public ComplexQuadrilateral( + @JsonProperty(value = JSON_PROPERTY_SHAPE_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String shapeType, + @JsonProperty(value = JSON_PROPERTY_QUADRILATERAL_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String quadrilateralType + ) { + this(); + this.shapeType = shapeType; + this.quadrilateralType = quadrilateralType; + } + public ComplexQuadrilateral shapeType(@javax.annotation.Nonnull String shapeType) { this.shapeType = shapeType; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/DanishPig.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/DanishPig.java index cecf17cf96c1..19a612836a97 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/DanishPig.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/DanishPig.java @@ -45,6 +45,19 @@ public class DanishPig { public DanishPig() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public DanishPig( + @JsonProperty(value = JSON_PROPERTY_CLASS_NAME, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String className + ) { + this(); + this.className = className; + } + public DanishPig className(@javax.annotation.Nonnull String className) { this.className = className; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Dog.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Dog.java index 3f9ec62c6e85..edbc00fb466d 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Dog.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Dog.java @@ -56,6 +56,18 @@ public class Dog extends Animal { public Dog() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public Dog( + @JsonProperty(value = JSON_PROPERTY_CLASS_NAME, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String className + ) { + super(className); + } + public Dog breed(@javax.annotation.Nullable String breed) { this.breed = breed; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/EnumTest.java index ca3718190fa7..8ef897bf7736 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/EnumTest.java @@ -269,6 +269,19 @@ public static EnumNumberEnum fromValue(Double value) { public EnumTest() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public EnumTest( + @JsonProperty(value = JSON_PROPERTY_ENUM_STRING_REQUIRED, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull EnumStringRequiredEnum enumStringRequired + ) { + this(); + this.enumStringRequired = enumStringRequired; + } + public EnumTest enumString(@javax.annotation.Nullable EnumStringEnum enumString) { this.enumString = enumString; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/EquilateralTriangle.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/EquilateralTriangle.java index b3bcc719c982..93c9909dfd2a 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/EquilateralTriangle.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/EquilateralTriangle.java @@ -50,6 +50,23 @@ public class EquilateralTriangle { public EquilateralTriangle() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public EquilateralTriangle( + @JsonProperty(value = JSON_PROPERTY_SHAPE_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String shapeType, + @JsonProperty(value = JSON_PROPERTY_TRIANGLE_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String triangleType + ) { + this(); + this.shapeType = shapeType; + this.triangleType = triangleType; + } + public EquilateralTriangle shapeType(@javax.annotation.Nonnull String shapeType) { this.shapeType = shapeType; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/FormatTest.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/FormatTest.java index 31ae8988fc4f..b7aa753a99a2 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/FormatTest.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/FormatTest.java @@ -126,6 +126,31 @@ public class FormatTest { public FormatTest() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public FormatTest( + @JsonProperty(value = JSON_PROPERTY_NUMBER, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull BigDecimal number, + @JsonProperty(value = JSON_PROPERTY_BYTE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull byte[] _byte, + @JsonProperty(value = JSON_PROPERTY_DATE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull LocalDate date, + @JsonProperty(value = JSON_PROPERTY_PASSWORD, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String password + ) { + this(); + this.number = number; + this._byte = _byte; + this.date = date; + this.password = password; + } + public FormatTest integer(@javax.annotation.Nullable Integer integer) { this.integer = integer; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/GrandparentAnimal.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/GrandparentAnimal.java index 3838630e6c6e..1a8c19080fff 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/GrandparentAnimal.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/GrandparentAnimal.java @@ -59,6 +59,19 @@ public class GrandparentAnimal { public GrandparentAnimal() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public GrandparentAnimal( + @JsonProperty(value = JSON_PROPERTY_PET_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String petType + ) { + this(); + this.petType = petType; + } + public GrandparentAnimal petType(@javax.annotation.Nonnull String petType) { this.petType = petType; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/HasOnlyReadOnly.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/HasOnlyReadOnly.java index 98f4c53feb75..b8c8cb52240e 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/HasOnlyReadOnly.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/HasOnlyReadOnly.java @@ -51,12 +51,19 @@ public class HasOnlyReadOnly { public HasOnlyReadOnly() { } - @JsonCreator + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public HasOnlyReadOnly( - @JsonProperty(JSON_PROPERTY_BAR) String bar, - @JsonProperty(JSON_PROPERTY_FOO) String foo + @JsonProperty(value = JSON_PROPERTY_BAR, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable String bar, + @JsonProperty(value = JSON_PROPERTY_FOO, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable String foo ) { - this(); + this(); this.bar = bar; this.foo = foo; } diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java index 4cc06cba8325..557c23bcb8bf 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java @@ -50,6 +50,23 @@ public class IsoscelesTriangle { public IsoscelesTriangle() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public IsoscelesTriangle( + @JsonProperty(value = JSON_PROPERTY_SHAPE_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String shapeType, + @JsonProperty(value = JSON_PROPERTY_TRIANGLE_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String triangleType + ) { + this(); + this.shapeType = shapeType; + this.triangleType = triangleType; + } + public IsoscelesTriangle shapeType(@javax.annotation.Nonnull String shapeType) { this.shapeType = shapeType; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Name.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Name.java index be4cc607a493..09698a20dfba 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Name.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Name.java @@ -60,12 +60,23 @@ public class Name { public Name() { } - @JsonCreator + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public Name( - @JsonProperty(JSON_PROPERTY_SNAKE_CASE) Integer snakeCase, - @JsonProperty(JSON_PROPERTY_123NUMBER) Integer _123number + @JsonProperty(value = JSON_PROPERTY_NAME, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull Integer name, + @JsonProperty(value = JSON_PROPERTY_SNAKE_CASE, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable Integer snakeCase, + @JsonProperty(value = JSON_PROPERTY_123NUMBER, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable Integer _123number ) { - this(); + this(); + this.name = name; this.snakeCase = snakeCase; this._123number = _123number; } diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ParentPet.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ParentPet.java index ea7a1a735215..d8ec40937ef2 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ParentPet.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ParentPet.java @@ -54,6 +54,18 @@ public class ParentPet extends GrandparentAnimal { public ParentPet() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public ParentPet( + @JsonProperty(value = JSON_PROPERTY_PET_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String petType + ) { + super(petType); + } + @Override public ParentPet petType(@javax.annotation.Nonnull String petType) { this.setPetType(petType); diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Pet.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Pet.java index c5eed7562e7b..3433eb882297 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Pet.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Pet.java @@ -111,6 +111,23 @@ public static StatusEnum fromValue(String value) { public Pet() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public Pet( + @JsonProperty(value = JSON_PROPERTY_NAME, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String name, + @JsonProperty(value = JSON_PROPERTY_PHOTO_URLS, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull List photoUrls + ) { + this(); + this.name = name; + this.photoUrls = photoUrls; + } + public Pet id(@javax.annotation.Nullable Long id) { this.id = id; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/QuadrilateralInterface.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/QuadrilateralInterface.java index 7ddebe818fa9..5e487d46b4aa 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/QuadrilateralInterface.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/QuadrilateralInterface.java @@ -45,6 +45,19 @@ public class QuadrilateralInterface { public QuadrilateralInterface() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public QuadrilateralInterface( + @JsonProperty(value = JSON_PROPERTY_QUADRILATERAL_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String quadrilateralType + ) { + this(); + this.quadrilateralType = quadrilateralType; + } + public QuadrilateralInterface quadrilateralType(@javax.annotation.Nonnull String quadrilateralType) { this.quadrilateralType = quadrilateralType; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ReadOnlyFirst.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ReadOnlyFirst.java index 8a1287d73b06..d60bd101c56c 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ReadOnlyFirst.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ReadOnlyFirst.java @@ -50,11 +50,16 @@ public class ReadOnlyFirst { public ReadOnlyFirst() { } - @JsonCreator + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public ReadOnlyFirst( - @JsonProperty(JSON_PROPERTY_BAR) String bar + @JsonProperty(value = JSON_PROPERTY_BAR, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable String bar ) { - this(); + this(); this.bar = bar; } diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ScaleneTriangle.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ScaleneTriangle.java index 37c22f35a6ad..b84e5235cb8a 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ScaleneTriangle.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ScaleneTriangle.java @@ -50,6 +50,23 @@ public class ScaleneTriangle { public ScaleneTriangle() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public ScaleneTriangle( + @JsonProperty(value = JSON_PROPERTY_SHAPE_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String shapeType, + @JsonProperty(value = JSON_PROPERTY_TRIANGLE_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String triangleType + ) { + this(); + this.shapeType = shapeType; + this.triangleType = triangleType; + } + public ScaleneTriangle shapeType(@javax.annotation.Nonnull String shapeType) { this.shapeType = shapeType; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ShapeInterface.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ShapeInterface.java index 805f4a9db9ce..ee91a6035a2d 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ShapeInterface.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/ShapeInterface.java @@ -45,6 +45,19 @@ public class ShapeInterface { public ShapeInterface() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public ShapeInterface( + @JsonProperty(value = JSON_PROPERTY_SHAPE_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String shapeType + ) { + this(); + this.shapeType = shapeType; + } + public ShapeInterface shapeType(@javax.annotation.Nonnull String shapeType) { this.shapeType = shapeType; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java index 516b39d68e81..7a2c0a6e6756 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java @@ -50,6 +50,23 @@ public class SimpleQuadrilateral { public SimpleQuadrilateral() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public SimpleQuadrilateral( + @JsonProperty(value = JSON_PROPERTY_SHAPE_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String shapeType, + @JsonProperty(value = JSON_PROPERTY_QUADRILATERAL_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String quadrilateralType + ) { + this(); + this.shapeType = shapeType; + this.quadrilateralType = quadrilateralType; + } + public SimpleQuadrilateral shapeType(@javax.annotation.Nonnull String shapeType) { this.shapeType = shapeType; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/TriangleInterface.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/TriangleInterface.java index 252bc21fd4e2..35197414a9b8 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/TriangleInterface.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/TriangleInterface.java @@ -45,6 +45,19 @@ public class TriangleInterface { public TriangleInterface() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public TriangleInterface( + @JsonProperty(value = JSON_PROPERTY_TRIANGLE_TYPE, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String triangleType + ) { + this(); + this.triangleType = triangleType; + } + public TriangleInterface triangleType(@javax.annotation.Nonnull String triangleType) { this.triangleType = triangleType; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Whale.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Whale.java index a323ce39f9b1..aed17ca65162 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Whale.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Whale.java @@ -56,6 +56,19 @@ public class Whale { public Whale() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public Whale( + @JsonProperty(value = JSON_PROPERTY_CLASS_NAME, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String className + ) { + this(); + this.className = className; + } + public Whale hasBaleen(@javax.annotation.Nullable Boolean hasBaleen) { this.hasBaleen = hasBaleen; return this; diff --git a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Zebra.java b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Zebra.java index d79f17dafdce..2533cdc89a36 100644 --- a/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Zebra.java +++ b/samples/client/petstore/java/native-jackson3/src/main/java/org/openapitools/client/model/Zebra.java @@ -92,6 +92,19 @@ public static TypeEnum fromValue(String value) { public Zebra() { } + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public Zebra( + @JsonProperty(value = JSON_PROPERTY_CLASS_NAME, required = true) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + @javax.annotation.Nonnull String className + ) { + this(); + this.className = className; + } + public Zebra type(@javax.annotation.Nullable TypeEnum type) { this.type = type; return this; diff --git a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/HasOnlyReadOnly.java b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/HasOnlyReadOnly.java index 98f4c53feb75..b8c8cb52240e 100644 --- a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/HasOnlyReadOnly.java +++ b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/HasOnlyReadOnly.java @@ -51,12 +51,19 @@ public class HasOnlyReadOnly { public HasOnlyReadOnly() { } - @JsonCreator + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public HasOnlyReadOnly( - @JsonProperty(JSON_PROPERTY_BAR) String bar, - @JsonProperty(JSON_PROPERTY_FOO) String foo + @JsonProperty(value = JSON_PROPERTY_BAR, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable String bar, + @JsonProperty(value = JSON_PROPERTY_FOO, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable String foo ) { - this(); + this(); this.bar = bar; this.foo = foo; } diff --git a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/Name.java b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/Name.java index 6b4ec737154c..d0fe51870cd0 100644 --- a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/Name.java +++ b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/Name.java @@ -61,12 +61,19 @@ public class Name { public Name() { } - @JsonCreator + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public Name( - @JsonProperty(JSON_PROPERTY_SNAKE_CASE) Integer snakeCase, - @JsonProperty(JSON_PROPERTY_123NUMBER) Integer _123number + @JsonProperty(value = JSON_PROPERTY_SNAKE_CASE, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable Integer snakeCase, + @JsonProperty(value = JSON_PROPERTY_123NUMBER, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable Integer _123number ) { - this(); + this(); this.snakeCase = snakeCase; this._123number = _123number; } diff --git a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/ReadOnlyFirst.java b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/ReadOnlyFirst.java index 44d0480f2afe..30c80ae9843a 100644 --- a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/ReadOnlyFirst.java +++ b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/ReadOnlyFirst.java @@ -51,11 +51,16 @@ public class ReadOnlyFirst { public ReadOnlyFirst() { } - @JsonCreator + /** + * Constructor with required and read-only properties + */ + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public ReadOnlyFirst( - @JsonProperty(JSON_PROPERTY_BAR) String bar + @JsonProperty(value = JSON_PROPERTY_BAR, required = false) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + @javax.annotation.Nullable String bar ) { - this(); + this(); this.bar = bar; }