nestjs / swagger

OpenAPI (Swagger) module for Nest framework (node.js) :earth_americas:
https://nestjs.com
MIT License
1.66k stars 459 forks source link

CLI Plugin cannot generate descriptions for endpoint #2958

Open shaunhurryup opened 3 months ago

shaunhurryup commented 3 months ago

Is there an existing issue for this?

Current behavior

I try to use CLI Plugin to generate descriptions for properties and endpoints based on comments, only the property work

Core Code

class HelloQuery {
  /**
   * username description
   * @example shaun
   */
  name: string
  /**
   * age description
   * @example 35 
   */
  age?: number
}

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  /**
   * This is endpoint
   * @description This is endpoint description
   * @summary This is endpoint summary
   */
  @Get()
  // Must use following statement and work :(
  // @ApiOperation({ description: 'Endpint description created by `ApiOperation`' })
  getHello(@Query() query: HelloQuery): string {
    return this.appService.getHello();
  }
}

Output File

{
    "openapi": "3.0.0",
    "paths": {
        "/": {
            "get": {
                "operationId": "AppController_getHello",
                "parameters": [
                    {
                        "name": "name",
                        "required": true,
                        "in": "query",
                        "description": "username description",
                        "example": "shaun",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "age",
                        "required": false,
                        "in": "query",
                        "description": "age description",
                        "example": 35,
                        "schema": {
                            "type": "number"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": ""
                    }
                }
            }
        }
    },
    "info": {
        "title": "nestjs swagger bug resport service",
        "description": "This is description",
        "version": "1.0",
        "contact": {}
    },
    "tags": [],
    "servers": [],
    "components": {
        "schemas": {}
    }
}

Minimum reproduction code

https://github.com/shaunhurryup/nestjs-swagger-bug-report

Steps to reproduce

  1. yarn
  2. yarn start:dev

You can see demo.swagger.json in the root directory

Expected behavior

{
    "openapi": "3.0.0",
    "paths": {
        "/": {
            "get": {
                "operationId": "AppController_getHello",
+                "summary": "",
+                "description": "Endpint description created by `ApiOperation`",
                "parameters": [
                    {
                        "name": "name",
                        "required": true,
                        "in": "query",
                        "description": "username description",
                        "example": "shaun",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "age",
                        "required": false,
                        "in": "query",
                        "description": "age description",
                        "example": 35,
                        "schema": {
                            "type": "number"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": ""
                    }
                }
            }
        }
    },
    "info": {
        "title": "nestjs swagger bug resport service",
        "description": "This is description",
        "version": "1.0",
        "contact": {}
    },
    "tags": [],
    "servers": [],
    "components": {
        "schemas": {}
    }
}

Package version

7.3.1

NestJS version

9.4.3

Node.js version

v16.20.2

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 1 month ago

Would you like to create a PR for this issue?