swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.96k stars 6.04k forks source link

[Typescript-node] Dumping models with subtypes causes stackoverflow #6494

Open baronfel opened 7 years ago

baronfel commented 7 years ago
Description

Given a yaml definition that uses discriminators and allOf, I am unable to debug the models to work on templates.

Swagger-codegen version

2.2.3, from homebrew.

Swagger declaration file content or url
swagger: "2.0"
info:
  version: "1.0.0"
  title: Test Swagger Yaml

host: localhost:3001

definitions:
  List:
    required:
      - count
      - previous
      - next
    properties:
      count:
        type: integer
      previous:
        type: string
      next:
        type: string

  Location:
    discriminator: kind
    properties:
      kind:
        type: string
        enum:
        - Gps
        - Address
    required:
    - kind
  Gps:
    allOf:
    - $ref: '#/definitions/Location'
    - properties:
        lat:
          type: number
        lon:
          type: number
      required:
      - lat
      - lon
      example:
        lat: 35.00
        lon: 60.1234
        kind: Gps
  Address:
    allOf:
    - $ref: '#/definitions/Location'
    - properties:
        line1:
          type: string
        line2:
          type: string
        line3:
          type: string
        city:
          type: string
        stateOrProvince:
          type: string
        postalCode:
          type: string
        countryCode:
          type: string
          pattern: ([A-Z])+
          minLength: 3
          maxLength: 3
          description: The three-letter ISO country abbreviation.
      required:
      - line1
      - city
      - stateOrProvince
      - postalCode
      - countryCode
      example:
        line1: 1600 Pennsylvania NW
        city: Washington
        stateOrProvince: DC
        postalCode: 20500
        countryCode: USA

  LocationList:
    allOf:
    - $ref: '#/definitions/List'
    - type: object
      required:
        - results
      properties:
        results:
          type: array
          items:
            $ref : '#/definitions/Location'

paths:
  /locations:
    get:
      operationId: list locations
      description: list all locations
      responses:
        200:
          description: Location List
          schema:
            $ref: '#/definitions/LocationList'
Command line used for generation

java -DdebugModels=true -jar /usr/local/Cellar/swagger-codegen/2.2.3/libexec/swagger-codegen-cli.jar generate -i test.yaml -l typescript-node

Steps to reproduce

save the above spec as test.yaml and run the above command.

Related issues/PRs

None that I could find.

Suggest a fix/enhancement

This doesn't stop normal operation, so template generate works fine. It's just the debug code can't handle this relationship.

wing328 commented 7 years ago

I don't think TS node supports discriminator at the moment. Would you have time to contribute the enhancement? We can work with you on that.

cc @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx

kenisteward commented 7 years ago

@wing328 what's a discriminator? Also if we implement it, that would be nice to have in the base typescript generation instead of a particular client unless it is actually client based.

baronfel commented 7 years ago

@wing328 no, it does with just a couple tweaks to the template that my company plans on contributing back. Mainly around the serialization/deserializing functions, having them check for desired type based on the presence or absence of the discriminator property. This is working well for us right now for describing variant types, but specifically the debug view of the models blows up when discriminator is used.

wing328 commented 7 years ago

@kenisteward https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields-13