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

impl JsonSchema for serde_json::Value #33

Closed
ralpha opened this issue May 24, 2020 · 1 comment
Closed

impl JsonSchema for serde_json::Value #33

ralpha opened this issue May 24, 2020 · 1 comment

Comments

@ralpha
Copy link
Contributor

ralpha commented May 24, 2020

The current implementation for impl JsonSchema for Value where Value is serde_json::Value does not work well.
https://github.com/GREsau/schemars/blob/master/schemars/src/json_schema_impls/serdejson.rs

Because this is a very special type it might be tricky.
Currently when this value is included in a response it will not set a type.
When a description is given it will set that. But that is about it.
The 'value' variable is the serde_json::Value type in the screenshot below.
Screenshot from 2020-05-25 00-19-49
Because of this UI's have a hard time parsing this.
RapiDoc: (an okay response)
Screenshot from 2020-05-25 00-32-46
Swagger UI: (Does not even acknowledge it, but in schema it is better)
Screenshot from 2020-05-25 00-34-57
Screenshot from 2020-05-25 00-34-05

I know these are issues with UI's and not Schemars. And the Spec does not really give any option for this.
But maybe we can use "allOf", "oneOf", "anyOf" to allow all types ("integer", "number", "string" and "boolean"). This will make sure there is at least something good there.

@GREsau
Copy link
Owner

GREsau commented Jun 11, 2020

Schemars is doing the right thing here, as "type" is not a required property in JSON Schema or OpenAPI 3 Schema objects (as confirmed in OAI/OpenAPI-Specification#1657).

Swagger UI seems to handle this ok in my opinion - the property doesn't appear in the example, but this would be fixed by GREsau/okapi#11. And to be honest I don't think it's much better when we include all types in "anyOf":
image

I don't think these slightly odd behaviours in third-party UIs are enough to warrant adding workarounds in Schemars.

If you do want to include all types in an "anyOf" for any schemas without a "type", you can do this in your application by writing a Visitor (which I still need to document 😅) that applies this change to any typeless schemas

@GREsau GREsau closed this as completed Jun 11, 2020
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

No branches or pull requests

2 participants