From b45de4fa4b2466ab23c7c7aa2619ef543cac6948 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Sat, 24 Aug 2024 10:40:56 +0200 Subject: [PATCH] Update samples --- .../resources/Java/modelInnerEnum.mustache | 2 +- .../openapitools/client/model/Example.java | 3 + .../openapitools/client/model/Example.java | 3 + .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 12 +- .../org/openapitools/client/model/Fruit.java | 3 + .../openapitools/client/model/FruitReq.java | 3 + .../openapitools/client/model/GmFruit.java | 75 ++++++---- .../org/openapitools/client/model/Mammal.java | 3 + .../client/model/MammalAnyof.java | 128 +++++++++++------- .../client/model/NullableShape.java | 3 + .../org/openapitools/client/model/Pig.java | 3 + .../client/model/Quadrilateral.java | 3 + .../org/openapitools/client/model/Shape.java | 3 + .../client/model/ShapeOrNull.java | 3 + .../openapitools/client/model/Triangle.java | 3 + .../openapitools/client/model/EnumTest.java | 12 +- .../openapitools/client/model/EnumTest.java | 12 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 8 +- .../openapitools/client/model/EnumTest.java | 12 +- .../org/openapitools/client/model/Fruit.java | 3 + .../openapitools/client/model/FruitReq.java | 3 + .../openapitools/client/model/GmFruit.java | 75 ++++++---- .../org/openapitools/client/model/Mammal.java | 3 + .../client/model/MammalAnyof.java | 128 +++++++++++------- .../client/model/NullableShape.java | 3 + .../org/openapitools/client/model/Pig.java | 3 + .../client/model/Quadrilateral.java | 3 + .../org/openapitools/client/model/Shape.java | 3 + .../client/model/ShapeOrNull.java | 3 + .../openapitools/client/model/Triangle.java | 3 + 52 files changed, 431 insertions(+), 269 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/modelInnerEnum.mustache b/modules/openapi-generator/src/main/resources/Java/modelInnerEnum.mustache index f875240996b32..be273444d7ff0 100644 --- a/modules/openapi-generator/src/main/resources/Java/modelInnerEnum.mustache +++ b/modules/openapi-generator/src/main/resources/Java/modelInnerEnum.mustache @@ -23,7 +23,7 @@ {{#withXml}} @XmlEnumValue({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}) {{/withXml}} - {{{name}}}({{^isUri}}{{dataType}}.valueOf({{/isUri}}{{{value}}}{{^isUri}}){{/isUri}}){{^-last}}, + {{{name}}}({{^isUri}}{{^isString}}{{dataType}}.valueOf({{/isString}}{{/isUri}}{{{value}}}{{^isUri}}{{^isString}}){{/isString}}{{/isUri}}){{^-last}}, {{/-last}}{{#-last}};{{/-last}} {{/enumVars}} {{/allowableValues}} diff --git a/samples/client/others/java/jersey2-oneOf-Mixed/src/main/java/org/openapitools/client/model/Example.java b/samples/client/others/java/jersey2-oneOf-Mixed/src/main/java/org/openapitools/client/model/Example.java index 7fd556601601e..88c216f26c4b1 100644 --- a/samples/client/others/java/jersey2-oneOf-Mixed/src/main/java/org/openapitools/client/model/Example.java +++ b/samples/client/others/java/jersey2-oneOf-Mixed/src/main/java/org/openapitools/client/model/Example.java @@ -122,6 +122,9 @@ public Example deserialize(JsonParser jp, DeserializationContext ctxt) throws IO ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new Example(); + } throw new IOException(String.format("Failed deserialization for Example: %d classes match result, expected 1", match)); } diff --git a/samples/client/others/java/jersey2-oneOf-duplicates/src/main/java/org/openapitools/client/model/Example.java b/samples/client/others/java/jersey2-oneOf-duplicates/src/main/java/org/openapitools/client/model/Example.java index d39111ccdfc58..e7704a1f3e2aa 100644 --- a/samples/client/others/java/jersey2-oneOf-duplicates/src/main/java/org/openapitools/client/model/Example.java +++ b/samples/client/others/java/jersey2-oneOf-duplicates/src/main/java/org/openapitools/client/model/Example.java @@ -122,6 +122,9 @@ public Example deserialize(JsonParser jp, DeserializationContext ctxt) throws IO ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new Example(); + } throw new IOException(String.format("Failed deserialization for Example: %d classes match result, expected 1", match)); } diff --git a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/model/EnumTest.java index 5fe70b9e5c67b..e8072d8bb9942 100644 --- a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/model/EnumTest.java @@ -134,9 +134,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -172,9 +172,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/model/EnumTest.java index 31e3f8199f3e0..67e9d965ce639 100644 --- a/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/feign-no-nullable/src/main/java/org/openapitools/client/model/EnumTest.java @@ -122,9 +122,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -160,9 +160,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/model/EnumTest.java index 6636e85935aeb..ed799eff97a71 100644 --- a/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/model/EnumTest.java @@ -131,9 +131,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -169,9 +169,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/google-api-client/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/google-api-client/src/main/java/org/openapitools/client/model/EnumTest.java index 726fcf37f13d4..6c368f4ff4fab 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/org/openapitools/client/model/EnumTest.java @@ -121,9 +121,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -159,9 +159,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/model/EnumTest.java index f25d2337822c1..0b77156a55e4e 100644 --- a/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/model/EnumTest.java @@ -124,9 +124,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -162,9 +162,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/EnumTest.java index f25d2337822c1..0b77156a55e4e 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/EnumTest.java @@ -124,9 +124,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -162,9 +162,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/EnumTest.java index 61987d6cb72aa..52ea4c2900f70 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/EnumTest.java @@ -137,9 +137,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -175,9 +175,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumIntegerOnly */ public enum EnumIntegerOnlyEnum { - NUMBER_2(2), + NUMBER_2(Integer.valueOf(2)), - NUMBER_MINUS_2(-2); + NUMBER_MINUS_2(Integer.valueOf(-2)); private Integer value; @@ -213,9 +213,9 @@ public static EnumIntegerOnlyEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; 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 9cc07429f12a1..1e4634db94931 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 @@ -131,6 +131,9 @@ public Fruit deserialize(JsonParser jp, DeserializationContext ctxt) throws IOEx ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new Fruit(); + } throw new IOException(String.format("Failed deserialization for Fruit: %d classes match result, expected 1", match)); } 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 63587eab7a4d1..d3a4e7d22f615 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 @@ -131,6 +131,9 @@ public FruitReq deserialize(JsonParser jp, DeserializationContext ctxt) throws I ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new FruitReq(); + } throw new IOException(String.format("Failed deserialization for FruitReq: %d classes match result, expected 1", match)); } diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/GmFruit.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/GmFruit.java index b718b0b32a3c3..10a54446858dd 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/GmFruit.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/GmFruit.java @@ -43,10 +43,12 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -89,29 +91,50 @@ public GmFruit deserialize(JsonParser jp, DeserializationContext ctxt) throws IO JsonNode tree = jp.readValueAsTree(); Object deserialized = null; - // deserialize Apple + boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); + int match = 0; + JsonToken token = tree.traverse(jp.getCodec()).nextToken(); + // deserialize Apple (nullable) try { - deserialized = tree.traverse(jp.getCodec()).readValueAs(Apple.class); - GmFruit ret = new GmFruit(); - ret.setActualInstance(deserialized); - return ret; + boolean attemptParsing = true; + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(Apple.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 'Apple'"); + } } catch (Exception e) { - // deserialization failed, continue, log to help debugging - log.log(Level.FINER, "Input data does not match 'GmFruit'", e); + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'Apple'", e); } // deserialize Banana try { - deserialized = tree.traverse(jp.getCodec()).readValueAs(Banana.class); + boolean attemptParsing = true; + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(Banana.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 'Banana'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'Banana'", e); + } + + if (match == 1) { GmFruit ret = new GmFruit(); ret.setActualInstance(deserialized); return ret; - } catch (Exception e) { - // deserialization failed, continue, log to help debugging - log.log(Level.FINER, "Input data does not match 'GmFruit'", e); } - - throw new IOException(String.format("Failed deserialization for GmFruit: no match found")); + if (tree.isEmpty()) { + return new GmFruit(); + } + throw new IOException(String.format("Failed deserialization for GmFruit: %d classes match result, expected 1", match)); } /** @@ -131,7 +154,7 @@ public GmFruit() { } public GmFruit(Apple o) { - super("anyOf", Boolean.FALSE); + super("anyOf", Boolean.TRUE); setActualInstance(o); } @@ -188,23 +211,23 @@ public Object getActualInstance() { } /** - * Get the actual instance of `Apple`. If the actual instance is not `Apple`, - * the ClassCastException will be thrown. - * - * @return The actual instance of `Apple` - * @throws ClassCastException if the instance is not `Apple` - */ + * Get the actual instance of `Apple`. If the actual instance is not `Apple`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Apple` + * @throws ClassCastException if the instance is not `Apple` + */ public Apple getApple() throws ClassCastException { return (Apple)super.getActualInstance(); } /** - * Get the actual instance of `Banana`. If the actual instance is not `Banana`, - * the ClassCastException will be thrown. - * - * @return The actual instance of `Banana` - * @throws ClassCastException if the instance is not `Banana` - */ + * Get the actual instance of `Banana`. If the actual instance is not `Banana`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Banana` + * @throws ClassCastException if the instance is not `Banana` + */ public Banana getBanana() throws ClassCastException { return (Banana)super.getActualInstance(); } 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 f359d92902e7f..0c71c65d1a8e8 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 @@ -174,6 +174,9 @@ public Mammal deserialize(JsonParser jp, DeserializationContext ctxt) throws IOE ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new Mammal(); + } throw new IOException(String.format("Failed deserialization for Mammal: %d classes match result, expected 1", match)); } diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/MammalAnyof.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/MammalAnyof.java index 2bec08cf2d7a2..7cd91a3dea247 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/MammalAnyof.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/MammalAnyof.java @@ -50,10 +50,12 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -106,40 +108,66 @@ public MammalAnyof deserialize(JsonParser jp, DeserializationContext ctxt) throw ret.setActualInstance(deserialized); return ret; } - // deserialize Pig + boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); + int match = 0; + JsonToken token = tree.traverse(jp.getCodec()).nextToken(); + // deserialize Whale try { - deserialized = tree.traverse(jp.getCodec()).readValueAs(Pig.class); - MammalAnyof ret = new MammalAnyof(); - ret.setActualInstance(deserialized); - return ret; + boolean attemptParsing = true; + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(Whale.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 'Whale'"); + } } catch (Exception e) { - // deserialization failed, continue, log to help debugging - log.log(Level.FINER, "Input data does not match 'MammalAnyof'", e); + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'Whale'", e); } - // deserialize Whale + // deserialize Zebra try { - deserialized = tree.traverse(jp.getCodec()).readValueAs(Whale.class); - MammalAnyof ret = new MammalAnyof(); - ret.setActualInstance(deserialized); - return ret; + boolean attemptParsing = true; + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(Zebra.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 'Zebra'"); + } } catch (Exception e) { - // deserialization failed, continue, log to help debugging - log.log(Level.FINER, "Input data does not match 'MammalAnyof'", e); + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'Zebra'", e); } - // deserialize Zebra + // deserialize Pig try { - deserialized = tree.traverse(jp.getCodec()).readValueAs(Zebra.class); + 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) { MammalAnyof ret = new MammalAnyof(); ret.setActualInstance(deserialized); return ret; - } catch (Exception e) { - // deserialization failed, continue, log to help debugging - log.log(Level.FINER, "Input data does not match 'MammalAnyof'", e); } - - throw new IOException(String.format("Failed deserialization for MammalAnyof: no match found")); + if (tree.isEmpty()) { + return new MammalAnyof(); + } + throw new IOException(String.format("Failed deserialization for MammalAnyof: %d classes match result, expected 1", match)); } /** @@ -207,17 +235,17 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(getActualInstance(), isNullable(), getSchemaType(), additionalProperties); } - public MammalAnyof(Pig o) { + public MammalAnyof(Whale o) { super("anyOf", Boolean.FALSE); setActualInstance(o); } - public MammalAnyof(Whale o) { + public MammalAnyof(Zebra o) { super("anyOf", Boolean.FALSE); setActualInstance(o); } - public MammalAnyof(Zebra o) { + public MammalAnyof(Pig o) { super("anyOf", Boolean.FALSE); setActualInstance(o); } @@ -254,17 +282,17 @@ public Map> getSchemas() { */ @Override public void setActualInstance(Object instance) { - if (JSON.isInstanceOf(Pig.class, instance, new HashSet<>())) { + if (JSON.isInstanceOf(Whale.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; } - if (JSON.isInstanceOf(Whale.class, instance, new HashSet<>())) { + if (JSON.isInstanceOf(Zebra.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; } - if (JSON.isInstanceOf(Zebra.class, instance, new HashSet<>())) { + if (JSON.isInstanceOf(Pig.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; } @@ -284,37 +312,37 @@ public Object 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. - * - * @return The actual instance of `Whale` - * @throws ClassCastException if the instance is not `Whale` - */ + * Get the actual instance of `Whale`. If the actual instance is not `Whale`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Whale` + * @throws ClassCastException if the instance is not `Whale` + */ public Whale getWhale() throws ClassCastException { return (Whale)super.getActualInstance(); } /** - * Get the actual instance of `Zebra`. If the actual instance is not `Zebra`, - * the ClassCastException will be thrown. - * - * @return The actual instance of `Zebra` - * @throws ClassCastException if the instance is not `Zebra` - */ + * Get the actual instance of `Zebra`. If the actual instance is not `Zebra`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Zebra` + * @throws ClassCastException if the instance is not `Zebra` + */ public Zebra getZebra() throws ClassCastException { 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 ad4615323d854..c6229bbaa6025 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 @@ -153,6 +153,9 @@ public NullableShape deserialize(JsonParser jp, DeserializationContext ctxt) thr ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new NullableShape(); + } throw new IOException(String.format("Failed deserialization for NullableShape: %d classes match result, expected 1", match)); } 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 5b264de1ab20b..22025d45009ae 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 @@ -153,6 +153,9 @@ public Pig deserialize(JsonParser jp, DeserializationContext ctxt) throws IOExce ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new Pig(); + } throw new IOException(String.format("Failed deserialization for Pig: %d classes match result, expected 1", match)); } 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 dfbc7e606a777..30d940d7b4a0b 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 @@ -153,6 +153,9 @@ public Quadrilateral deserialize(JsonParser jp, DeserializationContext ctxt) thr ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new Quadrilateral(); + } throw new IOException(String.format("Failed deserialization for Quadrilateral: %d classes match result, expected 1", match)); } 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 65b6b395bc108..5744dfa9666de 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 @@ -153,6 +153,9 @@ public Shape deserialize(JsonParser jp, DeserializationContext ctxt) throws IOEx ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new Shape(); + } throw new IOException(String.format("Failed deserialization for Shape: %d classes match result, expected 1", match)); } 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 00381f7f2e0ff..714fb6d9705a1 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 @@ -153,6 +153,9 @@ public ShapeOrNull deserialize(JsonParser jp, DeserializationContext ctxt) throw ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new ShapeOrNull(); + } throw new IOException(String.format("Failed deserialization for ShapeOrNull: %d classes match result, expected 1", match)); } 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 6183cd4dcde34..c07e35c58bad2 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 @@ -174,6 +174,9 @@ public Triangle deserialize(JsonParser jp, DeserializationContext ctxt) throws I ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new Triangle(); + } throw new IOException(String.format("Failed deserialization for Triangle: %d classes match result, expected 1", match)); } diff --git a/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/EnumTest.java index f317018d0fd03..db8f3265954e0 100644 --- a/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/native-async/src/main/java/org/openapitools/client/model/EnumTest.java @@ -137,9 +137,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -175,9 +175,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumIntegerOnly */ public enum EnumIntegerOnlyEnum { - NUMBER_2(2), + NUMBER_2(Integer.valueOf(2)), - NUMBER_MINUS_2(-2); + NUMBER_MINUS_2(Integer.valueOf(-2)); private Integer value; @@ -213,9 +213,9 @@ public static EnumIntegerOnlyEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/EnumTest.java index cdb411064b3ed..fbac9197e4573 100644 --- a/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/EnumTest.java @@ -137,9 +137,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -175,9 +175,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumIntegerOnly */ public enum EnumIntegerOnlyEnum { - NUMBER_2(2), + NUMBER_2(Integer.valueOf(2)), - NUMBER_MINUS_2(-2); + NUMBER_MINUS_2(Integer.valueOf(-2)); private Integer value; @@ -213,9 +213,9 @@ public static EnumIntegerOnlyEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/rest-assured-jackson/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/rest-assured-jackson/src/main/java/org/openapitools/client/model/EnumTest.java index 8f076161581f1..49689dddb523c 100644 --- a/samples/client/petstore/java/rest-assured-jackson/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/rest-assured-jackson/src/main/java/org/openapitools/client/model/EnumTest.java @@ -124,9 +124,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -162,9 +162,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/model/EnumTest.java index 1a526187b592c..790a5199f1e62 100644 --- a/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/model/EnumTest.java @@ -142,9 +142,9 @@ public EnumStringRequiredEnum read(final JsonReader jsonReader) throws IOExcepti */ @JsonAdapter(EnumIntegerEnum.Adapter.class) public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -193,9 +193,9 @@ public EnumIntegerEnum read(final JsonReader jsonReader) throws IOException { */ @JsonAdapter(EnumNumberEnum.Adapter.class) public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/restclient-swagger2/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/restclient-swagger2/src/main/java/org/openapitools/client/model/EnumTest.java index bbbeefaba1429..c9fa44866f8ff 100644 --- a/samples/client/petstore/java/restclient-swagger2/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/restclient-swagger2/src/main/java/org/openapitools/client/model/EnumTest.java @@ -132,9 +132,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -170,9 +170,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/restclient-useSingleRequestParameter/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/restclient-useSingleRequestParameter/src/main/java/org/openapitools/client/model/EnumTest.java index 42f9f8e206a7f..5524b4d3e0405 100644 --- a/samples/client/petstore/java/restclient-useSingleRequestParameter/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/restclient-useSingleRequestParameter/src/main/java/org/openapitools/client/model/EnumTest.java @@ -131,9 +131,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -169,9 +169,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/restclient/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/restclient/src/main/java/org/openapitools/client/model/EnumTest.java index 42f9f8e206a7f..5524b4d3e0405 100644 --- a/samples/client/petstore/java/restclient/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/restclient/src/main/java/org/openapitools/client/model/EnumTest.java @@ -131,9 +131,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -169,9 +169,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/model/EnumTest.java index c84f2fa3fc8dc..7f1caca5f0a99 100644 --- a/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/model/EnumTest.java @@ -131,9 +131,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -169,9 +169,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/model/EnumTest.java index 92d2f1eee1f38..5fae8e2e9fecf 100644 --- a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/model/EnumTest.java @@ -153,10 +153,10 @@ public static EnumStringRequiredEnum fromValue(String value) { @XmlEnum(Integer.class) public enum EnumIntegerEnum { @XmlEnumValue("1") - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), @XmlEnumValue("-1") - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -196,10 +196,10 @@ public static EnumIntegerEnum fromValue(Integer value) { @XmlEnum(Double.class) public enum EnumNumberEnum { @XmlEnumValue("1.1") - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), @XmlEnumValue("-1.2") - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/model/EnumTest.java index 836b9fc93fbb8..c613e446dd783 100644 --- a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/model/EnumTest.java @@ -131,9 +131,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -169,9 +169,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/retrofit2-play26/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/retrofit2-play26/src/main/java/org/openapitools/client/model/EnumTest.java index 268c45b7a6572..9d5ca6b7a9049 100644 --- a/samples/client/petstore/java/retrofit2-play26/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/retrofit2-play26/src/main/java/org/openapitools/client/model/EnumTest.java @@ -123,9 +123,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -161,9 +161,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/retrofit2/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/retrofit2/src/main/java/org/openapitools/client/model/EnumTest.java index 7ae5e0b170b9f..2e7e6dab97209 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/org/openapitools/client/model/EnumTest.java @@ -139,9 +139,9 @@ public EnumStringRequiredEnum read(final JsonReader jsonReader) throws IOExcepti */ @JsonAdapter(EnumIntegerEnum.Adapter.class) public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -190,9 +190,9 @@ public EnumIntegerEnum read(final JsonReader jsonReader) throws IOException { */ @JsonAdapter(EnumNumberEnum.Adapter.class) public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/retrofit2rx2/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/retrofit2rx2/src/main/java/org/openapitools/client/model/EnumTest.java index 7ae5e0b170b9f..2e7e6dab97209 100644 --- a/samples/client/petstore/java/retrofit2rx2/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/retrofit2rx2/src/main/java/org/openapitools/client/model/EnumTest.java @@ -139,9 +139,9 @@ public EnumStringRequiredEnum read(final JsonReader jsonReader) throws IOExcepti */ @JsonAdapter(EnumIntegerEnum.Adapter.class) public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -190,9 +190,9 @@ public EnumIntegerEnum read(final JsonReader jsonReader) throws IOException { */ @JsonAdapter(EnumNumberEnum.Adapter.class) public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/retrofit2rx3/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/retrofit2rx3/src/main/java/org/openapitools/client/model/EnumTest.java index 7ae5e0b170b9f..2e7e6dab97209 100644 --- a/samples/client/petstore/java/retrofit2rx3/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/retrofit2rx3/src/main/java/org/openapitools/client/model/EnumTest.java @@ -139,9 +139,9 @@ public EnumStringRequiredEnum read(final JsonReader jsonReader) throws IOExcepti */ @JsonAdapter(EnumIntegerEnum.Adapter.class) public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -190,9 +190,9 @@ public EnumIntegerEnum read(final JsonReader jsonReader) throws IOException { */ @JsonAdapter(EnumNumberEnum.Adapter.class) public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/vertx-no-nullable/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/vertx-no-nullable/src/main/java/org/openapitools/client/model/EnumTest.java index 726fcf37f13d4..6c368f4ff4fab 100644 --- a/samples/client/petstore/java/vertx-no-nullable/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/vertx-no-nullable/src/main/java/org/openapitools/client/model/EnumTest.java @@ -121,9 +121,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -159,9 +159,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/model/EnumTest.java index c84f2fa3fc8dc..7f1caca5f0a99 100644 --- a/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/model/EnumTest.java @@ -131,9 +131,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -169,9 +169,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/webclient-jakarta/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/webclient-jakarta/src/main/java/org/openapitools/client/model/EnumTest.java index 42f9f8e206a7f..5524b4d3e0405 100644 --- a/samples/client/petstore/java/webclient-jakarta/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/webclient-jakarta/src/main/java/org/openapitools/client/model/EnumTest.java @@ -131,9 +131,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -169,9 +169,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/webclient-swagger2/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/webclient-swagger2/src/main/java/org/openapitools/client/model/EnumTest.java index 6761607407da6..6fcf8f0f9b408 100644 --- a/samples/client/petstore/java/webclient-swagger2/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/webclient-swagger2/src/main/java/org/openapitools/client/model/EnumTest.java @@ -132,9 +132,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -170,9 +170,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/model/EnumTest.java index c84f2fa3fc8dc..7f1caca5f0a99 100644 --- a/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/model/EnumTest.java @@ -131,9 +131,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -169,9 +169,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/EnumTest.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/EnumTest.java index 210b4f21aaa4f..28b1a4f249795 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/EnumTest.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/EnumTest.java @@ -135,9 +135,9 @@ public static EnumStringRequiredEnum fromValue(String value) { * Gets or Sets enumInteger */ public enum EnumIntegerEnum { - NUMBER_1(1), + NUMBER_1(Integer.valueOf(1)), - NUMBER_MINUS_1(-1); + NUMBER_MINUS_1(Integer.valueOf(-1)); private Integer value; @@ -173,9 +173,9 @@ public static EnumIntegerEnum fromValue(Integer value) { * Gets or Sets enumIntegerOnly */ public enum EnumIntegerOnlyEnum { - NUMBER_2(2), + NUMBER_2(Integer.valueOf(2)), - NUMBER_MINUS_2(-2); + NUMBER_MINUS_2(Integer.valueOf(-2)); private Integer value; @@ -211,9 +211,9 @@ public static EnumIntegerOnlyEnum fromValue(Integer value) { * Gets or Sets enumNumber */ public enum EnumNumberEnum { - NUMBER_1_DOT_1(1.1), + NUMBER_1_DOT_1(Double.valueOf(1.1)), - NUMBER_MINUS_1_DOT_2(-1.2); + NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2)); private Double value; diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Fruit.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Fruit.java index b2a0eca0b1d79..67a032dc94b73 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Fruit.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Fruit.java @@ -129,6 +129,9 @@ public Fruit deserialize(JsonParser jp, DeserializationContext ctxt) throws IOEx ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new Fruit(); + } throw new IOException(String.format("Failed deserialization for Fruit: %d classes match result, expected 1", match)); } diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/FruitReq.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/FruitReq.java index bd3bf06705aa7..871ce9cbff029 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/FruitReq.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/FruitReq.java @@ -129,6 +129,9 @@ public FruitReq deserialize(JsonParser jp, DeserializationContext ctxt) throws I ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new FruitReq(); + } throw new IOException(String.format("Failed deserialization for FruitReq: %d classes match result, expected 1", match)); } diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/GmFruit.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/GmFruit.java index 2206205198b2f..eda64cc2890f2 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/GmFruit.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/GmFruit.java @@ -41,10 +41,12 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -87,29 +89,50 @@ public GmFruit deserialize(JsonParser jp, DeserializationContext ctxt) throws IO JsonNode tree = jp.readValueAsTree(); Object deserialized = null; - // deserialize Apple + boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); + int match = 0; + JsonToken token = tree.traverse(jp.getCodec()).nextToken(); + // deserialize Apple (nullable) try { - deserialized = tree.traverse(jp.getCodec()).readValueAs(Apple.class); - GmFruit ret = new GmFruit(); - ret.setActualInstance(deserialized); - return ret; + boolean attemptParsing = true; + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(Apple.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 'Apple'"); + } } catch (Exception e) { - // deserialization failed, continue, log to help debugging - log.log(Level.FINER, "Input data does not match 'GmFruit'", e); + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'Apple'", e); } // deserialize Banana try { - deserialized = tree.traverse(jp.getCodec()).readValueAs(Banana.class); + boolean attemptParsing = true; + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(Banana.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 'Banana'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'Banana'", e); + } + + if (match == 1) { GmFruit ret = new GmFruit(); ret.setActualInstance(deserialized); return ret; - } catch (Exception e) { - // deserialization failed, continue, log to help debugging - log.log(Level.FINER, "Input data does not match 'GmFruit'", e); } - - throw new IOException(String.format("Failed deserialization for GmFruit: no match found")); + if (tree.isEmpty()) { + return new GmFruit(); + } + throw new IOException(String.format("Failed deserialization for GmFruit: %d classes match result, expected 1", match)); } /** @@ -129,7 +152,7 @@ public GmFruit() { } public GmFruit(Apple o) { - super("anyOf", Boolean.FALSE); + super("anyOf", Boolean.TRUE); setActualInstance(o); } @@ -186,23 +209,23 @@ public Object getActualInstance() { } /** - * Get the actual instance of `Apple`. If the actual instance is not `Apple`, - * the ClassCastException will be thrown. - * - * @return The actual instance of `Apple` - * @throws ClassCastException if the instance is not `Apple` - */ + * Get the actual instance of `Apple`. If the actual instance is not `Apple`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Apple` + * @throws ClassCastException if the instance is not `Apple` + */ public Apple getApple() throws ClassCastException { return (Apple)super.getActualInstance(); } /** - * Get the actual instance of `Banana`. If the actual instance is not `Banana`, - * the ClassCastException will be thrown. - * - * @return The actual instance of `Banana` - * @throws ClassCastException if the instance is not `Banana` - */ + * Get the actual instance of `Banana`. If the actual instance is not `Banana`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Banana` + * @throws ClassCastException if the instance is not `Banana` + */ public Banana getBanana() throws ClassCastException { return (Banana)super.getActualInstance(); } diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Mammal.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Mammal.java index bb56c64bd090f..653f958f1b9c8 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Mammal.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Mammal.java @@ -172,6 +172,9 @@ public Mammal deserialize(JsonParser jp, DeserializationContext ctxt) throws IOE ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new Mammal(); + } throw new IOException(String.format("Failed deserialization for Mammal: %d classes match result, expected 1", match)); } diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/MammalAnyof.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/MammalAnyof.java index f50608c5960f2..22e954d397ff1 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/MammalAnyof.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/MammalAnyof.java @@ -48,10 +48,12 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -104,40 +106,66 @@ public MammalAnyof deserialize(JsonParser jp, DeserializationContext ctxt) throw ret.setActualInstance(deserialized); return ret; } - // deserialize Pig + boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); + int match = 0; + JsonToken token = tree.traverse(jp.getCodec()).nextToken(); + // deserialize Whale try { - deserialized = tree.traverse(jp.getCodec()).readValueAs(Pig.class); - MammalAnyof ret = new MammalAnyof(); - ret.setActualInstance(deserialized); - return ret; + boolean attemptParsing = true; + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(Whale.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 'Whale'"); + } } catch (Exception e) { - // deserialization failed, continue, log to help debugging - log.log(Level.FINER, "Input data does not match 'MammalAnyof'", e); + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'Whale'", e); } - // deserialize Whale + // deserialize Zebra try { - deserialized = tree.traverse(jp.getCodec()).readValueAs(Whale.class); - MammalAnyof ret = new MammalAnyof(); - ret.setActualInstance(deserialized); - return ret; + boolean attemptParsing = true; + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(Zebra.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 'Zebra'"); + } } catch (Exception e) { - // deserialization failed, continue, log to help debugging - log.log(Level.FINER, "Input data does not match 'MammalAnyof'", e); + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'Zebra'", e); } - // deserialize Zebra + // deserialize Pig try { - deserialized = tree.traverse(jp.getCodec()).readValueAs(Zebra.class); + 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) { MammalAnyof ret = new MammalAnyof(); ret.setActualInstance(deserialized); return ret; - } catch (Exception e) { - // deserialization failed, continue, log to help debugging - log.log(Level.FINER, "Input data does not match 'MammalAnyof'", e); } - - throw new IOException(String.format("Failed deserialization for MammalAnyof: no match found")); + if (tree.isEmpty()) { + return new MammalAnyof(); + } + throw new IOException(String.format("Failed deserialization for MammalAnyof: %d classes match result, expected 1", match)); } /** @@ -205,17 +233,17 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(getActualInstance(), isNullable(), getSchemaType(), additionalProperties); } - public MammalAnyof(Pig o) { + public MammalAnyof(Whale o) { super("anyOf", Boolean.FALSE); setActualInstance(o); } - public MammalAnyof(Whale o) { + public MammalAnyof(Zebra o) { super("anyOf", Boolean.FALSE); setActualInstance(o); } - public MammalAnyof(Zebra o) { + public MammalAnyof(Pig o) { super("anyOf", Boolean.FALSE); setActualInstance(o); } @@ -252,17 +280,17 @@ public Map> getSchemas() { */ @Override public void setActualInstance(Object instance) { - if (JSON.isInstanceOf(Pig.class, instance, new HashSet<>())) { + if (JSON.isInstanceOf(Whale.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; } - if (JSON.isInstanceOf(Whale.class, instance, new HashSet<>())) { + if (JSON.isInstanceOf(Zebra.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; } - if (JSON.isInstanceOf(Zebra.class, instance, new HashSet<>())) { + if (JSON.isInstanceOf(Pig.class, instance, new HashSet<>())) { super.setActualInstance(instance); return; } @@ -282,37 +310,37 @@ public Object 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. - * - * @return The actual instance of `Whale` - * @throws ClassCastException if the instance is not `Whale` - */ + * Get the actual instance of `Whale`. If the actual instance is not `Whale`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Whale` + * @throws ClassCastException if the instance is not `Whale` + */ public Whale getWhale() throws ClassCastException { return (Whale)super.getActualInstance(); } /** - * Get the actual instance of `Zebra`. If the actual instance is not `Zebra`, - * the ClassCastException will be thrown. - * - * @return The actual instance of `Zebra` - * @throws ClassCastException if the instance is not `Zebra` - */ + * Get the actual instance of `Zebra`. If the actual instance is not `Zebra`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `Zebra` + * @throws ClassCastException if the instance is not `Zebra` + */ public Zebra getZebra() throws ClassCastException { 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/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/NullableShape.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/NullableShape.java index 722be9d22c4a1..b4e2d670a1e8b 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/NullableShape.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/NullableShape.java @@ -151,6 +151,9 @@ public NullableShape deserialize(JsonParser jp, DeserializationContext ctxt) thr ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new NullableShape(); + } throw new IOException(String.format("Failed deserialization for NullableShape: %d classes match result, expected 1", match)); } diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Pig.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Pig.java index f11d2ab50aa55..6cefc34c81d3b 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Pig.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Pig.java @@ -151,6 +151,9 @@ public Pig deserialize(JsonParser jp, DeserializationContext ctxt) throws IOExce ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new Pig(); + } throw new IOException(String.format("Failed deserialization for Pig: %d classes match result, expected 1", match)); } diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Quadrilateral.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Quadrilateral.java index a1f6afaadfe0a..4b93aae72153d 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Quadrilateral.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Quadrilateral.java @@ -151,6 +151,9 @@ public Quadrilateral deserialize(JsonParser jp, DeserializationContext ctxt) thr ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new Quadrilateral(); + } throw new IOException(String.format("Failed deserialization for Quadrilateral: %d classes match result, expected 1", match)); } diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Shape.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Shape.java index 74326a74a1d32..197b4b839c547 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Shape.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Shape.java @@ -151,6 +151,9 @@ public Shape deserialize(JsonParser jp, DeserializationContext ctxt) throws IOEx ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new Shape(); + } throw new IOException(String.format("Failed deserialization for Shape: %d classes match result, expected 1", match)); } diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ShapeOrNull.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ShapeOrNull.java index 4acc913b0a52f..45cf41466468f 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ShapeOrNull.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ShapeOrNull.java @@ -151,6 +151,9 @@ public ShapeOrNull deserialize(JsonParser jp, DeserializationContext ctxt) throw ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new ShapeOrNull(); + } throw new IOException(String.format("Failed deserialization for ShapeOrNull: %d classes match result, expected 1", match)); } diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Triangle.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Triangle.java index 95cc9ee9e590f..3fe2c3af173d2 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Triangle.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/Triangle.java @@ -172,6 +172,9 @@ public Triangle deserialize(JsonParser jp, DeserializationContext ctxt) throws I ret.setActualInstance(deserialized); return ret; } + if (tree.isEmpty()) { + return new Triangle(); + } throw new IOException(String.format("Failed deserialization for Triangle: %d classes match result, expected 1", match)); }