cyclosproject / ng-openapi-gen

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

Self-referencing object type with dots in Schema name results in build errors #86

Closed tommck closed 4 years ago

tommck commented 4 years ago

I tweaked a simple OpenAPI 3.0 spec (file attached) to rename "Pet" to "One.Two.Pet" and have that object contain a reference to itself:

components:
  schemas:
    One.Two.Pet:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
        pets:
          type: array
          items:
            $ref: "#/components/schemas/One.Two.Pet"

This results in this TS code (entire file):

/* tslint:disable */
export interface Pet {
  id: number;
  name: string;
  pets?: Array<OneTwoPet>;
  tag?: string;
}

the "OneTwoPet" does not exist. pets-with-pets.txt

tommck commented 4 years ago

Third time I'm filing an issue and it might actually be a real issue this time! ;)

tommck commented 4 years ago

If I can get time to do it, I can try to fix this, or at least create a failing unit test

luisfpg commented 4 years ago

Third time I'm filing an issue and it might actually be a real issue this time! ;)

Well, this time it is a bug indeed ;) Thanks for the PR. Will merge and tweak if needed.

tommck commented 4 years ago

The fix felt a bit awkward, so that's why I put the comment in there about it probably being in the wrong place.

tommck commented 4 years ago

@luisfpg This still seems to be a problem... here's another quick sample JSON file:

{
  "openapi": "3.0.1",
  "info": {
    "title": "Blah"
  },
  "paths": {},
  "components": {
    "schemas": {
      "Foo.Bar.Baz": {
        "required": [
          "description",
          "childDetails"
        ],
        "type": "object",
        "properties": {
          "description": {
            "type": "string"
          },
          "childDetails": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Foo.Bar.Baz"
            }
          }
        },
        "additionalProperties": false
      }
    }
  }
}

Output:

/* tslint:disable */
export interface Baz {
  childDetails: Array<FooBarBaz>;
  description: string;
}

:(

tommck commented 4 years ago

I'll open another issue