andyglow / scala-jsonschema

Scala JSON Schema
Other
122 stars 38 forks source link

Include title and description for sum types inside companion object #230

Closed drevisios closed 2 years ago

drevisios commented 2 years ago

When generating oneOf schema for sum types inside companion object, also include title and description provided from annotations to the subtypes

andyglow commented 2 years ago

Hi, @drevisios thank you for the contribution may I ask in which version of spec this is allowed? I mean.. oneOf: [ { title: "", description: "", ... }] Are you sure this is aligned with spec?

drevisios commented 2 years ago

Hi @andyglow I think it is aligned. If we check the draft-07 schema the definition is "oneOf": { "$ref": "#/definitions/schemaArray" } and then "schemaArray": { "type": "array", "minItems": 1, "items": { "$ref": "#" } }, where schema array is a non empty list of schemas, so I guess it should carry all the extra properties.

Still I could be wrong but I find it really useful in my project when I generate forms from the json schema and the field is a union of types. It is useful to have some extra info about these types in a structured way.

andyglow commented 2 years ago

closing it without merge in favor of #233 @drevisios please check

drevisios commented 2 years ago

@andyglow Perfect!