-
-
Notifications
You must be signed in to change notification settings - Fork 233
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
Schemars overwrites declarations if there are structs with the same name #62
Comments
Note that turning on inlining is a possible workaround. This may make the schema more verbose though. https://docs.rs/schemars/0.8.0/schemars/gen/struct.SchemaSettings.html#structfield.inline_subschemas |
I have found and successfully used a workaround: Using |
This is a tricky one - schemars somewhat naively treats the I've considered trying to find a better way to do it that properly differentiates types with the same name. Perhaps we could use |
Currently, the suggestions from @NeoLegends and @pashadia are the best way to work around this. However, I can think of two potential ways we could fix this, both rely on adding a new attribute: Option 1:
|
A possible alternative fix would be to just treat A simple implementation of the unique ID would be to concatenate the the type's module path with the friendly name, although we'd need to be careful re generic types, e.g. ensure that |
… with the json schema. Previously if two config structs had the same name they would be resolved to the same definition. GREsau/schemars#62
* Separate out apollo plugins from general plugins section. * Enable inline subschemas to prevent name clashes from causeing issues with the json schema. Previously if two config structs had the same name they would be resolved to the same definition. GREsau/schemars#62 * Rename plugins to user_plugins. Now we have `apollo_plugins` and `user_plugins` * Move logic around defaulting and ordering to configuration. Reporting comes first, rhai comes last. * Fix tests. We can't enable the reporting plugin for unit testing, so check to see if the global subscriber is set before adding it. * Changelog Clippy * Test fixes * Review fixes Co-authored-by: bryn <bryn@apollographql.com>
This is finally fixed in v0.8.14 😄 |
generates the following, invalid schema:
This is because there are two member structs with the same name, although they sit at different paths. This use case occurs in our systems because some (more top-level modules) export their own
Config
structs which we then aggregate into one, global config for which we want to generate a schema for.Is this expected behavior? What can we do to fix this? Would it make sense to extend schemars with support for this use case? It could automatically incorporate, e. g. the parent module name / the module path into the name of the definitions, such that these clashes can be avoided.
The text was updated successfully, but these errors were encountered: