-
Notifications
You must be signed in to change notification settings - Fork 386
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
OpenAPI spec to endpoint generator does not recognize field validation #2786
Comments
Your described solution should be the right way. However, I am not sure that all Open API validations can be mapped to current schema validations. It might need some extension of zio schema. This would need to be checked |
/bounty $250 |
💎 $250 bounty • ZIOSteps to solve:
Thank you for contributing to zio/zio-http! Add a bounty • Share on socials
|
/attempt #2786 Options |
I got a bit stuck with adding more validation parameters when parsing openapi schemas
First, I added
It looks like the error is coming from zio-schema and has something to do with the 22 field restriction, with the last added field being the 23rd. I'll try to look for a workaround, maybe there is an hlist based approach or schema declarations could be rearranged. |
might be a bug - I was able to reproduce it in a simplified form zio/zio-schema#691 |
/livestream |
I am done with the impl. But another fix for zio-schema is needed |
💡 @987Nabil submitted a pull request that claims the bounty. You can visit your bounty board to reward. |
Is your feature request related to a problem? Please describe.
The code that gets generated based on an openapi spec does not take into account additional field validations, for example,
for the following definition
and the endpoint using it
the case class that gets generated looks like this
running a server with a dummy implementation
and issuing a POST request against
/pets
with payload that should fail validation (the name size should be at least 3 character long)gets processed successfully instead
Describe the solution you'd like
changing the generated case class to include zio-schema validations seems to work with no changes to other parts of the generated code
in the corresponding endpoint definition
.in[Pet]
already responsible for validating input against the schema, and after adding the validation annotation I'm now getting 400 response from the server,However the response body is empty which could be a problem.
Describe alternatives you've considered
An alternative could be to generate endpoints that return Either[ValidationError, T] for users to implement and adjust format of validation errors if needed
Additional context
the full example https://github.com/stanislav-chetvertkov/zio-http-gen-example
The text was updated successfully, but these errors were encountered: