OpenAPITools / OpenAPITools/openapi-generator
[REQ] detect circular refs in models / detect if container contains models
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
If a schemas has a property with a ref, which references the current schema in a circle (or loop/cycle), generators in some languages (e.g. C++) might have problems with finding the classes referenced.
Example:
Store -> Pet -> Person -> Store
Store references Pet directly and Person indirectly as Person references Store again.
Pet references Person directly and Store indirectly as Store references Pet again.
Person references Store directly and Pet indirectly as Pet references Person again.
Arrays of primitives usually need to be handled differently than arrays of objects, a flag which indicates the latter could come in handy.
Describe the solution you'd like
Add a member to CodegenModel which stores all circular referenced schemas.
Add a member flag to CodegenProperty which is true if an array schema consists of object schema items.
Additional context
I'm currently trying to improve the cpp-restbed codegen and found the need to forward declare classes in the template.
While trying to make the server work "out-of-the-box" I've encountered the problem that there seems no possibility in the template to differentiate containers of primitives or containers of objects.
Already creating a PR for this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with CodegenModel and CodegenProperty, then trace how schema references and array item schemas are represented in the generator core. Done means circularly referenced schemas can be exposed on CodegenModel and object-item arrays can be distinguished on CodegenProperty, including the Store/Pet/Person case described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, java, openapi
- Domain
- backend-api-design, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100