Open
Conversation
633a5d5 to
89409ca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This PR is based on #54. It will have to be rebased once #54 is merged
Summary
This PR allows glob inputs so that you can combine multiple json schema files into a single output
This is done by allowing glob for the
inputparameter (ex:npx schema2typebox -i **/*.json)Why is this better than generating one output per file?
Imagine you have the following schemas:
If you codegen this, you end up with three separate files, containing:
With the work done in #54, we can now easily solve this by just representing the types of all files as part of a single module
Is this really the best way to do this?
Using globs is very flexible, but another option would be to encourage people who want to aggregate files into a single output to instead use a file that only contains a single
$def:{ "$defs": { "Comment": { "$ref": "common.json#/$defs/comment" }, "Post": { "$ref": "common.json#/$defs/post" }, } }And you can see examples this single
$defpattern here, but I wouldn't recommend this approach for a few reasons:$defsare typically only meant to be used within the same file in which they're defined (if they're meant to be used by external files often, it's encouraged to split them into separate schema files). That means this pattern of files with only$defsin it is not really an encouraged pattern$defs(instead of having only top-level$defs)Given this, I believe the glob solution to be the best