-
Notifications
You must be signed in to change notification settings - Fork 12
Implement nested schemas #42
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
base: master
Are you sure you want to change the base?
Conversation
support "$ref" property: - the type of the property gets linked to the property in the definitions section - all property in the definitions section get written in there own comment sections support for the "allOf" property: - "$ref" : + if only one "$ref" is available the type gets linked + with multiple "$ref" all properties of the referenced definitions get copied into the current property and the type is set to "object" - all properties of sub objects get copied into the current property
This is exciting to see implemented, but could we implement a mechanism as in #41 by which a type can be derived from a type (e.g., an option that the first item in Especially for where one is following classical type inheritance, it would be convenient to be able to explicitly link the base type (rather than just treating it as an object mixin, though that would make sense for some projects/scenarios). It'd also be nice to have a test case to ensure it is working as intended. |
I've continued the discussion back in #41 . Especially since that approach is detailed in the JSON Schema spec, I think that would be the way to go. |
@brettz9 that would mean an This would be easy to implement for a For a Laborer: {
title: 'Laborer',
anyOf: [
{$ref: '#/$defs/Person', "classRelation": "is-a",},
{$ref: '#/$defs/Person1', "classRelation": "has-a",},
{$ref: '#/$defs/Person2',},
]
} would become: /**
* @typedef {object|Person|generatedType} Laborer
* @property {Person1} [Person1]
*/
/**
* @typedef {object} generatedType
* "copy of Person2"
*/ or should the |
I think the example they list where "has-a" is attached to one of the "properties" may have been intended to suggest merely that the "foo" property was related to the main schema in a "has-a" relationship as opposed to say just being an "attribute" of the main schema (e.g., like if a I don't think though that "has-a" has any utility for jsdoc (at least standard jsdoc) since using it to add a But the inheritance vs. property (aka mixin) distinction does map to jsdoc differently (i.e., |
implemented nested schemas with the anyOf and allOf keyword.
Implementation for the allOf:
anyOf:
|
Just an FYI that I've added support for this format in my project, jsdoc-jsonschema, and I've been using With 100% coverage in both projects, it appears that if this PR can be rebased and is deemed ready to be merged, there should I believe now be full round-trippabiility between the formats we expect/create. |
Just a small update: I have fixed the merging conflicts with the main branch, so it should be save to implement the changes. |
Hi, A couple items, if I may...
Even if you make no. 2 as an option, could we allow hierarchies to be shown in a more standard fashion with typedefs cross-referencing each other like: /**
* @typedef {PlainObject} Coordinate
* @property {number} x
* @property {number} y
*/
/**
* @typedef {Coordinate} Circle
* @property {number} r
*/
/**
* @typedef {Circle} ColoredShape
* @property {string} color
*/ And for unions/intersections, e.g., /**
* @typedef {ShapeInfo & (Circle|Rectangle)} PositionedShape3D
* @property {number} z
*/ FWIW, on my test-json-schema branch of Thanks! |
@RainerBayr : Do you think you could take a look at my comment at https://github.com/n3ps/json-schema-to-jsdoc/pull/42/files#issuecomment-706453382 for possible consideration in this PR? |
Looks like I had the wrong link. I think I had been referring to #41 (comment) |
#41 support "$ref" property:
support for the "allOf" property: