Skip to content
New issue

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

[Feature] Support for definitions #135

Open
rrmistry opened this issue May 21, 2019 · 2 comments
Open

[Feature] Support for definitions #135

rrmistry opened this issue May 21, 2019 · 2 comments

Comments

@rrmistry
Copy link

Problem I am trying to solve:

Given Java Objects:

@JsonSubTypes({
    @JsonSubTypes.Type(value = A.class),
    @JsonSubTypes.Type(value = B.class)
})
public interface I {}

public class A implements I {
    public int varA;
}
public class B implements I {
    public int varB;
}
public class C {
    public I varC;
}

I desire a json schema as follows:

{
  "definitions": {
    "urn:jsonschema:com:mycompany:GenerateSchemas:A": {
        "type" : "object",
        "id" : "urn:jsonschema:com:mycompany:GenerateSchemas:A",
        "properties" : {
          "varA" : {
            "type" : "integer"
          }
        }
      },
    "urn:jsonschema:com:mycompany:GenerateSchemas:B": {
        "type" : "object",
        "id" : "urn:jsonschema:com:mycompany:GenerateSchemas:B",
        "properties" : {
          "varB" : {
            "type" : "integer"
          }
        }
      }
  },
  "type" : "object",
  "id" : "urn:jsonschema:com:mycompany:GenerateSchemas:C",
  "properties" : {
    "varC" : {
      "type" : "object",
      "oneOf": [
        { "$ref": "urn:jsonschema:com:mycompany:GenerateSchemas:A" },
        { "$ref": "urn:jsonschema:com:mycompany:GenerateSchemas:B" }
      ]
    }
  }
}

Using version 2.9.8 of the library, the schema that is generated is:

{
  "type" : "object",
  "id" : "urn:jsonschema:com:mycompany:GenerateSchemas:C",
  "properties" : {
    "varC" : {
      "type" : "any"
    }
  }
}

It would be nice if it was possible to natively support this given that @JsonSubType annotations are present.

Please see related to StackOverflow Question: https://stackoverflow.com/questions/56174997/json-schema-generator-with-inheritance-and-references
My workaround: https://gist.github.com/rrmistry/2246c959d1c9cc45894ecf55305c61fd
(Could be improved if approved)

Thank you,

@mahajansourav87
Copy link

Any update?

@cowtowncoder
Copy link
Member

If there is an update, someone will actually write a note here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants