swagger-api / swagger-api/swagger-codegen

[Typescript-node] Dumping models with subtypes causes stackoverflow

Open
#6,494 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript Feature: Composition / Inheritance
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with test.yaml using the documented swagger-codegen 2.2.3 command and the typescript-node generator with -DdebugModels=true. Trace the debug model-dumping path for the discriminator and allOf relationship; done means model dumping no longer overflows while normal template generation continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.