Standalone Validators support, modelname[]
in body fix and globalDefinitions complience fix
#219
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.
The main purpose of this PR is to add standaloneValidators support to elysia-swagger using
t.Composite
to merge schemas, fixing #218.t.Intersection
was considered, but it seemed to generate much more complex schemas then was actually necessaryOf course, this wouldn't work with validator chains that don't make sense, like first checking that
body
is at.String()
in a standalone guard and then expecting it to be at.Object()
in a route, but those do not work in Elysia either. Currently,t.Composite
ignores all non-object schemas when merging, so the resulting type for this example would bet.Object()
. Alternative approach could be to check for non-object schemas in the validator chain and either throw an error or just return that schema to signal to the user that something is wrong, because most API's I assume expect objects, not plain values.Along the way, this PR fixes
.model
support making it more spec compliant by deleting the $id property on the globalDefinitions and creating valid schemas forbody: "modelname[]"
definitionsThe big test was updated to include all of these new behaviors