OpenAPITools / OpenAPITools/openapi-generator

[BUG][typescript-axios] for allOf construct containing $ref and anonymous inlined schema, inlined schema type is not being generated

Open
#21,781 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Constructs like

    ExampleResponse:
      allOf:
        - $ref: '#/components/schemas/ExampleResponseBase'
        - type: object
          properties:
            attribute1:
              type: string
            attribute2:
              type: string

where allOf contains $ref AND inlined anonymous object schema, openapi generator does not generate type for anonymous object schema, resulting in having only referenced $ref schema in resulting parent type:

export type ExampleResponse = ExampleResponseBase;

Version 5.4.0 seems to properly generate ExampleResponseAllOf containing inlined schema attributes resulting in proper

export type ExampleResponse = ExampleResponseAllOf & ExampleResponseBase;
openapi-generator version

7.14.0

OpenAPI declaration file content or url

input-openapi.yaml

Generation Details

Using openapitools.json

{
  "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "7.14.0",
    "repository": {
      "downloadUrl": "https://nexus.app.slsp.sk/repository/public-slsp-maven-group/org/openapitools/openapi-generator-cli/7.14.0/openapi-generator-cli-7.14.0.jar"
    },
    "generators": {
      "example-api": {
        "generatorName": "typescript-axios",
        "output": "./generated",
        "glob": "./input-openapi.yaml",
        "additionalProperties": {
          "enumPropertyNaming": "original",
          "stringEnums": true,
          "supportsES6": "true",
          "withSeparateModelsAndApi": true,
          "modelPackage": "model",
          "apiPackage": "api"
        }
      }
    }
  }
}
Steps to reproduce

Run

npx openapi-generator-cli generate --generator-key example-api

(from folder where openapitools.json and input-openapi.yaml are)

Suggest a fix

Since it is valid schema, inlined anonymous object should have its own type generated.

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 input-openapi.yaml and the generator configuration in openapitools.json, then run npx openapi-generator-cli generate --generator-key example-api. Inspect the typescript-axios generation path for the allOf case combining a $ref with an inline object. Done means the generated ExampleResponse includes a type for the inline attributes and combines it with ExampleResponseBase as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.