-
Notifications
You must be signed in to change notification settings - Fork 0
✨ Infer HTTP success status code from openapi spec #50
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
base: main
Are you sure you want to change the base?
Conversation
| if (pathSpec[method]?.operationId) { | ||
| const operationResponses = pathSpec[method].responses ?? {} | ||
| const successStatus = | ||
| Object.keys(operationResponses).find(status => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: What about redirects (3xx)?
| if (operationId && !res.headersSent) { | ||
| const metadata = operationPaths[operationId] | ||
| if (metadata?.successStatus) { | ||
| res.status(metadata.successStatus) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: This will overwrite the status user set right?
Imagine having two possible success statuses for operation (200 and 2xx or 200 and 3xx) for example based on Accept header of the client request. If the dev sets the status before the async handler is called, this will overwrite it to 200.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I moved the status code assignment before we execute the operation handler, so anything set by user will overwrite it.
…ent the overwrite of explicit status code
PR addresses: