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 optional JsonSchema support #78

Merged

Conversation

ZackPierce
Copy link
Contributor

@ZackPierce ZackPierce commented Apr 30, 2021

Hello @mbrubeck , @reem et al, thanks for this useful library. Here's a feature enhancement that could help out.

Motivating Use Case

I would like to use types from ordered-float in one of my JSON APIs. The JSON API has a constraint that all involved types must implement JsonSchema from the schemars crate in order to wire up autogeneration of JSON schema for API documentation and discoverability.

Implementation Details

schemars is added as an optional dependency. Implementations of JsonSchema for OrderedFloat<f32|f64> and NotNan<f32|f64> are provided behind feature flag gating. Both "std" and "schemars" features are required, as the schemars crate is firmly std-only.

The provided schema match the pre-existing serde implementations which serialize the underlying float value without any additional structure.

Relevant unit tests have been added as well.

@mbrubeck mbrubeck merged commit b08dc82 into reem:master May 3, 2021
mbrubeck added a commit that referenced this pull request May 3, 2021
Release notes:

* Add optional `schemars` feature (#78).
* Re-export the `Float` trait (#79).
@mbrubeck
Copy link
Collaborator

mbrubeck commented May 3, 2021

Thanks! Version 2.2.0 has been released with this feature.

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.

None yet

2 participants