-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
Internally tagged enums won't generate semantically correct schema #358
Comments
After some further investigation I found the root of the problem: Therefore, the generated schema is correct but it's not semantically what one would expect as the When using I see the following potential solutions:
I'm new to JSON schemas so there is a good chance I missed something but I have the feeling using the |
I don't believe that's correct - my understanding is that the correct validation result is the combination of the "local" keywords and the $ref target keywords. What are you using the process/consume the output schema? Perhaps the validation tool you're using doesn't support the latest version (draft 2020-12) of JSON schema? If that's the case, you can configure schemars to output schemas in an older format, e.g. let settings = SchemaSettings::draft07();
let generator = settings.into_generator();
let schema = generator.into_root_schema_for::<MySchema>(); |
You're absolutely right. I wrongly assumed a maintained yaml language server would support the 2020-12 draft as of now but I was wrong. I tested the schema using the vscode and zed language servers. After a bit of research I found out that I was using the yaml-language-server developed by RedHat in both editors. As it turns out this language server does not support drafts newer than draft 7 which explains why the schema didn't work in both editors. Thanks for the quick reply and sorry for the troubles |
When creating an enum of structs which are internally tagged (e.g. "type" as tag) the generated schema only suggests the type property and not the properties of the structs themselves.
I used the following minimal code example to reproduce the issue:
main.rs
Cargo.toml
Output schema.json
As far as I understand JSON schemas I come to the conclusion that the error lies in these parts:
When I replace this with
The schema works as expected. Therefore, I would suggest wrapping those references in an
allOf
block.Thanks a lot for this crate. It is very useful for defining JSON schemas for configuration files etc. for rust projects :)
The text was updated successfully, but these errors were encountered: