diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache index 8a1350c35431..ad68dd5463c4 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache @@ -990,7 +990,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { File file = (File) param.getValue(); FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()) .fileName(file.getName()).size(file.length()).build(); - + // Attempt to probe the content type for the file so that the form part is more correctly // and precisely identified, but fall back to application/octet-stream if that fails. MediaType type; @@ -999,7 +999,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { } catch (IOException | IllegalArgumentException e) { type = MediaType.APPLICATION_OCTET_STREAM_TYPE; } - + multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type)); } else { FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build(); diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache index c099cbd0e036..b17b14067d58 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pojo.mustache @@ -80,13 +80,22 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{/vendorExtensions.x-field-extra-annotation}} {{#vendorExtensions.x-is-jackson-optional-nullable}} {{#isContainer}} + {{#deprecated}} + @Deprecated + {{/deprecated}} private JsonNullable<{{{datatypeWithEnum}}}> {{name}} = JsonNullable.<{{{datatypeWithEnum}}}>undefined(); {{/isContainer}} {{^isContainer}} + {{#deprecated}} + @Deprecated + {{/deprecated}} private JsonNullable<{{{datatypeWithEnum}}}> {{name}} = JsonNullable.<{{{datatypeWithEnum}}}>{{#defaultValue}}of({{{.}}}){{/defaultValue}}{{^defaultValue}}undefined(){{/defaultValue}}; {{/isContainer}} {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^vendorExtensions.x-is-jackson-optional-nullable}} + {{#deprecated}} + @Deprecated + {{/deprecated}} private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}; {{/vendorExtensions.x-is-jackson-optional-nullable}} @@ -116,6 +125,9 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens )); {{/vendorExtensions.x-enum-as-string}} + {{#deprecated}} + @Deprecated + {{/deprecated}} public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) { {{#vendorExtensions.x-enum-as-string}} if (!{{{nameInSnakeCase}}}_VALUES.contains({{name}})) { @@ -256,6 +268,9 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{/vendorExtensions.x-is-jackson-optional-nullable}} {{^isReadOnly}} + {{#deprecated}} + @Deprecated + {{/deprecated}} {{#vendorExtensions.x-setter-extra-annotation}} {{{vendorExtensions.x-setter-extra-annotation}}} {{/vendorExtensions.x-setter-extra-annotation}}{{#jackson}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{> jackson_annotations}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{/jackson}} public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { {{#vendorExtensions.x-enum-as-string}} diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/ApiClient.mustache index 9da9ca4f2e7d..ad68dd5463c4 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/ApiClient.mustache @@ -119,13 +119,13 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { protected Integer serverIndex = 0; protected Map serverVariables = null; {{^hasOperationServers}} - protected Map> operationServers = new LinkedHashMap<>(); + protected Map> operationServers = new HashMap<>(); {{/hasOperationServers}} {{#hasOperationServers}} protected Map> operationServers; { - Map> operationServers = new LinkedHashMap<>(); + Map> operationServers = new HashMap<>(); {{#apiInfo}} {{#apis}} {{#operations}} @@ -992,14 +992,14 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { .fileName(file.getName()).size(file.length()).build(); // Attempt to probe the content type for the file so that the form part is more correctly - // and precisely identified, but fall back to application/octet-stream if that fails. + // and precisely identified, but fall back to application/octet-stream if that fails. MediaType type; try { type = MediaType.valueOf(Files.probeContentType(file.toPath())); } catch (IOException | IllegalArgumentException e) { type = MediaType.APPLICATION_OCTET_STREAM_TYPE; } - + multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type)); } else { FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build(); diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/oneof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/oneof_model.mustache index 043d75e97619..3b7069c0c295 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/oneof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/oneof_model.mustache @@ -60,7 +60,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im {{#useOneOfDiscriminatorLookup}} {{#discriminator}} {{classname}} new{{classname}} = new {{classname}}(); - Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); + Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); String discriminatorValue = (String)result2.get("{{{propertyBaseName}}}"); switch (discriminatorValue) { {{#mappedModels}} @@ -78,37 +78,74 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); int match = 0; JsonToken token = tree.traverse(jp.getCodec()).nextToken(); + {{#composedSchemas}} {{#oneOf}} - // deserialize {{{.}}} + // deserialize {{{dataType}}}{{#isNullable}} (nullable){{/isNullable}} try { + {{^isArray}} boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if ({{{.}}}.class.equals(Integer.class) || {{{.}}}.class.equals(Long.class) || {{{.}}}.class.equals(Float.class) || {{{.}}}.class.equals(Double.class) || {{{.}}}.class.equals(Boolean.class) || {{{.}}}.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= (({{{.}}}.class.equals(Integer.class) || {{{.}}}.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= (({{{.}}}.class.equals(Float.class) || {{{.}}}.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= ({{{.}}}.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= ({{{.}}}.class.equals(String.class) && token == JsonToken.VALUE_STRING); - {{#isNullable}} - attemptParsing |= (token == JsonToken.VALUE_NULL); - {{/isNullable}} - } + {{#isPrimitiveType}} + attemptParsing = typeCoercion; //respect type coercion setting + if (!attemptParsing) { + {{#isString}} + attemptParsing |= (token == JsonToken.VALUE_STRING); + {{/isString}} + {{#isInteger}} + attemptParsing |= (token == JsonToken.VALUE_NUMBER_INT); + {{/isInteger}} + {{#isLong}} + attemptParsing |= (token == JsonToken.VALUE_NUMBER_INT); + {{/isLong}} + {{#isShort}} + attemptParsing |= (token == JsonToken.VALUE_NUMBER_INT); + {{/isShort}} + {{#isFloat}} + attemptParsing |= (token == JsonToken.VALUE_NUMBER_FLOAT); + {{/isFloat}} + {{#isDouble}} + attemptParsing |= (token == JsonToken.VALUE_NUMBER_FLOAT); + {{/isDouble}} + {{#isNumber}} + attemptParsing |= (token == JsonToken.VALUE_NUMBER_FLOAT); + {{/isNumber}} + {{#isDecimal}} + attemptParsing |= (token == JsonToken.VALUE_NUMBER_FLOAT); + {{/isDecimal}} + {{#isBoolean}} + attemptParsing |= (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + {{/isBoolean}} + {{#isNullable}} + attemptParsing |= (token == JsonToken.VALUE_NULL); + {{/isNullable}} } + {{/isPrimitiveType}} if (attemptParsing) { - deserialized = tree.traverse(jp.getCodec()).readValueAs({{{.}}}.class); + deserialized = tree.traverse(jp.getCodec()).readValueAs({{{dataType}}}.class); // TODO: there is no validation against JSON schema constraints // (min, max, enum, pattern...), this does not perform a strict JSON // validation, which means the 'match' count may be higher than it should be. match++; - log.log(Level.FINER, "Input data matches schema '{{{.}}}'"); + log.log(Level.FINER, "Input data matches schema '{{{dataType}}}'"); } + {{/isArray}} + {{#isArray}} + if (token == JsonToken.START_ARRAY) { + final TypeReference<{{{dataType}}}> ref = new TypeReference<{{{dataType}}}>(){}; + deserialized = tree.traverse(jp.getCodec()).readValueAs(ref); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema '{{{dataType}}}'"); + } + {{/isArray}} } catch (Exception e) { // deserialization failed, continue - log.log(Level.FINER, "Input data does not match schema '{{{.}}}'", e); + log.log(Level.FINER, "Input data does not match schema '{{{dataType}}}'", e); } {{/oneOf}} + {{/composedSchemas}} if (match == 1) { {{classname}} ret = new {{classname}}(); ret.setActualInstance(deserialized); @@ -152,13 +189,17 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im return Objects.hash(getActualInstance(), isNullable(), getSchemaType(), additionalProperties); } {{/additionalPropertiesType}} + {{#composedSchemas}} {{#oneOf}} - public {{classname}}({{{.}}} o) { + {{^vendorExtensions.x-duplicated-data-type}} + public {{classname}}({{{baseType}}} o) { super("oneOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}}); setActualInstance(o); } + {{/vendorExtensions.x-duplicated-data-type}} {{/oneOf}} + {{/composedSchemas}} static { {{#oneOf}} schemas.put("{{{.}}}", new GenericType<{{{.}}}>() { @@ -198,13 +239,17 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im } {{/isNullable}} + {{#composedSchemas}} {{#oneOf}} - if (JSON.isInstanceOf({{{.}}}.class, instance, new HashSet<>())) { + {{^vendorExtensions.x-duplicated-data-type}} + if (JSON.isInstanceOf({{{baseType}}}.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; } + {{/vendorExtensions.x-duplicated-data-type}} {{/oneOf}} + {{/composedSchemas}} throw new RuntimeException("Invalid instance type. Must be {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}"); } @@ -219,17 +264,26 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im return super.getActualInstance(); } + {{#composedSchemas}} {{#oneOf}} /** - * Get the actual instance of `{{{.}}}`. If the actual instance is not `{{{.}}}`, + * Get the actual instance of `{{{dataType}}}`. If the actual instance is not `{{{dataType}}}`, * the ClassCastException will be thrown. * - * @return The actual instance of `{{{.}}}` - * @throws ClassCastException if the instance is not `{{{.}}}` + * @return The actual instance of `{{{dataType}}}` + * @throws ClassCastException if the instance is not `{{{dataType}}}` */ - public {{{.}}} get{{{.}}}() throws ClassCastException { - return ({{{.}}})super.getActualInstance(); + {{^isArray}} + public {{{dataType}}} get{{{dataType}}}() throws ClassCastException { + return ({{{dataType}}})super.getActualInstance(); } + {{/isArray}} + {{#isArray}} + public {{{dataType}}} get{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}() throws ClassCastException { + return ({{{dataType}}})super.getActualInstance(); + } + {{/isArray}} {{/oneOf}} + {{/composedSchemas}} } diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/pojo.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/pojo.mustache index 2898ccaeac7a..b17b14067d58 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/pojo.mustache @@ -113,7 +113,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens ) { this(); {{#readOnlyVars}} - this.{{name}} = {{name}}; + 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}} }{{/jackson}}{{/withXml}}{{/vendorExtensions.x-has-readonly-properties}} {{#vars}} diff --git a/samples/client/others/java/jersey2-oneOf-Mixed/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/others/java/jersey2-oneOf-Mixed/src/main/java/org/openapitools/client/ApiClient.java index 7d7850a83574..2138fc9bfaa6 100644 --- a/samples/client/others/java/jersey2-oneOf-Mixed/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/others/java/jersey2-oneOf-Mixed/src/main/java/org/openapitools/client/ApiClient.java @@ -758,7 +758,7 @@ public class ApiClient extends JavaTimeFormatter { File file = (File) param.getValue(); FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()) .fileName(file.getName()).size(file.length()).build(); - + // Attempt to probe the content type for the file so that the form part is more correctly // and precisely identified, but fall back to application/octet-stream if that fails. MediaType type; @@ -767,7 +767,7 @@ public class ApiClient extends JavaTimeFormatter { } catch (IOException | IllegalArgumentException e) { type = MediaType.APPLICATION_OCTET_STREAM_TYPE; } - + multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type)); } else { FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build(); diff --git a/samples/client/others/java/jersey2-oneOf-duplicates/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/others/java/jersey2-oneOf-duplicates/src/main/java/org/openapitools/client/ApiClient.java index 7d7850a83574..2138fc9bfaa6 100644 --- a/samples/client/others/java/jersey2-oneOf-duplicates/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/others/java/jersey2-oneOf-duplicates/src/main/java/org/openapitools/client/ApiClient.java @@ -758,7 +758,7 @@ public class ApiClient extends JavaTimeFormatter { File file = (File) param.getValue(); FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()) .fileName(file.getName()).size(file.length()).build(); - + // Attempt to probe the content type for the file so that the form part is more correctly // and precisely identified, but fall back to application/octet-stream if that fails. MediaType type; @@ -767,7 +767,7 @@ public class ApiClient extends JavaTimeFormatter { } catch (IOException | IllegalArgumentException e) { type = MediaType.APPLICATION_OCTET_STREAM_TYPE; } - + multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type)); } else { FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build(); diff --git a/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/ApiClient.java index 4a46ecac17a0..dfe7f28890f6 100644 --- a/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/ApiClient.java @@ -899,7 +899,7 @@ public class ApiClient extends JavaTimeFormatter { File file = (File) param.getValue(); FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()) .fileName(file.getName()).size(file.length()).build(); - + // Attempt to probe the content type for the file so that the form part is more correctly // and precisely identified, but fall back to application/octet-stream if that fails. MediaType type; @@ -908,7 +908,7 @@ public class ApiClient extends JavaTimeFormatter { } catch (IOException | IllegalArgumentException e) { type = MediaType.APPLICATION_OCTET_STREAM_TYPE; } - + multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type)); } else { FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build(); diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java index 4a46ecac17a0..dfe7f28890f6 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java @@ -899,7 +899,7 @@ public class ApiClient extends JavaTimeFormatter { File file = (File) param.getValue(); FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()) .fileName(file.getName()).size(file.length()).build(); - + // Attempt to probe the content type for the file so that the form part is more correctly // and precisely identified, but fall back to application/octet-stream if that fails. MediaType type; @@ -908,7 +908,7 @@ public class ApiClient extends JavaTimeFormatter { } catch (IOException | IllegalArgumentException e) { type = MediaType.APPLICATION_OCTET_STREAM_TYPE; } - + multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type)); } else { FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build(); diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/ApiClient.java index 47b5e77061e3..8ddd893b516a 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/ApiClient.java @@ -132,7 +132,7 @@ public class ApiClient extends JavaTimeFormatter { protected Map> operationServers; { - Map> operationServers = new LinkedHashMap<>(); + Map> operationServers = new HashMap<>(); operationServers.put("PetApi.addPet", new ArrayList<>(Arrays.asList( new ServerConfiguration( "http://petstore.swagger.io/v2", @@ -983,14 +983,14 @@ public class ApiClient extends JavaTimeFormatter { .fileName(file.getName()).size(file.length()).build(); // Attempt to probe the content type for the file so that the form part is more correctly - // and precisely identified, but fall back to application/octet-stream if that fails. + // and precisely identified, but fall back to application/octet-stream if that fails. MediaType type; try { type = MediaType.valueOf(Files.probeContentType(file.toPath())); } catch (IOException | IllegalArgumentException e) { type = MediaType.APPLICATION_OCTET_STREAM_TYPE; } - + multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type)); } else { FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build(); diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Fruit.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Fruit.java index 8937db638d20..050783451fab 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Fruit.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Fruit.java @@ -94,19 +94,9 @@ public class Fruit extends AbstractOpenApiSchema { boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); int match = 0; JsonToken token = tree.traverse(jp.getCodec()).nextToken(); - // deserialize Apple + // deserialize Apple (nullable) try { boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (Apple.class.equals(Integer.class) || Apple.class.equals(Long.class) || Apple.class.equals(Float.class) || Apple.class.equals(Double.class) || Apple.class.equals(Boolean.class) || Apple.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((Apple.class.equals(Integer.class) || Apple.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((Apple.class.equals(Float.class) || Apple.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (Apple.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (Apple.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } if (attemptParsing) { deserialized = tree.traverse(jp.getCodec()).readValueAs(Apple.class); // TODO: there is no validation against JSON schema constraints @@ -123,16 +113,6 @@ public class Fruit extends AbstractOpenApiSchema { // deserialize Banana try { boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (Banana.class.equals(Integer.class) || Banana.class.equals(Long.class) || Banana.class.equals(Float.class) || Banana.class.equals(Double.class) || Banana.class.equals(Boolean.class) || Banana.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((Banana.class.equals(Integer.class) || Banana.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((Banana.class.equals(Float.class) || Banana.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (Banana.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (Banana.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } if (attemptParsing) { deserialized = tree.traverse(jp.getCodec()).readValueAs(Banana.class); // TODO: there is no validation against JSON schema constraints @@ -171,7 +151,7 @@ public class Fruit extends AbstractOpenApiSchema { } public Fruit(Apple o) { - super("oneOf", Boolean.FALSE); + super("oneOf", Boolean.TRUE); setActualInstance(o); } diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/FruitReq.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/FruitReq.java index 85e54140a0a4..ec2b11296766 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/FruitReq.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/FruitReq.java @@ -97,17 +97,6 @@ public class FruitReq extends AbstractOpenApiSchema { // deserialize AppleReq try { boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (AppleReq.class.equals(Integer.class) || AppleReq.class.equals(Long.class) || AppleReq.class.equals(Float.class) || AppleReq.class.equals(Double.class) || AppleReq.class.equals(Boolean.class) || AppleReq.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((AppleReq.class.equals(Integer.class) || AppleReq.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((AppleReq.class.equals(Float.class) || AppleReq.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (AppleReq.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (AppleReq.class.equals(String.class) && token == JsonToken.VALUE_STRING); - attemptParsing |= (token == JsonToken.VALUE_NULL); - } - } if (attemptParsing) { deserialized = tree.traverse(jp.getCodec()).readValueAs(AppleReq.class); // TODO: there is no validation against JSON schema constraints @@ -124,17 +113,6 @@ public class FruitReq extends AbstractOpenApiSchema { // deserialize BananaReq try { boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (BananaReq.class.equals(Integer.class) || BananaReq.class.equals(Long.class) || BananaReq.class.equals(Float.class) || BananaReq.class.equals(Double.class) || BananaReq.class.equals(Boolean.class) || BananaReq.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((BananaReq.class.equals(Integer.class) || BananaReq.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((BananaReq.class.equals(Float.class) || BananaReq.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (BananaReq.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (BananaReq.class.equals(String.class) && token == JsonToken.VALUE_STRING); - attemptParsing |= (token == JsonToken.VALUE_NULL); - } - } if (attemptParsing) { deserialized = tree.traverse(jp.getCodec()).readValueAs(BananaReq.class); // TODO: there is no validation against JSON schema constraints @@ -173,12 +151,12 @@ public class FruitReq extends AbstractOpenApiSchema { } public FruitReq(AppleReq o) { - super("oneOf", Boolean.TRUE); + super("oneOf", Boolean.FALSE); setActualInstance(o); } public FruitReq(BananaReq o) { - super("oneOf", Boolean.TRUE); + super("oneOf", Boolean.FALSE); setActualInstance(o); } diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Mammal.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Mammal.java index da756ecedd0e..540d3d5f95d7 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Mammal.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Mammal.java @@ -99,7 +99,7 @@ public class Mammal extends AbstractOpenApiSchema { JsonNode tree = jp.readValueAsTree(); Object deserialized = null; Mammal newMammal = new Mammal(); - Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); + Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); String discriminatorValue = (String)result2.get("className"); switch (discriminatorValue) { case "Pig": @@ -121,45 +121,9 @@ public class Mammal extends AbstractOpenApiSchema { boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); int match = 0; JsonToken token = tree.traverse(jp.getCodec()).nextToken(); - // deserialize Pig - try { - boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (Pig.class.equals(Integer.class) || Pig.class.equals(Long.class) || Pig.class.equals(Float.class) || Pig.class.equals(Double.class) || Pig.class.equals(Boolean.class) || Pig.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((Pig.class.equals(Integer.class) || Pig.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((Pig.class.equals(Float.class) || Pig.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (Pig.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (Pig.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } - if (attemptParsing) { - deserialized = tree.traverse(jp.getCodec()).readValueAs(Pig.class); - // TODO: there is no validation against JSON schema constraints - // (min, max, enum, pattern...), this does not perform a strict JSON - // validation, which means the 'match' count may be higher than it should be. - match++; - log.log(Level.FINER, "Input data matches schema 'Pig'"); - } - } catch (Exception e) { - // deserialization failed, continue - log.log(Level.FINER, "Input data does not match schema 'Pig'", e); - } - // deserialize Whale try { boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (Whale.class.equals(Integer.class) || Whale.class.equals(Long.class) || Whale.class.equals(Float.class) || Whale.class.equals(Double.class) || Whale.class.equals(Boolean.class) || Whale.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((Whale.class.equals(Integer.class) || Whale.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((Whale.class.equals(Float.class) || Whale.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (Whale.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (Whale.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } if (attemptParsing) { deserialized = tree.traverse(jp.getCodec()).readValueAs(Whale.class); // TODO: there is no validation against JSON schema constraints @@ -176,16 +140,6 @@ public class Mammal extends AbstractOpenApiSchema { // deserialize Zebra try { boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (Zebra.class.equals(Integer.class) || Zebra.class.equals(Long.class) || Zebra.class.equals(Float.class) || Zebra.class.equals(Double.class) || Zebra.class.equals(Boolean.class) || Zebra.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((Zebra.class.equals(Integer.class) || Zebra.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((Zebra.class.equals(Float.class) || Zebra.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (Zebra.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (Zebra.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } if (attemptParsing) { deserialized = tree.traverse(jp.getCodec()).readValueAs(Zebra.class); // TODO: there is no validation against JSON schema constraints @@ -199,6 +153,22 @@ public class Mammal extends AbstractOpenApiSchema { log.log(Level.FINER, "Input data does not match schema 'Zebra'", e); } + // deserialize Pig + try { + boolean attemptParsing = true; + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(Pig.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'Pig'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'Pig'", e); + } + if (match == 1) { Mammal ret = new Mammal(); ret.setActualInstance(deserialized); @@ -272,11 +242,6 @@ public class Mammal extends AbstractOpenApiSchema { public int hashCode() { return Objects.hash(getActualInstance(), isNullable(), getSchemaType(), additionalProperties); } - public Mammal(Pig o) { - super("oneOf", Boolean.FALSE); - setActualInstance(o); - } - public Mammal(Whale o) { super("oneOf", Boolean.FALSE); setActualInstance(o); @@ -287,6 +252,11 @@ public class Mammal extends AbstractOpenApiSchema { setActualInstance(o); } + public Mammal(Pig o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + static { schemas.put("Pig", new GenericType() { }); @@ -319,11 +289,6 @@ public class Mammal extends AbstractOpenApiSchema { */ @Override public void setActualInstance(Object instance) { - if (JSON.isInstanceOf(Pig.class, instance, new HashSet<>())) { - super.setActualInstance(instance); - return; - } - if (JSON.isInstanceOf(Whale.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; @@ -334,6 +299,11 @@ public class Mammal extends AbstractOpenApiSchema { return; } + if (JSON.isInstanceOf(Pig.class, instance, new HashSet<>())) { + super.setActualInstance(instance); + return; + } + throw new RuntimeException("Invalid instance type. Must be Pig, Whale, Zebra"); } @@ -348,17 +318,6 @@ public class Mammal extends AbstractOpenApiSchema { return super.getActualInstance(); } - /** - * Get the actual instance of `Pig`. If the actual instance is not `Pig`, - * the ClassCastException will be thrown. - * - * @return The actual instance of `Pig` - * @throws ClassCastException if the instance is not `Pig` - */ - public Pig getPig() throws ClassCastException { - return (Pig)super.getActualInstance(); - } - /** * Get the actual instance of `Whale`. If the actual instance is not `Whale`, * the ClassCastException will be thrown. @@ -381,5 +340,16 @@ public class Mammal extends AbstractOpenApiSchema { return (Zebra)super.getActualInstance(); } + /** + * Get the actual instance of `Pig`. If the actual instance is not `Pig`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Pig` + * @throws ClassCastException if the instance is not `Pig` + */ + public Pig getPig() throws ClassCastException { + return (Pig)super.getActualInstance(); + } + } diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/NullableShape.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/NullableShape.java index d08f6d8bc59e..7fe97aff0b52 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/NullableShape.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/NullableShape.java @@ -98,7 +98,7 @@ public class NullableShape extends AbstractOpenApiSchema { JsonNode tree = jp.readValueAsTree(); Object deserialized = null; NullableShape newNullableShape = new NullableShape(); - Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); + Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); String discriminatorValue = (String)result2.get("shapeType"); switch (discriminatorValue) { case "Quadrilateral": @@ -116,47 +116,9 @@ public class NullableShape extends AbstractOpenApiSchema { boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); int match = 0; JsonToken token = tree.traverse(jp.getCodec()).nextToken(); - // deserialize Quadrilateral - try { - boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (Quadrilateral.class.equals(Integer.class) || Quadrilateral.class.equals(Long.class) || Quadrilateral.class.equals(Float.class) || Quadrilateral.class.equals(Double.class) || Quadrilateral.class.equals(Boolean.class) || Quadrilateral.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((Quadrilateral.class.equals(Integer.class) || Quadrilateral.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((Quadrilateral.class.equals(Float.class) || Quadrilateral.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (Quadrilateral.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (Quadrilateral.class.equals(String.class) && token == JsonToken.VALUE_STRING); - attemptParsing |= (token == JsonToken.VALUE_NULL); - } - } - if (attemptParsing) { - deserialized = tree.traverse(jp.getCodec()).readValueAs(Quadrilateral.class); - // TODO: there is no validation against JSON schema constraints - // (min, max, enum, pattern...), this does not perform a strict JSON - // validation, which means the 'match' count may be higher than it should be. - match++; - log.log(Level.FINER, "Input data matches schema 'Quadrilateral'"); - } - } catch (Exception e) { - // deserialization failed, continue - log.log(Level.FINER, "Input data does not match schema 'Quadrilateral'", e); - } - // deserialize Triangle try { boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (Triangle.class.equals(Integer.class) || Triangle.class.equals(Long.class) || Triangle.class.equals(Float.class) || Triangle.class.equals(Double.class) || Triangle.class.equals(Boolean.class) || Triangle.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((Triangle.class.equals(Integer.class) || Triangle.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((Triangle.class.equals(Float.class) || Triangle.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (Triangle.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (Triangle.class.equals(String.class) && token == JsonToken.VALUE_STRING); - attemptParsing |= (token == JsonToken.VALUE_NULL); - } - } if (attemptParsing) { deserialized = tree.traverse(jp.getCodec()).readValueAs(Triangle.class); // TODO: there is no validation against JSON schema constraints @@ -170,6 +132,22 @@ public class NullableShape extends AbstractOpenApiSchema { log.log(Level.FINER, "Input data does not match schema 'Triangle'", e); } + // deserialize Quadrilateral + try { + boolean attemptParsing = true; + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(Quadrilateral.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'Quadrilateral'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'Quadrilateral'", e); + } + if (match == 1) { NullableShape ret = new NullableShape(); ret.setActualInstance(deserialized); @@ -243,13 +221,13 @@ public class NullableShape extends AbstractOpenApiSchema { public int hashCode() { return Objects.hash(getActualInstance(), isNullable(), getSchemaType(), additionalProperties); } - public NullableShape(Quadrilateral o) { - super("oneOf", Boolean.TRUE); + public NullableShape(Triangle o) { + super("oneOf", Boolean.FALSE); setActualInstance(o); } - public NullableShape(Triangle o) { - super("oneOf", Boolean.TRUE); + public NullableShape(Quadrilateral o) { + super("oneOf", Boolean.FALSE); setActualInstance(o); } @@ -287,12 +265,12 @@ public class NullableShape extends AbstractOpenApiSchema { return; } - if (JSON.isInstanceOf(Quadrilateral.class, instance, new HashSet<>())) { + if (JSON.isInstanceOf(Triangle.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; } - if (JSON.isInstanceOf(Triangle.class, instance, new HashSet<>())) { + if (JSON.isInstanceOf(Quadrilateral.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; } @@ -311,17 +289,6 @@ public class NullableShape extends AbstractOpenApiSchema { return super.getActualInstance(); } - /** - * Get the actual instance of `Quadrilateral`. If the actual instance is not `Quadrilateral`, - * the ClassCastException will be thrown. - * - * @return The actual instance of `Quadrilateral` - * @throws ClassCastException if the instance is not `Quadrilateral` - */ - public Quadrilateral getQuadrilateral() throws ClassCastException { - return (Quadrilateral)super.getActualInstance(); - } - /** * Get the actual instance of `Triangle`. If the actual instance is not `Triangle`, * the ClassCastException will be thrown. @@ -333,5 +300,16 @@ public class NullableShape extends AbstractOpenApiSchema { return (Triangle)super.getActualInstance(); } + /** + * Get the actual instance of `Quadrilateral`. If the actual instance is not `Quadrilateral`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Quadrilateral` + * @throws ClassCastException if the instance is not `Quadrilateral` + */ + public Quadrilateral getQuadrilateral() throws ClassCastException { + return (Quadrilateral)super.getActualInstance(); + } + } diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Pig.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Pig.java index 6914f25644ca..ca13cee2b01c 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Pig.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Pig.java @@ -98,7 +98,7 @@ public class Pig extends AbstractOpenApiSchema { JsonNode tree = jp.readValueAsTree(); Object deserialized = null; Pig newPig = new Pig(); - Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); + Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); String discriminatorValue = (String)result2.get("className"); switch (discriminatorValue) { case "BasquePig": @@ -119,16 +119,6 @@ public class Pig extends AbstractOpenApiSchema { // deserialize BasquePig try { boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (BasquePig.class.equals(Integer.class) || BasquePig.class.equals(Long.class) || BasquePig.class.equals(Float.class) || BasquePig.class.equals(Double.class) || BasquePig.class.equals(Boolean.class) || BasquePig.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((BasquePig.class.equals(Integer.class) || BasquePig.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((BasquePig.class.equals(Float.class) || BasquePig.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (BasquePig.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (BasquePig.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } if (attemptParsing) { deserialized = tree.traverse(jp.getCodec()).readValueAs(BasquePig.class); // TODO: there is no validation against JSON schema constraints @@ -145,16 +135,6 @@ public class Pig extends AbstractOpenApiSchema { // deserialize DanishPig try { boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (DanishPig.class.equals(Integer.class) || DanishPig.class.equals(Long.class) || DanishPig.class.equals(Float.class) || DanishPig.class.equals(Double.class) || DanishPig.class.equals(Boolean.class) || DanishPig.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((DanishPig.class.equals(Integer.class) || DanishPig.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((DanishPig.class.equals(Float.class) || DanishPig.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (DanishPig.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (DanishPig.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } if (attemptParsing) { deserialized = tree.traverse(jp.getCodec()).readValueAs(DanishPig.class); // TODO: there is no validation against JSON schema constraints diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Quadrilateral.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Quadrilateral.java index de75e54bbe6b..18886bf7d272 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Quadrilateral.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Quadrilateral.java @@ -98,7 +98,7 @@ public class Quadrilateral extends AbstractOpenApiSchema { JsonNode tree = jp.readValueAsTree(); Object deserialized = null; Quadrilateral newQuadrilateral = new Quadrilateral(); - Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); + Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); String discriminatorValue = (String)result2.get("quadrilateralType"); switch (discriminatorValue) { case "ComplexQuadrilateral": @@ -116,45 +116,9 @@ public class Quadrilateral extends AbstractOpenApiSchema { boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); int match = 0; JsonToken token = tree.traverse(jp.getCodec()).nextToken(); - // deserialize ComplexQuadrilateral - try { - boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (ComplexQuadrilateral.class.equals(Integer.class) || ComplexQuadrilateral.class.equals(Long.class) || ComplexQuadrilateral.class.equals(Float.class) || ComplexQuadrilateral.class.equals(Double.class) || ComplexQuadrilateral.class.equals(Boolean.class) || ComplexQuadrilateral.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((ComplexQuadrilateral.class.equals(Integer.class) || ComplexQuadrilateral.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((ComplexQuadrilateral.class.equals(Float.class) || ComplexQuadrilateral.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (ComplexQuadrilateral.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (ComplexQuadrilateral.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } - if (attemptParsing) { - deserialized = tree.traverse(jp.getCodec()).readValueAs(ComplexQuadrilateral.class); - // TODO: there is no validation against JSON schema constraints - // (min, max, enum, pattern...), this does not perform a strict JSON - // validation, which means the 'match' count may be higher than it should be. - match++; - log.log(Level.FINER, "Input data matches schema 'ComplexQuadrilateral'"); - } - } catch (Exception e) { - // deserialization failed, continue - log.log(Level.FINER, "Input data does not match schema 'ComplexQuadrilateral'", e); - } - // deserialize SimpleQuadrilateral try { boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (SimpleQuadrilateral.class.equals(Integer.class) || SimpleQuadrilateral.class.equals(Long.class) || SimpleQuadrilateral.class.equals(Float.class) || SimpleQuadrilateral.class.equals(Double.class) || SimpleQuadrilateral.class.equals(Boolean.class) || SimpleQuadrilateral.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((SimpleQuadrilateral.class.equals(Integer.class) || SimpleQuadrilateral.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((SimpleQuadrilateral.class.equals(Float.class) || SimpleQuadrilateral.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (SimpleQuadrilateral.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (SimpleQuadrilateral.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } if (attemptParsing) { deserialized = tree.traverse(jp.getCodec()).readValueAs(SimpleQuadrilateral.class); // TODO: there is no validation against JSON schema constraints @@ -168,6 +132,22 @@ public class Quadrilateral extends AbstractOpenApiSchema { log.log(Level.FINER, "Input data does not match schema 'SimpleQuadrilateral'", e); } + // deserialize ComplexQuadrilateral + try { + boolean attemptParsing = true; + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(ComplexQuadrilateral.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'ComplexQuadrilateral'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'ComplexQuadrilateral'", e); + } + if (match == 1) { Quadrilateral ret = new Quadrilateral(); ret.setActualInstance(deserialized); @@ -241,12 +221,12 @@ public class Quadrilateral extends AbstractOpenApiSchema { public int hashCode() { return Objects.hash(getActualInstance(), isNullable(), getSchemaType(), additionalProperties); } - public Quadrilateral(ComplexQuadrilateral o) { + public Quadrilateral(SimpleQuadrilateral o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } - public Quadrilateral(SimpleQuadrilateral o) { + public Quadrilateral(ComplexQuadrilateral o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } @@ -280,12 +260,12 @@ public class Quadrilateral extends AbstractOpenApiSchema { */ @Override public void setActualInstance(Object instance) { - if (JSON.isInstanceOf(ComplexQuadrilateral.class, instance, new HashSet<>())) { + if (JSON.isInstanceOf(SimpleQuadrilateral.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; } - if (JSON.isInstanceOf(SimpleQuadrilateral.class, instance, new HashSet<>())) { + if (JSON.isInstanceOf(ComplexQuadrilateral.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; } @@ -304,17 +284,6 @@ public class Quadrilateral extends AbstractOpenApiSchema { return super.getActualInstance(); } - /** - * Get the actual instance of `ComplexQuadrilateral`. If the actual instance is not `ComplexQuadrilateral`, - * the ClassCastException will be thrown. - * - * @return The actual instance of `ComplexQuadrilateral` - * @throws ClassCastException if the instance is not `ComplexQuadrilateral` - */ - public ComplexQuadrilateral getComplexQuadrilateral() throws ClassCastException { - return (ComplexQuadrilateral)super.getActualInstance(); - } - /** * Get the actual instance of `SimpleQuadrilateral`. If the actual instance is not `SimpleQuadrilateral`, * the ClassCastException will be thrown. @@ -326,5 +295,16 @@ public class Quadrilateral extends AbstractOpenApiSchema { return (SimpleQuadrilateral)super.getActualInstance(); } + /** + * Get the actual instance of `ComplexQuadrilateral`. If the actual instance is not `ComplexQuadrilateral`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `ComplexQuadrilateral` + * @throws ClassCastException if the instance is not `ComplexQuadrilateral` + */ + public ComplexQuadrilateral getComplexQuadrilateral() throws ClassCastException { + return (ComplexQuadrilateral)super.getActualInstance(); + } + } diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Shape.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Shape.java index 04b57a98c958..943571323655 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Shape.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Shape.java @@ -98,7 +98,7 @@ public class Shape extends AbstractOpenApiSchema { JsonNode tree = jp.readValueAsTree(); Object deserialized = null; Shape newShape = new Shape(); - Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); + Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); String discriminatorValue = (String)result2.get("shapeType"); switch (discriminatorValue) { case "Quadrilateral": @@ -116,45 +116,9 @@ public class Shape extends AbstractOpenApiSchema { boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); int match = 0; JsonToken token = tree.traverse(jp.getCodec()).nextToken(); - // deserialize Quadrilateral - try { - boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (Quadrilateral.class.equals(Integer.class) || Quadrilateral.class.equals(Long.class) || Quadrilateral.class.equals(Float.class) || Quadrilateral.class.equals(Double.class) || Quadrilateral.class.equals(Boolean.class) || Quadrilateral.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((Quadrilateral.class.equals(Integer.class) || Quadrilateral.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((Quadrilateral.class.equals(Float.class) || Quadrilateral.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (Quadrilateral.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (Quadrilateral.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } - if (attemptParsing) { - deserialized = tree.traverse(jp.getCodec()).readValueAs(Quadrilateral.class); - // TODO: there is no validation against JSON schema constraints - // (min, max, enum, pattern...), this does not perform a strict JSON - // validation, which means the 'match' count may be higher than it should be. - match++; - log.log(Level.FINER, "Input data matches schema 'Quadrilateral'"); - } - } catch (Exception e) { - // deserialization failed, continue - log.log(Level.FINER, "Input data does not match schema 'Quadrilateral'", e); - } - // deserialize Triangle try { boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (Triangle.class.equals(Integer.class) || Triangle.class.equals(Long.class) || Triangle.class.equals(Float.class) || Triangle.class.equals(Double.class) || Triangle.class.equals(Boolean.class) || Triangle.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((Triangle.class.equals(Integer.class) || Triangle.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((Triangle.class.equals(Float.class) || Triangle.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (Triangle.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (Triangle.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } if (attemptParsing) { deserialized = tree.traverse(jp.getCodec()).readValueAs(Triangle.class); // TODO: there is no validation against JSON schema constraints @@ -168,6 +132,22 @@ public class Shape extends AbstractOpenApiSchema { log.log(Level.FINER, "Input data does not match schema 'Triangle'", e); } + // deserialize Quadrilateral + try { + boolean attemptParsing = true; + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(Quadrilateral.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'Quadrilateral'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'Quadrilateral'", e); + } + if (match == 1) { Shape ret = new Shape(); ret.setActualInstance(deserialized); @@ -241,12 +221,12 @@ public class Shape extends AbstractOpenApiSchema { public int hashCode() { return Objects.hash(getActualInstance(), isNullable(), getSchemaType(), additionalProperties); } - public Shape(Quadrilateral o) { + public Shape(Triangle o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } - public Shape(Triangle o) { + public Shape(Quadrilateral o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } @@ -280,12 +260,12 @@ public class Shape extends AbstractOpenApiSchema { */ @Override public void setActualInstance(Object instance) { - if (JSON.isInstanceOf(Quadrilateral.class, instance, new HashSet<>())) { + if (JSON.isInstanceOf(Triangle.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; } - if (JSON.isInstanceOf(Triangle.class, instance, new HashSet<>())) { + if (JSON.isInstanceOf(Quadrilateral.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; } @@ -304,17 +284,6 @@ public class Shape extends AbstractOpenApiSchema { return super.getActualInstance(); } - /** - * Get the actual instance of `Quadrilateral`. If the actual instance is not `Quadrilateral`, - * the ClassCastException will be thrown. - * - * @return The actual instance of `Quadrilateral` - * @throws ClassCastException if the instance is not `Quadrilateral` - */ - public Quadrilateral getQuadrilateral() throws ClassCastException { - return (Quadrilateral)super.getActualInstance(); - } - /** * Get the actual instance of `Triangle`. If the actual instance is not `Triangle`, * the ClassCastException will be thrown. @@ -326,5 +295,16 @@ public class Shape extends AbstractOpenApiSchema { return (Triangle)super.getActualInstance(); } + /** + * Get the actual instance of `Quadrilateral`. If the actual instance is not `Quadrilateral`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Quadrilateral` + * @throws ClassCastException if the instance is not `Quadrilateral` + */ + public Quadrilateral getQuadrilateral() throws ClassCastException { + return (Quadrilateral)super.getActualInstance(); + } + } diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/ShapeOrNull.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/ShapeOrNull.java index 3e77e29ae037..c604ba4e1ac7 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/ShapeOrNull.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/ShapeOrNull.java @@ -98,7 +98,7 @@ public class ShapeOrNull extends AbstractOpenApiSchema { JsonNode tree = jp.readValueAsTree(); Object deserialized = null; ShapeOrNull newShapeOrNull = new ShapeOrNull(); - Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); + Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); String discriminatorValue = (String)result2.get("shapeType"); switch (discriminatorValue) { case "Quadrilateral": @@ -116,47 +116,9 @@ public class ShapeOrNull extends AbstractOpenApiSchema { boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); int match = 0; JsonToken token = tree.traverse(jp.getCodec()).nextToken(); - // deserialize Quadrilateral - try { - boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (Quadrilateral.class.equals(Integer.class) || Quadrilateral.class.equals(Long.class) || Quadrilateral.class.equals(Float.class) || Quadrilateral.class.equals(Double.class) || Quadrilateral.class.equals(Boolean.class) || Quadrilateral.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((Quadrilateral.class.equals(Integer.class) || Quadrilateral.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((Quadrilateral.class.equals(Float.class) || Quadrilateral.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (Quadrilateral.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (Quadrilateral.class.equals(String.class) && token == JsonToken.VALUE_STRING); - attemptParsing |= (token == JsonToken.VALUE_NULL); - } - } - if (attemptParsing) { - deserialized = tree.traverse(jp.getCodec()).readValueAs(Quadrilateral.class); - // TODO: there is no validation against JSON schema constraints - // (min, max, enum, pattern...), this does not perform a strict JSON - // validation, which means the 'match' count may be higher than it should be. - match++; - log.log(Level.FINER, "Input data matches schema 'Quadrilateral'"); - } - } catch (Exception e) { - // deserialization failed, continue - log.log(Level.FINER, "Input data does not match schema 'Quadrilateral'", e); - } - // deserialize Triangle try { boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (Triangle.class.equals(Integer.class) || Triangle.class.equals(Long.class) || Triangle.class.equals(Float.class) || Triangle.class.equals(Double.class) || Triangle.class.equals(Boolean.class) || Triangle.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((Triangle.class.equals(Integer.class) || Triangle.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((Triangle.class.equals(Float.class) || Triangle.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (Triangle.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (Triangle.class.equals(String.class) && token == JsonToken.VALUE_STRING); - attemptParsing |= (token == JsonToken.VALUE_NULL); - } - } if (attemptParsing) { deserialized = tree.traverse(jp.getCodec()).readValueAs(Triangle.class); // TODO: there is no validation against JSON schema constraints @@ -170,6 +132,22 @@ public class ShapeOrNull extends AbstractOpenApiSchema { log.log(Level.FINER, "Input data does not match schema 'Triangle'", e); } + // deserialize Quadrilateral + try { + boolean attemptParsing = true; + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(Quadrilateral.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'Quadrilateral'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'Quadrilateral'", e); + } + if (match == 1) { ShapeOrNull ret = new ShapeOrNull(); ret.setActualInstance(deserialized); @@ -243,13 +221,13 @@ public class ShapeOrNull extends AbstractOpenApiSchema { public int hashCode() { return Objects.hash(getActualInstance(), isNullable(), getSchemaType(), additionalProperties); } - public ShapeOrNull(Quadrilateral o) { - super("oneOf", Boolean.TRUE); + public ShapeOrNull(Triangle o) { + super("oneOf", Boolean.FALSE); setActualInstance(o); } - public ShapeOrNull(Triangle o) { - super("oneOf", Boolean.TRUE); + public ShapeOrNull(Quadrilateral o) { + super("oneOf", Boolean.FALSE); setActualInstance(o); } @@ -287,12 +265,12 @@ public class ShapeOrNull extends AbstractOpenApiSchema { return; } - if (JSON.isInstanceOf(Quadrilateral.class, instance, new HashSet<>())) { + if (JSON.isInstanceOf(Triangle.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; } - if (JSON.isInstanceOf(Triangle.class, instance, new HashSet<>())) { + if (JSON.isInstanceOf(Quadrilateral.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; } @@ -311,17 +289,6 @@ public class ShapeOrNull extends AbstractOpenApiSchema { return super.getActualInstance(); } - /** - * Get the actual instance of `Quadrilateral`. If the actual instance is not `Quadrilateral`, - * the ClassCastException will be thrown. - * - * @return The actual instance of `Quadrilateral` - * @throws ClassCastException if the instance is not `Quadrilateral` - */ - public Quadrilateral getQuadrilateral() throws ClassCastException { - return (Quadrilateral)super.getActualInstance(); - } - /** * Get the actual instance of `Triangle`. If the actual instance is not `Triangle`, * the ClassCastException will be thrown. @@ -333,5 +300,16 @@ public class ShapeOrNull extends AbstractOpenApiSchema { return (Triangle)super.getActualInstance(); } + /** + * Get the actual instance of `Quadrilateral`. If the actual instance is not `Quadrilateral`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Quadrilateral` + * @throws ClassCastException if the instance is not `Quadrilateral` + */ + public Quadrilateral getQuadrilateral() throws ClassCastException { + return (Quadrilateral)super.getActualInstance(); + } + } diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Triangle.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Triangle.java index 770a3f101a58..8f2fb0d9d130 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Triangle.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/Triangle.java @@ -99,7 +99,7 @@ public class Triangle extends AbstractOpenApiSchema { JsonNode tree = jp.readValueAsTree(); Object deserialized = null; Triangle newTriangle = new Triangle(); - Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); + Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); String discriminatorValue = (String)result2.get("triangleType"); switch (discriminatorValue) { case "EquilateralTriangle": @@ -124,16 +124,6 @@ public class Triangle extends AbstractOpenApiSchema { // deserialize EquilateralTriangle try { boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (EquilateralTriangle.class.equals(Integer.class) || EquilateralTriangle.class.equals(Long.class) || EquilateralTriangle.class.equals(Float.class) || EquilateralTriangle.class.equals(Double.class) || EquilateralTriangle.class.equals(Boolean.class) || EquilateralTriangle.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((EquilateralTriangle.class.equals(Integer.class) || EquilateralTriangle.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((EquilateralTriangle.class.equals(Float.class) || EquilateralTriangle.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (EquilateralTriangle.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (EquilateralTriangle.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } if (attemptParsing) { deserialized = tree.traverse(jp.getCodec()).readValueAs(EquilateralTriangle.class); // TODO: there is no validation against JSON schema constraints @@ -150,16 +140,6 @@ public class Triangle extends AbstractOpenApiSchema { // deserialize IsoscelesTriangle try { boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (IsoscelesTriangle.class.equals(Integer.class) || IsoscelesTriangle.class.equals(Long.class) || IsoscelesTriangle.class.equals(Float.class) || IsoscelesTriangle.class.equals(Double.class) || IsoscelesTriangle.class.equals(Boolean.class) || IsoscelesTriangle.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((IsoscelesTriangle.class.equals(Integer.class) || IsoscelesTriangle.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((IsoscelesTriangle.class.equals(Float.class) || IsoscelesTriangle.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (IsoscelesTriangle.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (IsoscelesTriangle.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } if (attemptParsing) { deserialized = tree.traverse(jp.getCodec()).readValueAs(IsoscelesTriangle.class); // TODO: there is no validation against JSON schema constraints @@ -176,16 +156,6 @@ public class Triangle extends AbstractOpenApiSchema { // deserialize ScaleneTriangle try { boolean attemptParsing = true; - // ensure that we respect type coercion as set on the client ObjectMapper - if (ScaleneTriangle.class.equals(Integer.class) || ScaleneTriangle.class.equals(Long.class) || ScaleneTriangle.class.equals(Float.class) || ScaleneTriangle.class.equals(Double.class) || ScaleneTriangle.class.equals(Boolean.class) || ScaleneTriangle.class.equals(String.class)) { - attemptParsing = typeCoercion; - if (!attemptParsing) { - attemptParsing |= ((ScaleneTriangle.class.equals(Integer.class) || ScaleneTriangle.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); - attemptParsing |= ((ScaleneTriangle.class.equals(Float.class) || ScaleneTriangle.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); - attemptParsing |= (ScaleneTriangle.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); - attemptParsing |= (ScaleneTriangle.class.equals(String.class) && token == JsonToken.VALUE_STRING); - } - } if (attemptParsing) { deserialized = tree.traverse(jp.getCodec()).readValueAs(ScaleneTriangle.class); // TODO: there is no validation against JSON schema constraints diff --git a/samples/openapi3/client/extensions/x-auth-id-alias/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java b/samples/openapi3/client/extensions/x-auth-id-alias/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java index 4eee9572af6b..ba75d77993e7 100644 --- a/samples/openapi3/client/extensions/x-auth-id-alias/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/openapi3/client/extensions/x-auth-id-alias/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java @@ -807,7 +807,7 @@ public class ApiClient extends JavaTimeFormatter { File file = (File) param.getValue(); FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()) .fileName(file.getName()).size(file.length()).build(); - + // Attempt to probe the content type for the file so that the form part is more correctly // and precisely identified, but fall back to application/octet-stream if that fails. MediaType type; @@ -816,7 +816,7 @@ public class ApiClient extends JavaTimeFormatter { } catch (IOException | IllegalArgumentException e) { type = MediaType.APPLICATION_OCTET_STREAM_TYPE; } - + multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type)); } else { FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build(); diff --git a/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/main/java/org/openapitools/client/ApiClient.java b/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/main/java/org/openapitools/client/ApiClient.java index 080fcf9c2ca9..65d79525c8a0 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/main/java/org/openapitools/client/ApiClient.java @@ -758,7 +758,7 @@ public class ApiClient extends JavaTimeFormatter { File file = (File) param.getValue(); FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()) .fileName(file.getName()).size(file.length()).build(); - + // Attempt to probe the content type for the file so that the form part is more correctly // and precisely identified, but fall back to application/octet-stream if that fails. MediaType type; @@ -767,7 +767,7 @@ public class ApiClient extends JavaTimeFormatter { } catch (IOException | IllegalArgumentException e) { type = MediaType.APPLICATION_OCTET_STREAM_TYPE; } - + multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type)); } else { FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build(); diff --git a/samples/openapi3/client/petstore/java/jersey2-java8-swagger1/src/main/java/org/openapitools/client/ApiClient.java b/samples/openapi3/client/petstore/java/jersey2-java8-swagger1/src/main/java/org/openapitools/client/ApiClient.java index 43af9909de30..74b9334611f1 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8-swagger1/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8-swagger1/src/main/java/org/openapitools/client/ApiClient.java @@ -883,7 +883,7 @@ public class ApiClient extends JavaTimeFormatter { File file = (File) param.getValue(); FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()) .fileName(file.getName()).size(file.length()).build(); - + // Attempt to probe the content type for the file so that the form part is more correctly // and precisely identified, but fall back to application/octet-stream if that fails. MediaType type; @@ -892,7 +892,7 @@ public class ApiClient extends JavaTimeFormatter { } catch (IOException | IllegalArgumentException e) { type = MediaType.APPLICATION_OCTET_STREAM_TYPE; } - + multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type)); } else { FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build(); diff --git a/samples/openapi3/client/petstore/java/jersey2-java8-swagger1/src/main/java/org/openapitools/client/model/Pet.java b/samples/openapi3/client/petstore/java/jersey2-java8-swagger1/src/main/java/org/openapitools/client/model/Pet.java index 4f660dc5aa83..850463066531 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8-swagger1/src/main/java/org/openapitools/client/model/Pet.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8-swagger1/src/main/java/org/openapitools/client/model/Pet.java @@ -99,6 +99,7 @@ public class Pet { } public static final String JSON_PROPERTY_STATUS = "status"; + @Deprecated private StatusEnum status; public Pet() { @@ -250,6 +251,7 @@ public class Pet { } + @Deprecated public Pet status(StatusEnum status) { this.status = status; return this; @@ -271,6 +273,7 @@ public class Pet { } + @Deprecated @JsonProperty(JSON_PROPERTY_STATUS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) public void setStatus(StatusEnum status) { diff --git a/samples/openapi3/client/petstore/java/jersey2-java8-swagger2/src/main/java/org/openapitools/client/ApiClient.java b/samples/openapi3/client/petstore/java/jersey2-java8-swagger2/src/main/java/org/openapitools/client/ApiClient.java index 43af9909de30..74b9334611f1 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8-swagger2/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8-swagger2/src/main/java/org/openapitools/client/ApiClient.java @@ -883,7 +883,7 @@ public class ApiClient extends JavaTimeFormatter { File file = (File) param.getValue(); FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()) .fileName(file.getName()).size(file.length()).build(); - + // Attempt to probe the content type for the file so that the form part is more correctly // and precisely identified, but fall back to application/octet-stream if that fails. MediaType type; @@ -892,7 +892,7 @@ public class ApiClient extends JavaTimeFormatter { } catch (IOException | IllegalArgumentException e) { type = MediaType.APPLICATION_OCTET_STREAM_TYPE; } - + multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type)); } else { FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build(); diff --git a/samples/openapi3/client/petstore/java/jersey2-java8-swagger2/src/main/java/org/openapitools/client/model/Pet.java b/samples/openapi3/client/petstore/java/jersey2-java8-swagger2/src/main/java/org/openapitools/client/model/Pet.java index 3795fd24e06e..cbd7d59d9f5b 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8-swagger2/src/main/java/org/openapitools/client/model/Pet.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8-swagger2/src/main/java/org/openapitools/client/model/Pet.java @@ -98,6 +98,7 @@ public class Pet { } public static final String JSON_PROPERTY_STATUS = "status"; + @Deprecated private StatusEnum status; public Pet() { @@ -249,6 +250,7 @@ public class Pet { } + @Deprecated public Pet status(StatusEnum status) { this.status = status; return this; @@ -270,6 +272,7 @@ public class Pet { } + @Deprecated @JsonProperty(JSON_PROPERTY_STATUS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) public void setStatus(StatusEnum status) { diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java index 8b9ab208aeca..262ed26ba3b8 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java @@ -981,7 +981,7 @@ public class ApiClient extends JavaTimeFormatter { File file = (File) param.getValue(); FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()) .fileName(file.getName()).size(file.length()).build(); - + // Attempt to probe the content type for the file so that the form part is more correctly // and precisely identified, but fall back to application/octet-stream if that fails. MediaType type; @@ -990,7 +990,7 @@ public class ApiClient extends JavaTimeFormatter { } catch (IOException | IllegalArgumentException e) { type = MediaType.APPLICATION_OCTET_STREAM_TYPE; } - + multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type)); } else { FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build(); diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ObjectWithDeprecatedFields.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ObjectWithDeprecatedFields.java index 872f9734a9d4..aaf5316423cb 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ObjectWithDeprecatedFields.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ObjectWithDeprecatedFields.java @@ -45,12 +45,15 @@ public class ObjectWithDeprecatedFields { private String uuid; public static final String JSON_PROPERTY_ID = "id"; + @Deprecated private BigDecimal id; public static final String JSON_PROPERTY_DEPRECATED_REF = "deprecatedRef"; + @Deprecated private DeprecatedObject deprecatedRef; public static final String JSON_PROPERTY_BARS = "bars"; + @Deprecated private List bars = new ArrayList<>(); public ObjectWithDeprecatedFields() { @@ -81,6 +84,7 @@ public class ObjectWithDeprecatedFields { } + @Deprecated public ObjectWithDeprecatedFields id(BigDecimal id) { this.id = id; return this; @@ -101,6 +105,7 @@ public class ObjectWithDeprecatedFields { } + @Deprecated @JsonProperty(JSON_PROPERTY_ID) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) public void setId(BigDecimal id) { @@ -108,6 +113,7 @@ public class ObjectWithDeprecatedFields { } + @Deprecated public ObjectWithDeprecatedFields deprecatedRef(DeprecatedObject deprecatedRef) { this.deprecatedRef = deprecatedRef; return this; @@ -128,6 +134,7 @@ public class ObjectWithDeprecatedFields { } + @Deprecated @JsonProperty(JSON_PROPERTY_DEPRECATED_REF) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) public void setDeprecatedRef(DeprecatedObject deprecatedRef) { @@ -135,6 +142,7 @@ public class ObjectWithDeprecatedFields { } + @Deprecated public ObjectWithDeprecatedFields bars(List bars) { this.bars = bars; return this; @@ -163,6 +171,7 @@ public class ObjectWithDeprecatedFields { } + @Deprecated @JsonProperty(JSON_PROPERTY_BARS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) public void setBars(List bars) {