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
feat: support $ref #1208
feat: support $ref #1208
Changes from 5 commits
f7ba9d6
31486e2
d2a599f
5a53880
f97459c
3d7a019
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
export interface MyObject { | ||
/** | ||
* @ref http://json-schema.org/draft-07/schema# | ||
*/ | ||
nested: MyNestedObject | ||
|
||
/** | ||
* @ref http://json-schema.org/draft-07/schema# | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does json schema support additional properties here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand. What do you mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also add a comment here and see that in the description of the json schema property? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done 👍 |
||
*/ | ||
myObject: { [key: string]: string }; | ||
} | ||
|
||
export interface MyNestedObject { | ||
foo: string; | ||
bar: number; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"$ref": "#/definitions/MyObject", | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"definitions": { | ||
"MyObject": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"nested": { | ||
"$ref": "http://json-schema.org/draft-07/schema#" | ||
}, | ||
"myObject": { | ||
"$ref": "http://json-schema.org/draft-07/schema#" | ||
} | ||
}, | ||
"required": [ | ||
"nested", "myObject" | ||
], | ||
"type": "object" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is too late. At this point we already generated the schema. It would be better to not even recurse into types when we have a ref.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'll look into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated
AnnotatedNodeParser
such that it short-circuits child type parsing if an explicitref
annotation was provided.Instead, it sets the child type to
AnyType
. The AnyType is conveniently represented as an empty object which means we'll only get the$ref
property in the output schema and no additional noise coming from the type itself.