lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.33k stars 481 forks source link

Using `Omit` causes extra model to be output in OpenAPI file #1577

Closed sl33kr closed 3 months ago

sl33kr commented 4 months ago

When attempting to use the Omit utility type, tsoa generates an extra model into the swagger definition that isn't actually referenced anywhere.

We currently use all interfaces as the tsoa generated naming for Generics isn't compatible with AWS API Gateway. Unfortunately this included extra type breaks our deployment.

Sorting

Expected Behavior

Swagger file should generate with only referenced interfaces

openapi: 3.0.0
components:
    examples: {}
    headers: {}
    parameters: {}
    requestBodies: {}
    responses: {}
    schemas:
        InheritingModel:
            properties:
                key:
                    type: string
                value:
                    type: string
            required:
                - key
                - value
            type: object
            additionalProperties: false
    securitySchemes: {}
info:
    title: tsoa-example
    version: 1.0.0
    license:
        name: ISC
    contact: {}
paths:
    /example/omit:
        get:
            operationId: GetOmit
            responses:
                '200':
                    description: Ok
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/InheritingModel'
            security: []
            parameters: []
servers:
    -
        url: /

Current Behavior

An extra unreferenced type is included in the swagger docs.

openapi: 3.0.0
components:
    examples: {}
    headers: {}
    parameters: {}
    requestBodies: {}
    responses: {}
    schemas:
        Pick_BaseModel.Exclude_keyofBaseModel.index__:
            properties:
                key:
                    type: string
                value:
                    type: string
            required:
                - key
                - value
            type: object
            description: 'From T, pick a set of properties whose keys are in the union K'
        InheritingModel:
            properties:
                key:
                    type: string
                value:
                    type: string
            required:
                - key
                - value
            type: object
            additionalProperties: false
    securitySchemes: {}
info:
    title: tsoa-example
    version: 1.0.0
    license:
        name: ISC
    contact: {}
paths:
    /example/omit:
        get:
            operationId: GetOmit
            responses:
                '200':
                    description: Ok
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/InheritingModel'
            security: []
            parameters: []
servers:
    -
        url: /

Possible Solution

Looks like the workaround described in this feature request does appear to work here.

Steps to Reproduce

Repo with minimal repo steps https://github.com/sl33kr/tsoa-example

Note in that repo, that Pick does not have this issue.

Context (Environment)

Version of the library: > 6.0.0 Version of NodeJS: 18.19.1

WoH commented 4 months ago

Why is this a tsoa issue? The name is valid afaict

sl33kr commented 4 months ago

I expected Omit to behave the same as Pick when extended like in the example repo.

Is it possible to not output this model, given it's not being referenced by anything in the doc?

github-actions[bot] commented 3 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days