We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jackson allows to define polymorphic types definitions on the properties:
@Data public static class Container { private String polymorphicPropertyDefinition; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "polymorphicPropertyDefinition") @JsonSubTypes({ @JsonSubTypes.Type(value = ConcreteType1.class, name = "type_1"), @JsonSubTypes.Type(value = ConcreteType2.class, name = "type_2") }) private AbstractType polymorphicProperty; } public interface AbstractType { } @Data public static class ConcreteType1 implements AbstractType { private String value; } @Data public static class ConcreteType2 implements AbstractType { private int value; }
When generating a schema for Container from the example above:
Container
@Test void testPolymorphicType() throws JsonProcessingException { ObjectMapper mapper = createObjectMapper(); JsonSchemaGenerator jsonSchemaGenerator = new JsonSchemaGenerator(mapper); JsonNode jsonSchema = jsonSchemaGenerator.generateJsonSchema(Container.class); System.out.println(mapper.writeValueAsString(jsonSchema)); }
this type information is not used and oneOf is not generated:
oneOf
{ "$schema" : "http://json-schema.org/draft-04/schema#", "title" : "Container", "type" : "object", "additionalProperties" : false, "properties" : { "polymorphicPropertyDefinition" : { "type" : "string" }, "polymorphicProperty" : { } } }
I would expect the schema to look like this (similarly to what is generated when @JsonSubTypes is used on a class level):
@JsonSubTypes
{ "$schema" : "http://json-schema.org/draft-04/schema#", "title" : "Container", "type" : "object", "additionalProperties" : false, "properties" : { "polymorphicPropertyDefinition" : { "type" : "string", "enum" : [ "type_1", "type_2" ] }, "polymorphicProperty" : { "oneOf" : [ { "$ref" : "#/definitions/ConcreteType1" }, { "$ref" : "#/definitions/ConcreteType2" } ] } }, "definitions" : { "ConcreteType1" : { "type" : "object", "additionalProperties" : false, "properties" : { "value" : { "type" : "string" } }, "title" : "type_1" }, "ConcreteType2" : { "type" : "object", "additionalProperties" : false, "properties" : { "value" : { "type" : "integer" } }, "title" : "type_2" } } }
The text was updated successfully, but these errors were encountered:
Any update here? Not sure where to start to fix this
Sorry, something went wrong.
No branches or pull requests
Jackson allows to define polymorphic types definitions on the properties:
When generating a schema for
Container
from the example above:this type information is not used and
oneOf
is not generated:I would expect the schema to look like this (similarly to what is generated when
@JsonSubTypes
is used on a class level):The text was updated successfully, but these errors were encountered: