OpenAPITools / OpenAPITools/openapi-generator
[REQ] Add ability to not unalias schemas for OpenAPIGenerator and OpenAPIYamlGenerator
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.
Currently if you use OpenAPIGenerator or OpenAPIYamlGenerator the schemas are always unaliased. For example in the following fragment:
components:
schemas:
Category:
type: string
example: dogs
Pet:
type: object
properties:
name:
type: string
example: doggie
category:
"$ref": "#/components/schemas/Category"
Category will be unaliased in Pet and the result would be:
components:
schemas:
Category:
example: dogs
type: string
Pet:
example:
name: doggie
category: dogs
properties:
name:
example: doggie
type: string
category:
example: dogs
type: string
Although Category is indeed an alias for string and both fragments are equivalent, I would like to keep the reference as it serves as kind of documentation.
Describe the solution you'd like
It would be great to have configuration parameter that controls this behaviors. For example both classes may override Schema unaliasSchema(Schema schema):
@Override
public Schema unaliasSchema(Schema schema) {
return shouldUnaliasSchemas ? super.unaliasSchema(schema) : schema;
}
Describe alternatives you've considered
An alternative is to just subclass OpenAPIYamlGenerator but it would be more convenient if we have this functionality in the build-in generators.
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 OpenAPIGenerator and OpenAPIYamlGenerator, focusing on their unaliasSchema(Schema schema) entry points and how generator configuration is exposed. Trace where schema unaliasing is invoked and how both generators are configured. Done means users can control unaliasing while references such as Category remain references when disabled, with behavior covered by the relevant generator tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100