cyclosproject / ng-swagger-gen

A Swagger 2.0 codegen for Angular
MIT License
220 stars 100 forks source link

Bad model generation when using reference to another swagger file #258

Open martinduris opened 3 years ago

martinduris commented 3 years ago

Hi,

when i use in entity reference to entity defined in another swagger file: (child-api-doc.yaml:)

ChildEntity:
    type: object
    discriminator: 'className'
    properties:
      className:
        type: string
      childEntity:
        $ref: 'parent-api-doc.yaml#/definitions/ChildResponseResponse'
    required:
      - childEntity

and this referenced entity has definition: (parent-api-doc.yaml:)

ChildEntity:
    type: object
    properties:
      email:
        type: string
      vision:
        $ref: '#/definitions/Translation'
  ChildResponseResponse:
    allOf:
      - $ref: '#/definitions/ChildEntity'
      - type: object
        properties:
          id:
            type: integer
        required:
          - id
 ################################## TRANSLATIONS ##############################
  TranslationLanguage:
    type: string
    enum:
      - GB
      - SK
      - CS
  TranslationContent:
    type: object
    properties:
      language:
        $ref: '#/definitions/TranslationLanguage'
      content:
        type: string
    required:
      - language
      - content
  Translation:
    type: object
    properties:
      defaultLanguage:
        $ref: '#/definitions/TranslationLanguage'
      translations:
        type: array
        minItems: 1
        items:
          $ref: '#/definitions/TranslationContent'
    required:
        - defaultLanguage
        - translations

generated model 'ChildEntity' looks:

/* tslint:disable */
export interface ChildEntity {
  childEntity: {email?: string, vision?: {defaultLanguage: 'GB' | 'SK' | 'CS', translations: Array<{language: DefaultLanguage, content: string}>}} & {id: number};
  className?: string;
}

Problem is here:

translations: Array<{language: DefaultLanguage, content: string}>}}

Interface 'DefaultLanguage' is not existing/not generated (please notice, that "defaultLanguage: 'GB' | 'SK' | 'CS'" is looking good)


You can try example in this sample repo: https://github.com/martinduris/ng-swagger-gen-test ... just run npm run swagger

Thanks a lot Martin

luisfpg commented 3 years ago

Sorry, I don't really have any more time to maintain this project. Help is appreciated.