Skip to content

Standalone Validators support, modelname[] in body fix and globalDefinitions complience fix #219

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Lolotronop
Copy link

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 necessary

Of course, this wouldn't work with validator chains that don't make sense, like first checking that body is a t.String() in a standalone guard and then expecting it to be a t.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 be t.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 for body: "modelname[]" definitions
The big test was updated to include all of these new behaviors

@walker-tx
Copy link

walker-tx commented Jul 2, 2025

Howdy - it looks like this PR fixes 2 issues I'm currently experiencing:

Is this PR ready to merge? Looking forward to publishing my OAS via Elysia!

Update

I was wrong - my issues are a bit different than what's addressed here. But I'll submit a PR 👍🏻

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

Successfully merging this pull request may close these issues.

2 participants