FasterXML / FasterXML/jackson-module-jsonSchema

[Feature] Support for `definitions`

Đang mở
#135 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Java
Star
387
Fork
136
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### Problem I am trying to solve:

Given Java Objects:

```java
@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:
```json
{
"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:
```json
{
"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,

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.