question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nest 5.0.0-rc.2 Swagger example not correct generate parameters

See original GitHub issue

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 example not correct generate parameters

Expected behavior

parameters should generate correct.

Minimal reproduction of the problem with instructions

use example codes: https://github.com/nestjs/nest/tree/master/sample/11-swagger

What is the motivation / use case for changing the behavior?

Environment


Nest version: 5.0.0-rc.2

 
```
{
    "@nestjs/microservices": "^5.0.0-rc.2",
    "@nestjs/common": "^5.0.0-rc.2",
    "@nestjs/core": "^5.0.0-rc.2",
    "@nestjs/passport": "^1.0.6",
    "@nestjs/swagger": "^1.2.2",
    "@nestjs/testing": "^5.0.0-rc.2",
    "@nestjs/typeorm": "^2.0.0",
    "@nestjs/websockets": "^5.0.0-rc.2",
    "class-transformer": "^0.1.7",
    "class-validator": "^0.7.2",
    "reflect-metadata": "^0.1.12",
    "rxjs": "^6.0.0",
    "rxjs-compat": "^6.0.0",
    "typescript": "^2.8.0"
  }
```

For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
edevilcommented, Sep 11, 2018

@kamilmysliwiec I also have to specify ApiImplicitParam otherwise the params do not show up in the UI:

  @Get(':id/:id2')
  @ApiImplicitParam({ name: 'id2' })
  @ApiImplicitParam({ name: 'id' })
  findOne(@Param('id') id, @Param('id2') id2) {
    return `This action returns a #${id} cat #${id2}`;
  }

Is this expected? In addition, I installed nest (CLI) from scratch today and got these versions:

[System Information]
OS Version     : macOS High Sierra
NodeJS Version : v8.12.0
NPM Version    : 6.4.1
[Nest Information]
swagger version : 2.5.1
common version  : 5.1.0
core version    : 5.1.0

Isn’t 5.4.0 the latest Nest version?

6reactions
Thatkookooguycommented, May 8, 2019

@kamilmysliwiec @vellengs Not sure why this is happening, but from my investigation, you can fix this by adding a type of string to that function argument. for example:

This will NOT generate the swagger parameter:

  @Get('/raw/:username')
  getUser(@Param('username') username): string {
    return 'given user: ' + username;
  }

Screen Shot 2019-05-08 at 1 58 20 PM

But this WILL

  @Get('/raw/:username')
  getUser(@Param('username') username: string): string {
    return 'given user: ' + username;
  }

Screen Shot 2019-05-08 at 1 59 00 PM

the only difference is in this part: @Param('username') username: string where I set the username parameter to be a string.

Since most of the examples here didn’t include types for the function arguments, I thought I might share this because this might solve the problem in the meanwhile for people.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Describing Parameters - Swagger
In OpenAPI, a path parameter is defined using in: path . The parameter name must be the same as specified in the path....
Read more >
Adding Examples - Swagger
You can add examples to parameters, properties and objects to make OpenAPI specification of your web service clearer. Examples can be read by...
Read more >
Parameter Serialization - Swagger
explode (true/false) specifies whether arrays and objects should generate separate parameters for each array item or object property. OpenAPI serialization ...
Read more >
Describing Parameters - Swagger
OAS 2 This page applies to OpenAPI Specification ver. ... The location is determined by the parameter's in key, for example, in: query...
Read more >
Adding Examples - Swagger
OAS 2 This page applies to OpenAPI Specification ver. 2 (fka Swagger). ... Note: Do not confuse example values with the default values....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found