samchon / nestia

NestJS Helper Libraries + TypeScript OpenAPI generator
https://nestia.io/
MIT License
1.81k stars 94 forks source link

Nestia swagger generates incorrect schema when using EncryptedRoute with @nestjs/cache-manager #864

Closed honguyenhaituan closed 5 months ago

honguyenhaituan commented 5 months ago

Summary

Nestia swagger generates incorrect schema when using EncryptedRoute with @nestjs/cache-manager

When I use cache interceptor in a controller like this

@EncryptedRoute.Get()
@UseInterceptors(CacheInterceptor)
async getGames(@TypedQuery() query: GetGamesQuery): Promise<GetGamesResponse> {}

the swagger generate not contain information about encrypted route:

"/api/games": {
    "get": {
        "tags": ["games"],
        "operationId": "getGames",
        "parameters": [
            {
                "name": "query",
                "in": "query",
                "schema": {
                    "$ref": "#/components/schemas/GetGamesQuery"
                },
                "description": "",
                "required": true
            }
        ],
        "responses": {
            "200": {
                "description": "",
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/GetGamesResponse"
                        }
                    }
                }
            }
        }
    }
},

but when I change the order of decorator like this every thing is ok

@UseInterceptors(CacheInterceptor)
@EncryptedRoute.Get()
async getGames(@TypedQuery() query: GetGamesQuery): Promise<GetGamesResponse> {}
"/api/games": {
    "get": {
        "tags": ["games"],
        "operationId": "getGames",
        "parameters": [
            {
                "name": "query",
                "in": "query",
                "schema": {
                    "$ref": "#/components/schemas/GetGamesQuery"
                },
                "description": "",
                "required": true
            }
        ],
        "responses": {
            "200": {
                "description": "## Warning\n\nResponse data have been encrypted.\n\nThe response body data would be encrypted as \"AES-128(256) / CBC mode / PKCS#5 Padding / Base64 Encoding\", through the [EncryptedRoute.G.et](https://github.com/samchon/@nestia/core#encryptedroute) component.\n\nTherefore, just utilize this swagger editor only for referencing. If you need to call the real API, using [SDK](https://github.com/samchon/nestia#software-development-kit) would be much better.",
                "content": {
                    "text/plain": {
                        "schema": {
                            "$ref": "#/components/schemas/GetGamesResponse"
                        }
                    }
                },
                "x-nestia-encrypted": true
            }
        }
    }
},
honguyenhaituan commented 5 months ago

I think it because this line https://github.com/samchon/nestia/blob/fbe753e45807c3a92d54957c4643bb8423c89352/packages/sdk/src/analyses/ReflectAnalyzer.ts#L222-L224

samchon commented 5 months ago

Good, I will patch it.