Skip to content
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

Allow refPointerSuffix #42

Open
dbartholomae opened this issue Jul 3, 2020 · 4 comments
Open

Allow refPointerSuffix #42

dbartholomae opened this issue Jul 3, 2020 · 4 comments

Comments

@dbartholomae
Copy link

Hi there! I'm using class-validator-jsonschema to create multiple .schema.json files for creating schemas and then other libraries to dereference the schemas and build markdown documentation. The dereferencing only works with a bit of a hack, though: With the default refPointerPrefix of #/definitions/ the schemas cannot be dereferenced, as class-validator-jsonschema doesn't really put them in #/definitions/. Instead I now create the schemas as individual files, use refPointerPrefix as ./ and manually add .schema.json as a suffic to all #refs so the dereferencer can find the files.
It would be great to either have a refPointerSuffix option to add .schema.json to all #refs, or some guidance on what the preferred way is to link the schemas together and dereference them correctly.

@epiphone
Copy link
Owner

epiphone commented Jul 4, 2020

Hi! Not sure if I totally grasp your use case here, but do you think it'd be solvable with JSON Schema's id property? https://json-schema.org/understanding-json-schema/structuring.html#id

I'd be happy to review a PR for refPointerSuffix too if that's easier.

@dbartholomae
Copy link
Author

It seems the $id property could also be a work-around, but also doesn't address the problem. Here's the repo which shows the usecase. In ./src you can find event definitions. Each event has a corresponding details definition that wouldn't really make sense without the event, but class-validator as far as I understand it requires me to split it into two classes. With help of the scripts in ./scripts I first convert from classes to json schema in ./schemas, and then from schemas to documentation in ./docs. The extractSchemas script manually changes the $ref properties so the createDocs script can correctly dereference them.

@epiphone
Copy link
Owner

epiphone commented Jul 9, 2020

Alright, looks like refPointerSuffix is the way to go then.

@dbartholomae
Copy link
Author

Thinking about it a bit more, there are two other ways to solve this:

  1. Add a refPointerTransformer function as an alternative to refPointerSuffix. This would offer more flexibility without introducing additional complexity.
  2. Allowing some way to inline references as definitions into schemas, e. g. in the JSONSchema decorator. This would solve the core problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants