/
ExampleAPI.ts
42 lines (33 loc) · 1.49 KB
/
ExampleAPI.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import * as cdk from 'aws-cdk-lib'
import { Construct } from 'constructs'
import { OpenAPIRestAPI, OpenAPIVerifiers, OpenAPIBasicModels } from '@connected-web/openapi-rest-api'
import { ExampleResources } from './Resources'
import { StatusEndpoint } from './endpoints/Status/metadata'
import { ReceivePayloadEndpoint } from './endpoints/ReceivePayload/metadata'
export interface IdentityConfig {
verifiers: OpenAPIVerifiers
}
export interface StackParameters { hostedZoneDomain: string, serviceDataBucketName: string, identity: IdentityConfig }
export class ExampleAPIStack extends cdk.Stack {
constructor (scope: Construct, id: string, props: cdk.StackProps, config: StackParameters) {
super(scope, id, props)
// Create shared resources
const sharedResources = new ExampleResources(scope, this)
// Create API Gateway
const apiGateway = new OpenAPIRestAPI<ExampleResources>(this, 'Example API', {
Description: 'Example API - https://github.com/connected-web/openapi-rest-api',
SubDomain: 'example-api',
HostedZoneDomain: config.hostedZoneDomain,
Verifiers: config?.identity.verifiers ?? []
}, sharedResources)
// Kick of dependency injection for shared models and model factory
OpenAPIBasicModels.setup(this, apiGateway.restApi)
// Add endpoints to API
apiGateway
.addEndpoints({
'GET /status': new StatusEndpoint(),
'PUT /receive-payload/{pathParam}': new ReceivePayloadEndpoint(sharedResources)
})
.report()
}
}