[TypesScript] Models are sorted incorrectly in output
Created by: gbrown-ce
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.