OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.33k stars 6.46k forks source link

[BUG] Circular Reference when name conflict occurs #19263

Open dhon opened 1 month ago

dhon commented 1 month ago
Description

An object model will create as a circular reference to itself if the name is a combination of the parent object and the field. image

In the YAML code below, if you change the property in the HelloWorld schema to anything other than 'test' it will generate correctly. It seems like it is occurring because the two schemas are fighting over the same name, where the reference generation always wins and the original schema file is never created.

openapi-generator version

version: 7.7.0 openapi-generator-cli: 2.13.4 generatorName: typescript-angular ngVersion: 16.2.12

OpenAPI declaration file content or url
---
x-generator: NSwag v14.0.0.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))
openapi: 3.0.0
info:
  title: Circular Reference Test
  version: 1.0.0
servers:
- url: https://google.com/
paths:
  "/GetHelloWorld":
    get:
      responses:
        '200':
          description: Description
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/HelloWorld"
components:
  schemas:
    HelloWorld:
      type: object
      properties:
        test:
          oneOf:
          - "$ref": "#/components/schemas/HelloWorldTest"
    HelloWorldTest:
      type: string
      x-enumNames:
      - Hello
      - World
      enum:
      - Hello
      - World
Generation Details
{
  "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "7.7.0",
    "generators": {
      "test": {
        "generatorName": "typescript-angular",
        "inputSpec": "swagger.yml",
        "logToStderr": false,
        "output": "#{cwd}/src/app/api",
        "additionalProperties": {
          "modelPropertyNaming": "camelCase",
          "ngVersion": "16.2.12"
        }
      }
    }
  }
}
Steps to reproduce

openapi-generator-cli generate -c ./openapitools.json --generator-key test

Related issues/PRs

I believe this is the same issue mentioned here that was resolved and later reverted, but may be mistaken. https://github.com/OpenAPITools/openapi-generator/issues/13709

Suggest a fix

No suggestions, sorry.

dhon commented 1 month ago

@devhl-labs Figured I'd throw a mention your way just for informational purposes, since it seems related to the issue you raised and resolved that I have linked in the ticket.

devhl-labs commented 1 month ago

Oh interesting, i thought the problem was fixed which is why i reverted my hotfix. If it wasn't fixed beyond my c# only hotfix then imy issue shouldn't have been closed.

devhl-labs commented 1 month ago

I checked again and somehow I don't see this problem anymore.