Skip to content

Schemas with the same name, but not used in the same NinjaAPI, get a counter suffix in OpenAPI spec #51

@maxhollmann

Description

@maxhollmann

Is your feature request related to a problem? Please describe.
When there are two separate schema classes with the same name, one of them will end up being called TheSchema2 in the openapi.json, even if they're not used in the same NinjaAPI. This is because SchemaFactory is a singleton, tracks a global schema_names and generates unique names over all schemas it has created in _get_unique_name.

We have separate APIs in the same codebase for different user groups. Some models are available in both, but with different fields available, so naturally for a SomeModel we'd have two SomeModelSchemas, one for each API. Right now we have to prefix them with the API they're used in to avoid the 2 being added to one of them effectively randomly.

Describe the solution you'd like
A clear and concise description of what you want to happen.

Don't proactively generate names for schemas, instead only generate them once they're needed, i.e. on schema generation. There it would be possible to check whether two different schemas have the same name that are actually used in that specific NinjaAPI, and only then add a counter to the name (or ideally add a flag to NinjaAPI to allow raising an error in that case).

This would be the ideal solution in my eyes, but might require a major refactoring. There may be other more pragmatic ways, would have to look into it more.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions