wing
wing copied to clipboard
api path: collision with /{proxy+}
I tried this:
A minimal example:
bring cloud;
let api = new cloud.Api();
api.get("/:id", inflight (req) => {
let id = req.vars.get("id");
return {
body: "id: {id}",
status: 200,
};
});
This happened:
It compiles, but fails when I try to apply the tf files:
Error: creating API Gateway REST API (hjnq3g5xqd) specification: BadRequestException: Errors found during import:
│ Unable to create resource at path '/{proxy+}': A sibling ({id}) of this resource already has a variable path part -- only one is allowed
│ Additionally, these warnings were found:
│ Parse issue: attribute info is missing
│ Required "info" property is missing from the document root.
│
│ with aws_api_gateway_rest_api.cloudApi_api_2B334D75,
│ on main.tf.json line 72, in resource.aws_api_gateway_rest_api.cloudApi_api_2B334D75:
│ 72: }
I expected this:
API route in /:id
.
Is there a workaround?
No response
Anything else?
Here is the JSON the program generated:
{
"openapi": "3.0.3",
"paths": {
"/{id}": {
"get": {
"operationId": "get-:id",
"responses": {
"200": {
"description": "200 response",
"content": {}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"x-amazon-apigateway-integration": {
"uri": "arn:aws:apigateway:${data.aws_region.Region.name}:lambda:path/2015-03-31/functions/${aws_lambda_function.cloudApi_get_id_0_456E8BD7.arn}/invocations",
"type": "aws_proxy",
"httpMethod": "POST",
"responses": {
"default": {
"statusCode": "200"
}
},
"passthroughBehavior": "when_no_match",
"contentHandling": "CONVERT_TO_TEXT"
}
}
},
"/{proxy+}": {
"x-amazon-apigateway-any-method": {
"produces": [
"application/json"
],
"x-amazon-apigateway-integration": {
"type": "mock",
"requestTemplates": {
"application/json": "\n {\"statusCode\": 404}\n "
},
"passthroughBehavior": "never",
"responses": {
"404": {
"statusCode": "404",
"responseParameters": {
"method.response.header.Content-Type": "'application/json'"
},
"responseTemplates": {
"application/json": "{\"statusCode\": 404, \"message\": \"Error: Resource not found\"}"
}
},
"default": {
"statusCode": "404",
"responseParameters": {
"method.response.header.Content-Type": "'application/json'"
},
"responseTemplates": {
"application/json": "{\"statusCode\": 404, \"message\": \"Error: Resource not found\"}"
}
}
}
},
"responses": {
"404": {
"description": "404 response",
"headers": {
"Content-Type": {
"type": "string"
}
}
}
}
}
}
}
}
The compiler always adds the "/{proxy+}" part and this causes a conflict with the variable that the user chooses.
I think the problem is in this line:
https://github.com/winglang/wing/blob/693ee4b3a995a9c305479b32c10e0a87013ff125/libs/wingsdk/src/target-tf-aws/api.ts#L325
It should be:
const defaultResponse = props.cors ? API_CORS_DEFAULT_RESPONSE(props.cors) : {};
Wing Version
0.51.16
Node.js Version
v21.2.0
Platform(s)
MacOS
Community Notes
- Please vote by adding a 👍 reaction to the issue to help us prioritize.
- If you are interested to work on this issue, please leave a comment.