-
Notifications
You must be signed in to change notification settings - Fork 202
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: Generate titles from definition names #2127
base: next
Are you sure you want to change the base?
Conversation
* Patch generator to generate definition titles until vega/ts-json-schema-generator#2127 is resolved * Add launch config for debugging schema generation * Disallow topRef generation so docusarus json viewer works * Write to docsite static assets on generation
@@ -135,6 +135,9 @@ export class SchemaGenerator { | |||
const name = child.getName(); | |||
if (!(name in definitions)) { | |||
definitions[name] = this.typeFormatter.getDefinition(child.getType()); | |||
if (this.config?.definitionTitles) { |
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'm not sure if this is the best place. Something inside getDefinition
should be better. This doesn't work for deep objects/definitions, either.
@domoritz general idea seems fair, but I'm not sure if this is something we want to add (at least not just as an |
What's the reason for having titles? I don't like having extra CLI actions when possible. |
The reason for generating titles is that they are a valid property type for draft-07 json-schema and are used by some applications for displaying the names of definitions. I use json-schema-plugin for Docusaurus to display my application's config to users in the documentation. Without With This is just the relevant example to me but I'm sure I'm not the only one who would benefit from having titles, since its a valid piece of the schema to consume. I would have also preferred to avoid adding CLI args by instead using custom formatting for a definition but I could not find a way to get access to the node's name ( In the last stage of If anyone has guidance on how I could better achieve this using a custom formatter I'd be happy to adapt this PR to do that instead but I was struggling for a simple way to get this result. |
I think we should make titles the default but also
Does that seem reasonable? |
Titles could be the default but should be available under a configuration option as well, otherwise this release would invalidate all previous generated schemas. Maybe non-default until next major? |
Adding titles isn't a breaking change imo but should be a minor version bump. But I don't feel strongly about it. |
It might not be a breaking change like builds failing, but this will increase the final JSON output by a considerable percentage since names will now be duplicated. Also, any kind of cache keys (hashed ones) will hash into different values even for the same input since a new field was added for every single schema present. |
All root child definitions have a 'title' added to their definition if the opt-in definitionTitles option is set
Any thoughts regarding refactoring so this could be a custom formatter instead? I'll admit I don't fully grok the whole schema generation lifecycle but from what I observed while debugging: Changing
|
Yeah, I think this should/could be implemented as a formatter similar to the annotation formatter. We can already get the title via a comment so we should also make sure that we are letting people override the title with a comment. |
can you elaborate on this a bit more? Where, in code? |
I don't have the exact syntax handy but with @title or @tjs-title you can set properties that will appear in the schema. |
All root child definitions have a
title
added to their definition if the opt-indefinitionTitles
option is setdefinitionTitles: true
programatically or from the command line with arg--definition-titles
Closes #1486