-
In a scenorio with AWS CloudFormation and inline REST API spec it is possible to do the following: openapi: 3.0.3
info:
version: 1.0.0
title: My API
paths:
/hello:
get:
operationId: sayHello
parameters:
- in: query
name: name
schema:
type: string
required: true
responses:
'200':
description: Successful response
content:
'application/json':
schema:
$ref: '#/components/schemas/SayHelloResponseContent'
'400':
description: Error response
content:
'application/json':
schema:
$ref: '#/components/schemas/ApiErrorResponseContent'
x-amazon-apigateway-integration:
contentHandling: CONVERT_TO_TEXT
credentials:
Fn::Sub: ${CacheReadS3Role.Arn} # Variable
httpMethod: GET
passthroughBehavior: when_no_match
responses:
default:
statusCode: 200
responseParameters:
method.response.header.Access-Control-Allow-Headers: "'Accept,Authorization,Content-Type,X-Amz-Date,X-Amz-Security-Token,X-Api-Key,X-Forwarded-For'"
method.response.header.Access-Control-Allow-Methods: "'GET,OPTIONS'"
method.response.header.Access-Control-Allow-Origin: "'*'"
method.response.header.Access-Control-Max-Age: "'600'"
4|5\d{2}:
statusCode: 500
responseParameters:
method.response.header.Access-Control-Allow-Headers: "'Accept,Authorization,Content-Type,X-Amz-Date,X-Amz-Security-Token,X-Api-Key,X-Forwarded-For'"
method.response.header.Access-Control-Allow-Methods: "'GET,OPTIONS'"
method.response.header.Access-Control-Allow-Origin: "'*'"
method.response.header.Access-Control-Max-Age: "'600'"
timeoutInMillis: 19000
type: aws
uri:
Fn::Sub: arn:${AWS::Partition}:apigateway:${AWS::Region}:s3:path/${CacheS3Bucket}/types/hello-types.json # Variable
components:
schemas:
ApiErrorResponseContent:
type: object
properties:
errorMessage:
type: string
required:
- errorMessage
SayHelloResponseContent:
type: object
properties:
message:
type: string
required:
- message As AWS integration is currently not supported the only way to achieve s3 integration is by writing the integration directly in the Open API spec file. Is there a way to fill variables in the file ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey! TypeSafeApi uses "Integrations" to construct the You can achieve the same as your above example by implementing a "custom integration" (see docs here). Essentially, you can extend the Hope that helps! Cheers, |
Beta Was this translation helpful? Give feedback.
Hey!
TypeSafeApi uses "Integrations" to construct the
x-amazon-apigateway-integration
part of the OpenAPI spec through CDK, rather than through variables in your template.You can achieve the same as your above example by implementing a "custom integration" (see docs here).
Essentially, you can extend the
Integration
class and implement therender
method to return thex-amazon-apigateway-integration
part of the spec for your specific integration. See here for howIntegrations.lambda
is implemented for a simple example, or here for a more complex example for a Network Load Balancer.Hope that helps!
Cheers,
Jack