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

Types with same name overrides schemas in components #1

Open
Flowneee opened this issue Feb 15, 2023 · 1 comment
Open

Types with same name overrides schemas in components #1

Flowneee opened this issue Feb 15, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Flowneee
Copy link
Owner

Flowneee commented Feb 15, 2023

If there is 2 or more types with same name, they will override each other, when schema generated. For example

handler1.rs

#[derive(JsonSchema)]
struct Request {
    name: String
}

handler2.rs

#[derive(JsonSchema)]
struct Request {
    id: u64
}

will create only one definition in #/components/schema, and handlers from both files wil reference same schema.

First potenial fix - enable inlining in https://docs.rs/schemars/latest/schemars/gen/struct.SchemaSettings.html#structfield.inline_subschemas, which will solve most problems (probably everything sxcept recursive types).

@Flowneee Flowneee added the bug Something isn't working label Feb 15, 2023
@Flowneee
Copy link
Owner Author

Proper solution could be adding some attribute to schemars macro JsonSchema, which will make type non-referenceable, like

#[derive(JsonSchema)]
#[schemars(referenceable = false)]
struct Request { ... }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant