ts-json-schema-generator
ts-json-schema-generator copied to clipboard
feat: support dependencies json schema field
in JSON Schema Specification 7, it support dependencies in object type that can be used for data validate.
reference: https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#page-14
draft 7: https://json-schema.org/specification-links.html#draft-7
more info:
In JSON Schema 2019-09, dependencies has been split into dependentSchemas and dependentRequired
but currently we used the types from JSON Schema 7, so we can only support dependencies now.
Thanks. I marked this as a draft.
@domoritz Hello, This pull request is ready for review.
I'm sorry for updating this PR so late, I was a little busy recently.
All good. Do you think it makes sense to update to a newer version of json schema? Also, is there some way we could use this functionality for some specific ts patterns rather than just for Jsdoc comments? Are the jadoc comments used anywhere else ow is this just a json schema thing?
- Do you think it makes sense to update to a newer version of json schema?
I don't think there's a need to do that.
- is there some way we could use this functionality for some specific ts patterns rather than just for Jsdoc comments.
Currently, it seem that TypeScript do not has a conception about dependency? In my use case, I'm using JSON Schemas to validate user input data, so this code already meets my needs.
Thanks for the pull request. I think I would like to hear from someone else who wants this feature before adding it since there is no equivalent support in TS. Does that make sense?
Thanks for the pull request. I think I would like to hear from someone else who wants this feature before adding it since there is no equivalent support in TS. Does that make sense?
Ok, But in my opinion, the dependentRequired is the same kind of title/format in BasicAnnotationsReader class, it also read the jsdoc and save it to JSON Schemas:
https://github.com/vega/ts-json-schema-generator/blob/6b0e62e9e4794a28f60fa74ee332d03b026ca105/src/AnnotationsReader/BasicAnnotationsReader.ts#L10
it is a descriptor about this field.
So I think jsdoc is acceptable.
@domoritz I have moved the dependencies related code to ExtendedAnnotationsReader.
I add a new function called getTypeAnnotations for AnnotationsReader interface:
export interface AnnotationsReader {
getAnnotations(node: ts.Node): Annotations | undefined;
+ getTypeAnnotations?(type: BaseType): Annotations | undefined;
}
and then in the ExtendedAnnotationsReader, it can read things its need from the ObjectType, then create the dependencies we need.
Can you resolve the conflicts @bytemain. Thanks for your patience with my review!
Can you resolve the conflicts @bytemain. Thanks for your patience with my review!
Done.