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.

[Feature Request] Multiple response with the same status code

See original GitHub issue

I’m submitting a…


[ ] Regression 
[ ] Bug report
[x] 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 only allows one response per status code, but sometimes we have more than one response body.

Expected behavior

We can work around this in the decorator by:

  • Changing the status field type from number to number | string
  • Checking if the status already exists
  • If it exists, we add a space to the response code

Minimal reproduction of the problem

@ApiForbiddenResponse({ type: UnauthorizedTokenException })
@ApiForbiddenResponse({ type: InsufficientRolesException })

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

I have more than one error response with different Dto classes using the same status code.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:31
  • Comments:21 (7 by maintainers)

github_iconTop GitHub Comments

27reactions
ziadalzarkacommented, May 19, 2019

Any updates?

8reactions
fwoelffelcommented, Aug 5, 2020

@fwoelffel Yes, I tried. However, refs require function array type and my UserOrerInfoDto is Class type, so type error occured. 스크린샷 2020-08-05 16 57 50

Could you share your UserOrderInfoDto implementation? Make sure it is a class and not an interface.


EDIT: Ok, I’m sorry I didn’t realize this earlier. Your DTOs should not be wrapped in an array:

@ApiOkResponse({
  schema: {
    anyOf: refs(
      UserOrderInfoDto
    ),
  },
})

Sorry for misleading you. 😞

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger; specify two responses with same code based on ...
OpenAPI 3.x. In OAS3 you can use oneOf to define multiple possible request bodies or response bodies for the same operation: openapi: ...
Read more >
Parsing Multiple responses inside the response xml. - Help
I have a job with multiple invoices listed under the job. I send a request and it shows all the multiple invoices and...
Read more >
Swagger responses - Multiple response codes with t...
Hi! Is it possible to have multiple codes use the same schema without duplicating the schema-reference? I.e.: responses: '202': description: ...
Read more >
Describing Responses - Swagger
HTTP Status Codes · responses: · 200: · description: OK · 400: · description: Bad request. User ID must be an integer and...
Read more >
Define multiple responses for each route - Mockoon
For each route, multiple responses can be defined (status, body, and headers) and triggered using a set of rules. There is always at...
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