Skip to content

bug - regenerating TS from YAML Swagger/OpenAPI file results an unstable output #1668

@nirzafran

Description

@nirzafran

in the case where a Swagger/OpenAPI YAML file has several endpoints with the same suffix, the swagger-typescript-api library results with an unstable output when re-running it.

Starting from point 0 of a YAML file (see attached), try running on the file couple of times to see it "flip-flop", see screenshot below for demonstration:

npx --yes swagger-typescript-api generate -p ./scripts/repro-swagger-bug.yaml -o ./scripts/generated -n client.ts --single-http-client --extract-request-params --extract-request-body --extract-response-body --extract-response-error --extract-enums --sort-types --sort-routes --clean-output

Image

see the YAML file below:

openapi: 3.0.3
info:
  title: swagger-typescript-api non-deterministic suffix repro
  version: "1.0"
paths:
  /findings/exports:
    get:
      tags: [Findings]
      summary: List finding exports
      parameters:
        - { name: offset, in: query, schema: { type: integer } }
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ListExportsResponse"
  /assets/exports:
    get:
      tags: [Assets]
      summary: List asset exports
      parameters:
        - { name: offset, in: query, schema: { type: integer } }
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ListExportsResponse"
  /remediation/exports:
    get:
      tags: [Remediation]
      summary: List remediation exports
      parameters:
        - { name: offset, in: query, schema: { type: integer } }
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ListExportsResponse"
  /exports:
    get:
      tags: [Exports]
      summary: List all exports
      parameters:
        - { name: offset, in: query, schema: { type: integer } }
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ListExportsResponse"
components:
  schemas:
    ListExportsResponse:
      type: object
      properties:
        items:
          type: array
          items:
            type: object
            properties:
              id: { type: string }
              status: { type: string }

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions