OpenAPITools / OpenAPITools/openapi-generator

[REQ] Add ability to not unalias schemas for OpenAPIGenerator and OpenAPIYamlGenerator

Open
#15,591 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.