Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypesScript] Models are sorted incorrectly in output #350

Closed
gbrown-ce opened this issue Jun 19, 2018 · 2 comments
Closed

[TypesScript] Models are sorted incorrectly in output #350

gbrown-ce opened this issue Jun 19, 2018 · 2 comments

Comments

@gbrown-ce
Copy link
Contributor

gbrown-ce commented Jun 19, 2018

Description

When generating the client, the model classes in the resulting api.ts file are sorted alphabetically. In many cases this is fine and doesn't matter. The problem comes in when you are using inheritance. In TypeScript you cannot put an inherited class before its parent. If for instance you have a parent "Section" and a child "ButtonSection", this will cause the Typescript compilation to fail since the child comes before the parent alphabetically.

openapi-generator version

3.0.2

OpenAPI declaration file content or url
swagger: "2.0"
info:
  version: "1.0.0"
  title: Sections Service
basePath: /
# 
schemes:
  - http
consumes:
  - application/json
produces:
  - application/json
paths:
  /sections:
    x-swagger-router-controller: sections
    get:
      description: Retrieves sections
      operationId: getSections
      parameters:
        - name: skip
          in: query
          description: Number of items to skip
          required: false
          type: integer
          format: int64
          default: 0
          minimum: 0
        - name: take
          in: query
          description: Number of items to return
          required: false
          type: integer
          format: int64
          default: 20
          minimum: 1
          maximum: 100
      responses:
        200:
          description: Success
          headers:
            X-Total-Count:
              description: Total number of sections
              type: integer
              format: int64
              minimum: 0
          schema:
            type: array
            items:
              $ref: "#/definitions/Section"
  /swagger:
    x-swagger-pipe: swagger_raw
definitions:
  Section:
    type: object
    discriminator: type
    required:
      - name
      - type
    properties:
      name:
        type: string
      type:
        type: string
        enum:
          - ButtonSection
  ButtonSection:
    type: object
    allOf:
      - $ref: '#/definitions/Section'
      - type: object
        required:
          - buttons
        properties:
          buttons:
            type: array
            items:
              $ref: '#/definitions/Button'
  Button:
    type: object
    required:
      - index
      - label
    properties:
      index:
        type: integer
        format: int64
        minimum: 0
      label:
        type: string
Command line used for generation

docker run -d --rm -v $WORKSPACE:/input:ro -v $WORKSPACE/output:/output openapitools/openapi-generator-cli generate -i /input/swagger.yaml -g typescript-node -o /output

Steps to reproduce

Run the above command on reference file

Suggest a fix/enhancement

The CodeGen needs to sort models based on their inheritance tree before outputting. Another solution could be breaking the output out into multiple different files instead of one massive file.

@macjohnny
Copy link
Member

@gbrown-ce has this issue been resolved with your PR #363 ?

@gbrown-ce
Copy link
Contributor Author

@macjohnny yes it has!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants