Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically determine response status code from @oas.response decorator. #5149

Closed
mschnee opened this issue Apr 18, 2020 · 5 comments
Closed

Comments

@mschnee
Copy link
Contributor

mschnee commented Apr 18, 2020

Suggestion

The @oas.response convenience decorator lets us easily decorate controller methods .
However, as the developer, you are still responsible for setting the response code if you aren't going to return a default 200 status:

class MyController {
  @response(200, SuccessModel, AnotherSuccessModel)
  @response(409, MessageTooSmallModel)
  @get('/echo/{message}')
  public async echoMessage(
    @param.path.string('message') message?: string,
    @inject(RestBindings.Http.RESPONSE) res: Response
  ) {
    if (message.length < 15) {
      res.status(409)
      return new MessageTooSmallModel({message: 'minimum length is 15 characters'});      
    } else {
      return new SuccessModel({message});
    }
  }
}

While not necessarily inclusive of all possible response models, it is a safe assumption:

  • if the developer decorated a path method with @response(someCode, SomeModel, SomeOtherModel),
  • and the invocation of that path method responds with- or throws- an instance of SomeModel or SomeOtherModel,
  • then the developer intended to set the response status to be someCode

Questions

  • Where would this go?
  • Is this something that can be configured by adding an optional extension in a given RestApplication?
  • Is the best place for this lookup inside of the Sequence handler?
  • And if so, is the implementation a simple function that gets called on demand in the try/catch blocks of a sequence handler?

Acceptance Criteris

TBD

@dhmlau
Copy link
Member

dhmlau commented Apr 21, 2020

@jannyHou, could you please take a look? Thanks.

@mschnee
Copy link
Contributor Author

mschnee commented Apr 24, 2020

Additional thoughts- if a developer invokes res.status(), that should be authoritative, and nothing should change that.

@deepakrkris
Copy link
Contributor

moving to backlog, will assign target milestone in estimation meeting

@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.

@stale stale bot added the stale label Dec 25, 2020
@stale
Copy link

stale bot commented Jul 14, 2021

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

@stale stale bot closed this as completed Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants