cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
397 stars 132 forks source link

Unqualified name clash #309

Open juneidy opened 10 months ago

juneidy commented 10 months ago

An example schema:

{
  "openapi": "3.0.1",
  "info": {
    "title": "Blah",
    "version": "1"
  },
  "paths": {},
  "components": {
    "schemas": {
      "Clazz": {
        "type": "object",
        "properties": {
          "parentProps": {
            "type": "string"
          }
        }
      },
      "Foo.Bar.Baz.Clazz": {
        "allOf": [{ "$ref": "#/components/schemas/Clazz" }, {
          "type": "object",
          "required": [
            "arrayProperty"
          ],
          "properties": {
            "refProperty": {
              "$ref": "#/components/schemas/Foo.Bar.Baz.Clazz"
            },
            "arrayProperty": {
              "type": "array",
              "items": {
                "$ref": "#/components/schemas/Foo.Bar.Baz.Clazz"
              }
            },
            "objectProperty": {
              "type": "object",
              "required": [
                "nestedArray",
                "nestedRef"
              ],
              "properties": {
                "nestedArray": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Foo.Bar.Baz.Clazz"
                  }
                },
                "nestedRef": {
                  "$ref": "#/components/schemas/Foo.Bar.Baz.Clazz"
                }
              }
            }
          }
        }]
      }
    }
  }
}

Produces wrong typescript:

import { Clazz } from '../../../../models/clazz';
export type Clazz = Clazz & {
'refProperty'?: Clazz;
'arrayProperty': Array<Clazz>;
'objectProperty'?: {
'nestedArray': Array<Clazz>;
'nestedRef': Clazz;
};
};

I think the only way to do this is to always use qualified name, so it will look roughly like:

import { Clazz } from '../../../../models/clazz';
export type FooBarBazClazz = Clazz & {
'refProperty'?: FooBarBazClazz;
'arrayProperty': Array<FooBarBazClazz>;
'objectProperty'?: {
'nestedArray': Array<FooBarBazClazz>;
'nestedRef': FooBarBazClazz;
};
};

Thoughts?

juneidy commented 10 months ago

FYI: I've made a workaround https://github.com/juneidy/ng-openapi-gen/tree/unqualified-bug

Let me know if there's any improvement you have in mind.