{"action":"created","issue":{"url":"https://api.github.com/repos/mbknor/mbknor-jackson-jsonSchema/issues/28","repository_url":"https://api.github.com/repos/mbknor/mbknor-jackson-jsonSchema","labels_url":"https://api.github.com/repos/mbknor/mbknor-jackson-jsonSchema/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/mbknor/mbknor-jackson-jsonSchema/issues/28/comments","events_url":"https://api.github.com/repos/mbknor/mbknor-jackson-jsonSchema/issues/28/events","html_url":"https://github.com/mbknor/mbknor-jackson-jsonSchema/issues/28","id":193859209,"number":28,"title":"Inlining abstract classes","user":{"login":"ratulm","id":4723124,"avatar_url":"https://avatars.githubusercontent.com/u/4723124?v=3","gravatar_id":"","url":"https://api.github.com/users/ratulm","html_url":"https://github.com/ratulm","followers_url":"https://api.github.com/users/ratulm/followers","following_url":"https://api.github.com/users/ratulm/following{/other_user}","gists_url":"https://api.github.com/users/ratulm/gists{/gist_id}","starred_url":"https://api.github.com/users/ratulm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ratulm/subscriptions","organizations_url":"https://api.github.com/users/ratulm/orgs","repos_url":"https://api.github.com/users/ratulm/repos","events_url":"https://api.github.com/users/ratulm/events{/privacy}","received_events_url":"https://api.github.com/users/ratulm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-06T19:15:04Z","updated_at":"2016-12-09T02:33:20Z","closed_at":null,"body":"Hi, I have an inter-linked class structure, the essence of which can be captured as the following:\r\n\r\n        public class SchemaTest {\r\n           public List<Parent> parents;   \r\n        }\r\n        \r\n        @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = \"class\")\r\n        @JsonSubTypes({\r\n           @JsonSubTypes.Type(value = Child1.class),\r\n           @JsonSubTypes.Type(value = Child2.class)})\r\n         public abstract class Parent {\r\n          }\r\n           \r\n         public class Child1 extends Parent {\r\n            public List<Parent> parents1;      \r\n         }\r\n           \r\n         public class Child2 extends Parent {      \r\n            public List<Parent> parents2;\r\n         }\r\n\r\nThe module generates schema by essentially inlining the abstract class, as follows:\r\n\r\n      {\r\n        \"$schema\" : \"http://json-schema.org/draft-04/schema#\",\r\n        \"title\" : \"Schema Test\",\r\n        \"type\" : \"object\",\r\n        \"additionalProperties\" : false,\r\n        \"properties\" : {\r\n          \"parents\" : {\r\n            \"type\" : \"array\",\r\n            \"items\" : {\r\n              \"oneOf\" : [\r\n                {\r\n                  \"$ref\" : \"#/definitions/Child2\"\r\n                },\r\n                {\r\n                  \"$ref\" : \"#/definitions/Child1\"\r\n                }\r\n              ]\r\n            }\r\n          }\r\n        },\r\n        \"definitions\" : {\r\n          \"Child2\" : {\r\n            \"type\" : \"object\",\r\n            \"additionalProperties\" : false,\r\n            \"properties\" : {\r\n              \"class\" : {\r\n                \"type\" : \"string\",\r\n                \"enum\" : [\r\n                  null\r\n                ],\r\n                \"default\" : null\r\n              },\r\n              \"parents2\" : {\r\n                \"type\" : \"array\",\r\n                \"items\" : {\r\n                  \"oneOf\" : [\r\n                    {\r\n                      \"$ref\" : \"#/definitions/Child2\"\r\n                    },\r\n                    {\r\n                      \"$ref\" : \"#/definitions/Child1\"\r\n                    }\r\n                  ]\r\n                }\r\n              }\r\n            },\r\n            \"title\" : null,\r\n            \"required\" : [\r\n              \"class\"\r\n            ]\r\n          },\r\n          \"Child1\" : {\r\n            \"type\" : \"object\",\r\n            \"additionalProperties\" : false,\r\n            \"properties\" : {\r\n              \"class\" : {\r\n                \"type\" : \"string\",\r\n                \"enum\" : [\r\n                  null\r\n                ],\r\n                \"default\" : null\r\n              },\r\n              \"parents1\" : {\r\n                \"type\" : \"array\",\r\n                \"items\" : {\r\n                  \"oneOf\" : [\r\n                    {\r\n                      \"$ref\" : \"#/definitions/Child2\"\r\n                    },\r\n                    {\r\n                      \"$ref\" : \"#/definitions/Child1\"\r\n                    }\r\n                  ]\r\n                }\r\n              }\r\n            },\r\n            \"title\" : null,\r\n            \"required\" : [\r\n              \"class\"\r\n            ]\r\n          }\r\n        }\r\n      }\r\n\r\nThe issue is that this representation is losing information that all of the oneOf's are of the same type (Parent). Would it be possible to generate something like the following?\r\n\r\n       {\r\n        \"$schema\" : \"http://json-schema.org/draft-04/schema#\",\r\n        \"title\" : \"Schema Test\",\r\n        \"type\" : \"object\",\r\n        \"additionalProperties\" : false,\r\n        \"properties\" : {\r\n          \"parents\" : {\r\n            \"type\" : \"array\",\r\n            \"items\" : {\r\n              \"$ref\" : \"#/definitions/Parent\"\r\n            }\r\n          }\r\n        },\r\n        \"definitions\" : {\r\n          \"Parent\" : {\r\n            \"oneOf\" : [\r\n              {\r\n                \"$ref\" : \"#/definitions/Child2\"\r\n              },\r\n              {\r\n                \"$ref\" : \"#/definitions/Child1\"\r\n              }\r\n            ]\r\n          },\r\n          \"Child2\" : {\r\n            \"type\" : \"object\",\r\n            \"additionalProperties\" : false,\r\n            \"properties\" : {\r\n              \"class\" : {\r\n                \"type\" : \"string\",\r\n                \"enum\" : [\r\n                  null\r\n                ],\r\n                \"default\" : null\r\n              },\r\n              \"parents2\" : {\r\n                \"type\" : \"array\",\r\n                \"items\" : {\r\n                  \"$ref\" : \"#/definitions/Parent\"\r\n                }\r\n              }\r\n            },\r\n            \"title\" : null,\r\n            \"required\" : [\r\n              \"class\"\r\n            ]\r\n          },\r\n          \"Child1\" : {\r\n            \"type\" : \"object\",\r\n            \"additionalProperties\" : false,\r\n            \"properties\" : {\r\n              \"class\" : {\r\n                \"type\" : \"string\",\r\n                \"enum\" : [\r\n                  null\r\n                ],\r\n                \"default\" : null\r\n              },\r\n              \"parents1\" : {\r\n                \"type\" : \"array\",\r\n                \"items\" : {\r\n                  \"$ref\" : \"#/definitions/Parent\"\r\n                }\r\n              }\r\n            },\r\n            \"title\" : null,\r\n            \"required\" : [\r\n              \"class\"\r\n            ]\r\n          }\r\n        }\r\n      }\r\n"},"comment":{"url":"https://api.github.com/repos/mbknor/mbknor-jackson-jsonSchema/issues/comments/265917367","html_url":"https://github.com/mbknor/mbknor-jackson-jsonSchema/issues/28#issuecomment-265917367","issue_url":"https://api.github.com/repos/mbknor/mbknor-jackson-jsonSchema/issues/28","id":265917367,"user":{"login":"ratulm","id":4723124,"avatar_url":"https://avatars.githubusercontent.com/u/4723124?v=3","gravatar_id":"","url":"https://api.github.com/users/ratulm","html_url":"https://github.com/ratulm","followers_url":"https://api.github.com/users/ratulm/followers","following_url":"https://api.github.com/users/ratulm/following{/other_user}","gists_url":"https://api.github.com/users/ratulm/gists{/gist_id}","starred_url":"https://api.github.com/users/ratulm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ratulm/subscriptions","organizations_url":"https://api.github.com/users/ratulm/orgs","repos_url":"https://api.github.com/users/ratulm/repos","events_url":"https://api.github.com/users/ratulm/events{/privacy}","received_events_url":"https://api.github.com/users/ratulm/received_events","type":"User","site_admin":false},"created_at":"2016-12-09T02:33:20Z","updated_at":"2016-12-09T02:33:20Z","body":"For a real-world example, see http://intentionet.github.io/batfish/docson/#../datamodel.json. The relevant part is routingPolicies --> expand \"Statement\" --> expand \"If\" which nicely shows that If contains Statement.\r\n\r\nI got this by modifying expectObjectFormat. The changes are committed to branch noAbstractInline of my fork. I didn't issue a pull requests because it breaks some tests, and I don't have the expertise to fix them easily. \r\n\r\nHappy to help if you wanted to incorporate this change.\r\n\r\nThanks."}}
{"actor":{"display_login":"ratulm"}}