-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[WIP] feat(openapi-v2): add decorator for head op #862
Conversation
eabbeb2
to
c46ca1b
Compare
@slnode test please |
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.
Nice 👍
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.
lgtm 👍
df3cff6
to
d2dfd67
Compare
@slnode test please |
greet() { | ||
return 'Hello world!'; | ||
} | ||
greet() {} |
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.
@b-admike I am not quite familiar with these test cases, but I feel the spec for a function that has a return arg is different than the one that doesn't have a return...so I am not sure how the same openrationSpec
passes for both?
Maybe the code with your change is correct. It depends on does operationSpec
contains a response object.
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.
@jannyHou I think these tests are for asserting that the correct operation object is mapped to its corresponding controller method. Yeah I think the response object in operationSpec
is the same throughout the tests.
|
||
function givenAnOperationSpec() { | ||
return anOperationSpec() | ||
.withStringResponse() |
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.
hmm...I think if this helper function calls withStringResponse
then we probably could not omit the return
in those controller functions.
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.
Discussed this with Janny, but for posterity, we do not have any assertions in the tests for the response object or the actual response, and thus having a return statement with a string for the controller methods doesn't have any effect.
d2dfd67
to
353e448
Compare
@b-admike Can you explain why you removed all return values for |
@raymondfeng it's because we weren't using them in the tests and it increased our code coverage. See my discussion with Janny above. |
Tests are examples for some developers to learn and follow. I would rather not sacrifice them for artificial coverage numbers. It's better to use |
I mainly got rid of them because I thought they didn't serve any purpose. The coverage increase was just a bonus :). But I don't mind reverting those changes and using the ignore comments. |
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.
+1 on Raymond's comment, otherwise LGTM
@b-admike It does serve some purposes to show the usage of our decorators and when they apply. For example, |
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.
Please revert the changes on greet
and use /* istanbul ignore next*/
to ignore such sections if desired. I'm fine to let the coverage tool complain for these cases.
Great addition!! Just thinking about this from a developer perspective though ... declaring an additional @Head() with a function seems like extra work. Can this decorator be nested on a function doing the @get() call but make the function just return the headers. Or perhaps we should consider a way to mark a GET route as HEAD enabled ... or we just enable it by default for all GET requests and the decorator allows header values to be set? I'm ok with the changes. Asking this question more for the purposes of discussion before any changes are made. Reference for purpose of HEAD request: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD |
@virkt25 Those are good points. I'm up for finding alternatives to this approach! Not sure how to implement what you've suggested though. |
4990415
to
93c1e92
Compare
93c1e92
to
2cc856a
Compare
I think it might be better from a performance standpoint to not execute the GET function at all rather than to remove the response body. Unnecessary delay in response to HEAD + additional hits against DB. But we should be able to set the content-type header (json / xml / whatever) for the expected response. And for files (if static handler will be using the same router) ... we should be able to return the Content-Length header and type header appropriately as well. |
Without invoking the get, head won’t have the same list of response headers. |
I was just wondering if we may be able to avoid that overhead by letting users optionally specify the headers they want to pass along for a
|
openapi-v2 is now removed. |
Add sugar function for head operation.
Connect to #691
Checklist
npm test
passes on your machinepackages/cli
were updated (N/A?)packages/example-*
were updated (N/A?)