Swagger: Swagger (OpenAPI) spec not correctly generated for a route with 1 path parameter

Created on 15 Sep 2018  路  6Comments  路  Source: nestjs/swagger

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Swagger spec is not correctly generated for a route with 1 path parameter.

Expected behavior

Swagger UI should have a parameter description and input, instead it says No parameters.

Minimal reproduction of the problem with instructions

https://github.com/miikaah/nestjs-repro

Environment


Nest version: 5.1.0
@nestjs/swagger version: 2.5.1

next

Most helpful comment

Also facing the problems with generated spec.

"@nestjs/core": "5.7.3"
"@nestjs/swagger": "2.5.1"

Declaration:

    @Delete(':storeId')
    @ApiImplicitParam({ name: 'merchantId', type: String })
    @ApiImplicitParam({ name: 'storeId', type: String })
    async deleteStore(@Param(DefaultStoreByMerchantStoreIdPipe) defaultStore: DefaultStore): Promise<void> {
        await this.defaultStoreService.remove(defaultStore);
    }

Result:
image

Workaround (| any):

    @Delete(':storeId')
    @ApiImplicitParam({ name: 'merchantId', type: String })
    @ApiImplicitParam({ name: 'storeId', type: String })
    async deleteStore(@Param(DefaultStoreByMerchantStoreIdPipe) defaultStore: DefaultStore | any): Promise<void> {
        await this.defaultStoreService.remove(defaultStore);
    }

Result (which is expected):
image

It's reproducible only for @Delete action.

All 6 comments

Had the same problem, the solution is to add type on param.
This works:

@Delete('/:id')
async deleteById(@Param('id', new ParseIntPipe()) id: number) {
    return await this.projectOwnersService.deleteById(id);
}

This doesn't:

@Delete('/:id')
async deleteById(@Param('id', new ParseIntPipe()) id) {
    return await this.projectOwnersService.deleteById(id);
}

Also facing the problems with generated spec.

"@nestjs/core": "5.7.3"
"@nestjs/swagger": "2.5.1"

Declaration:

    @Delete(':storeId')
    @ApiImplicitParam({ name: 'merchantId', type: String })
    @ApiImplicitParam({ name: 'storeId', type: String })
    async deleteStore(@Param(DefaultStoreByMerchantStoreIdPipe) defaultStore: DefaultStore): Promise<void> {
        await this.defaultStoreService.remove(defaultStore);
    }

Result:
image

Workaround (| any):

    @Delete(':storeId')
    @ApiImplicitParam({ name: 'merchantId', type: String })
    @ApiImplicitParam({ name: 'storeId', type: String })
    async deleteStore(@Param(DefaultStoreByMerchantStoreIdPipe) defaultStore: DefaultStore | any): Promise<void> {
        await this.defaultStoreService.remove(defaultStore);
    }

Result (which is expected):
image

It's reproducible only for @Delete action.

the same

Fixed in the next version (to install run npm i @nestjs/swagger@next). Note: remember to update @nestjs/common, @nestjs/core and typescript as well to ensure that you're using the latest versions.

Steps to migrate: https://github.com/nestjs/swagger/pull/355#issuecomment-547925879

4.0.0 has been published

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mogusbi picture mogusbi  路  3Comments

djedlajn picture djedlajn  路  4Comments

vh13294 picture vh13294  路  4Comments

Fiorello picture Fiorello  路  5Comments

malbertSC picture malbertSC  路  5Comments