Comments (3)
I don't know how much of an effort this is. I've seen libraries like json schema random data generators that don't work with $defs
and I don't know if the maintainers didn't bother or it was difficult.
from json-schema-to-jsdoc.
I can't speak to the tools in question, but this is just JSON after all. Also $defs
was simply a name change from definitions
, I guess for better avoidance of conflicts, so I don't think it will be too much trouble.
from json-schema-to-jsdoc.
I just came across a very interesting part of the JSON Schema spec: http://json-schema.org/draft/2019-09/json-schema-core.html#rfc.appendix.E
The whole section is relevant and worth a read, but to summarize, it suggests creating "an annotation keyword for use in the same schema object alongside of a reference keyword such as "$ref". " It qualifies that this is only for illustrative purposes, but the keyword they offer is "classRelation": "is-a",
, and that sounds reasonable to me. This also has the benefit that we could allow multiple inheritance (via unions), e.g.:
const schemas = {
$defs: {
Person: {
title: 'Person',
type: 'object',
properties: {
name: { type: 'string', description: "A person's name" },
age: { type: 'integer', description: "A person's age" }
},
required: ['name']
},
Personnel: {
type: 'object',
properties: {skillLevel: {type: 'integer'}},
},
Laborer: {
title: 'Laborer',
allOf: [
{$ref: '#/$defs/Person', "classRelation": "is-a",},
{$ref: '#/$defs/Personnel', "classRelation": "is-a",},
]
}
}
}
...could become:
/**
* @typedef {PlainObject} Person
* @property {string} name A person's name
* @property {integer} [age] A person's age
*/
/**
* @typedef {PlainObject} Personnel
* @property {integer} [skillLevel]
*/
/**
* @typedef {Person&Personnel} Laborer
*/
And if anyOf
is used, the operator |
could be used in place of &
(actually &
is not really accepted by jsdoc, but there is an issue for it, and TypeScript (including when just plain JavaScript + jsdoc) supports it).
I think this would be an especially robust approach as well as one somewhat blessed by the JSON Schema spec.
from json-schema-to-jsdoc.
Related Issues (11)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-schema-to-jsdoc.