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

Add schemars integration #226

Closed
wants to merge 4 commits into from
Closed

Conversation

DXist
Copy link
Contributor

@DXist DXist commented Jul 11, 2022

This PR adds integration with schemars

The integration derives JsonSchema trait for ValidationErrors, ValidationErrorKind and ValidationError types.

This allows to include ValidationErrors in OpenAPI operation definitions as result types. Example integration code is included as an integration test that uses rocket and rocket_okapi to define an API method that takes validated input result and returns OperationError::ValidationErrors error variant in case of validation failure.

Without this integration I used newtype wrappers for the mentioned types + From definitions that did several field clones. With integration no extra memory allocations is required.

Below is a visualisation of an API error type that has recursive ValidationErrors variant. The visualisation is done by rapidoc.
Снимок экрана 2022-07-11 в 21 06 31

@DXist
Copy link
Contributor Author

DXist commented Jul 11, 2022

Unfortunately Rust 1.57 is required to run test for this feature.

@DXist DXist mentioned this pull request Jul 25, 2022
@IniterWorker
Copy link
Contributor

IniterWorker commented Jul 26, 2022

Hi,

I fast reviewed @DXist's commits in #226. Impl schemars is good to me. But what are your thoughts @Keats and @krojew, about tests/examples with a hard coupling on rocket and rocket_okapi.
Perhaps too hard coupled on third-party libs rocket and rocket_okapi?

@DXist
Copy link
Contributor Author

DXist commented Jul 26, 2022

Hi,

Thank you for feedback!

I think it's possible to introduce a separate crate in this repository to run integration tests. And isolate test dependencies there. They can run separately with newer Rust version.

@Keats Keats closed this Nov 21, 2024
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.

3 participants