-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(apigateway): add methodresponse support #1572
feat(apigateway): add methodresponse support #1572
Conversation
efc8afd
to
ed930fe
Compare
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.
Thanks for the pull! I have reservations about shipping this without support for Models.
/** | ||
* The method response's status code, which you map to an IntegrationResponse. | ||
*/ | ||
responseModels?: { [destination: string]: string }; |
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 we're going to implement L2 support for method responses, I think we should also support Model, since the value of each key here should be a reference to https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-model.html
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.
Agreed.
}, | ||
responseModels: { | ||
'application/json': 'Empty', | ||
'text/plain': 'Empty' |
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.
Do you have a use-case where you'll be hard-coding the model names or creating them as part of your stack?
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. My current use-case is just using the default Empty model. Maybe this is worth at least adding an IModel
interface, as @RomainMuller mentioned below, and perhaps having some default Empty implementation.
responseParameters?: { [destination: string]: boolean }; | ||
|
||
/** | ||
* The method response's status code, which you map to an IntegrationResponse. |
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.
This is a mapping of content type to model name, not the status code.
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.
Totally grabbed the wrong description from the docs 😛 Will fix that.
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 agree with @sam-goodwin, it would be awesome if we can push this a little further and have basic support for models, at least to the point the APIs here can be reasonably expected not to change once we make a more comprehensive L2 support for model definition. Maybe it's just a matter of introducing an IModel
interface and passing this instead of the model names...
Working on getting base level support for referencing an |
If I may make a suggestion, a default class of |
That'll work. I was probably overcomplicating the association to the RestAPI in my head, and thinking I should deal with that. But, it sounds like that's not necessary. |
b3d24c1
to
ddcb89f
Compare
I've added a start at models, with |
@RomainMuller and/or @sam-goodwin, any chance you guys have some time to look at the updates on this? |
@@ -34,11 +35,15 @@ export interface MethodOptions { | |||
*/ | |||
apiKeyRequired?: boolean; | |||
|
|||
/** | |||
* The responses that can be sent to the client who calls the method. | |||
*/ |
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.
Add a "@default" clause and describe the behavior if this is not defined
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.
Sure. I can add that. I'll also look at doing the same for the properties of the MethodResponse
type itself.
assigning to @sam-goodwin |
be86fed
to
1cf909e
Compare
@sam-goodwin, I've augmented the documentation around MethodResponse, as per @eladb's ask. |
readonly modelId: string; | ||
} | ||
|
||
export class EmptyModel implements IModel { |
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 add docs and provide a link to official documentation describing the keywords 'Empty' and 'Error'.
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've added some documentation around both the Empty and Error models. As far as reference links, I was able to find some mention in the official docs for the Empty model, but not specifically the Error model (outside of mentioning that Empty and Error are available by default). Are you aware of a page in the documentation that addresses the Error model in any further detail?
6ac7b17
to
c9a77f5
Compare
public readonly modelId = 'Error'; | ||
} | ||
|
||
// TODO: Implement Model, enabling management of custom models. |
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.
Update README roadmap section
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'm adding an issue to track the lack of support for API gateway models, and will quote that in the api-gateway readme.
responseParameters: { | ||
'method.response.header.errthing': true | ||
}, | ||
responseModels: { |
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 am wondering if a bunch of static properties on Model to make it “enum-like” would make a nicer and more discoverable API here: “Model.Empty” and “Model.Error”
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 explored adding static properties to a stubbed Model class, but I get an error that the build wants me to have Model implement cdk.Construct
, so I backed away for now. Perhaps there's a way to get the build to temporarily ignore that requirement?
Remove Dockerfile that was no longer needed Update python base image from 3.6 to 3.6.5 Make the dockerfile work Add MethodResponse support for aws-apigateway Remove Dockerfile that was no longer needed Update python base image from 3.6 to 3.6.5 Make the dockerfile work Add MethodResponse to API Gateway Method. Add some documentation to the MethodResponse properties. Update the test for MethodResponse with response models. Fix some formatting and finish adding code documentation for MethodResponse. Remove Dockerfile from this branch Fix bad merge to methodresponse test. Correct the MethodResponse response models documentation. Add IModel type to reference when configuring a MethodResponse Slight update to comments. Update API Gateway MethodResponse documentation. Author: John Shaskin <[email protected]> Date: Mon Feb 05 5:30:45 2019 +0100 Add some documentation around the referencing default Empty/Error models. Edit documentation around the referencing default Empty/Error models. Edit documentation around the referencing default Empty/Error models. Fix 'trailing whitespace' in comments Add roadmap section with item for adding support for API gateway models
c9a77f5
to
624bda3
Compare
@eladb, is there anything else pending on this PR to get it merged? |
Add MethodResponse type and the ability to add one or more method responses, when creating an API gateway REST API method.
Pull Request Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.