-
Notifications
You must be signed in to change notification settings - Fork 12
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
[FIX] Fix client generation when custom header are defined #271
Conversation
Example of PR titles that include pivotal stories:
Generated by 🚫 dangerJS |
@@ -156,8 +166,12 @@ export const renderOperation = ( | |||
|
|||
const requestType = `r.I${capitalize(method)}ApiRequestType`; | |||
|
|||
const standardHeadersOnly = headers.filter(h => standardHeaders.includes(h)); |
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.
If I get it right, this strips off all non-standard headers. My concerns are this is done silently, so the user will never know about it. Am I right?
Which makes me think about... do we need this concept of "standard headers"? What's that for?
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.
If I get it right, this strips off all non-standard headers. My concerns are this is done silently, so the user will never know about it. Am I right?
You're right, but please notice that somehow it's already happening when the header is defined at method level.
You can see the openapi and the related snapshot.
Which makes me think about... do we need this concept of "standard headers"? What's that for?
Standard headers are the ones defined in @pagopa/ts-commons, but I don't know why this restriction was setup in the first place.
Maybe we can think about upgrading that type to a more inclusive one.
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.
What if we just accept any string, and let the "validation" to happen on the input specification? I mean: an invalid header should not be included in the spec in the first place.
Maybe @gunzip remembers the need for such a constraint.
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.
no as it was set up by @cloudify
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.
@gquadrati to summarize, what are the changes expected from this PR?
When... | Before | After |
---|---|---|
...a custom header is specified | Code is generated, but then fails to build | Code is generated but custom headers are removed silently |
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.
Yes, and actually there is another change:
When... | Before | After |
---|---|---|
...an optional header is specified | Code is generated, but then fails to build | Code is generated considering the header parameter as optional |
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.
@gquadrati about custom headers: I see there will be no real-life changes to actual users, still we're producing a result which silently ignores users' input. It's a red-flag for me as it may lead to very unexpected issues, I'd rather fail the code generation.
Anyway I'm fine with the proposed changes, too, so we can merge if you think it's ok. Whatever you decide, I advice to place a good comment on that very piece of code to explain why we're doing that.
Let's discuss the need for restrict which header a user can define on another PR. I see no value nowadays, we may decide is a useless constraint.
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.
I don't like the idea to make the generation fail as it's not a user problem, he has done everything right.
I don't like this solution neither, but I suppose changing @pagopa/ts-commons
types will require a bit of attention.
We can propose the user to put headers as method parameter and not path param, and just fix the optional header issue.
@balanza What do you think about it?
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.
I think we can merge code as is and then we think about remove the constraint on standard headers.
Rationale: users should be able to provide any OpenAPI spec as long as it's valid, it's not this module's responsibility to argue on what the user puts in the spec.
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.
fine for me.
Maybe this is no longer a need after #286 @gquadrati |
No more useful |
Description
Two different problems have been detected:
if an header parameter is optional, its generated name contains "?" at the end of the name, so the generated code does not compile
if an header parameter is defined at path level, generated code does not compile:
Example:
This because
IGetApiRequestType
from@pagopa/ts-commons
is defined aswhere
RequestHeaderKey
isSo we expect
KH
type to be a subset ofRequestHeaderKey
.The workaround is, just like what happen for method header parameters, to ignore headers other that the expected ones in request type definition.
Two failing tests have been added.
Motivation and Context
This PR is intended to fix issue #269
How Has This Been Tested?
pagopa-api-config-fe
project corrctly.Screenshots (if appropriate):
Types of changes
Checklist: