json-schema-typed
json-schema-typed copied to clipboard
Allow for additional properties
Hello @remyrylan and thanks for putting these types together!
I plan to use the JSONSchema type to author some schemas in TypeScript based on the draft 07, but I would also like to add custom keys to them (mainly to help generated documentation from these schemas).
Would you consider adding an extension point like an empty AdditionalProperties interface that we could then hook into using declare module to add additional properties?
Here is what it would look like:
Then we could do:
declare module "json-schema-typed" {
interface AdditionalProperties {
/**
* Yay, custom property!
*/
tags?: string[]
}
}
Does this adhere to the JSON Schema Spec? I have to keep it strictly to spec, would you be able to just create a derivative type in your project?
Something like
interface HelloWorld extends JSONSchema.Interface {
tags: string[]
}
It doesn't change the final type for the JSON Schema Spec by default, it's just an extension point for people needing a schema built on top of the existing drafts.
Extending the JSONSchema type isn't enough as the type is generic and is recursive.
I can't think of any other solution for people like me needing the JSONSchema type + additional properties. 😅