Skip to content

Commit

Permalink
feat: support api cdk overrides (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
thantos authored Aug 24, 2023
1 parent 46ca77f commit 9e17a69
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/@eventual/aws-cdk/src/command-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Arn, Duration, Lazy, Stack } from "aws-cdk-lib/core";
import { Construct } from "constructs";
import type openapi from "openapi3-ts";
import { ApiDefinition } from "./constructs/http-api-definition.js";
import { SpecHttpApi } from "./constructs/spec-http-api";
import { SpecHttpApi, SpecHttpApiProps } from "./constructs/spec-http-api";
import type { EventService } from "./event-service";
import { grant } from "./grant";
import { EventualResource } from "./resource.js";
Expand All @@ -41,6 +41,8 @@ import type { TaskService } from "./task-service";
import { ServiceEntityProps, serviceFunctionArn } from "./utils";
import type { WorkflowService } from "./workflow-service";

export type ApiOverrides = Omit<SpecHttpApiProps, "apiDefinition">;

export type Commands<Service> = {
default: EventualResource;
} & ServiceEntityProps<Service, "Command", EventualResource>;
Expand Down Expand Up @@ -93,6 +95,7 @@ export interface CommandsProps<Service = any>
info: openapi.InfoObject;
};
overrides?: CommandProps<Service>;
apiOverrides?: ApiOverrides;
taskService: TaskService<Service>;
workflowService: WorkflowService;
}
Expand Down Expand Up @@ -201,6 +204,7 @@ export class CommandService<Service = any> {
// Service => Gateway
this.gateway = new SpecHttpApi(props.serviceScope, "Gateway", {
apiDefinition: ApiDefinition.fromInline(this.specification),
...props.apiOverrides,
});

this.gateway.node.addDependency(this.integrationRole);
Expand Down
8 changes: 6 additions & 2 deletions packages/@eventual/aws-cdk/src/constructs/spec-http-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export class SpecHttpApi extends HttpApiBase {
props.apiDefinition.bindAfterCreate(this, this);

const resource = new CfnApi(this, "Resource", {
name: props.apiName,
body: apiDefConfig.inlineDefinition ?? undefined,
bodyS3Location: apiDefConfig.inlineDefinition
? undefined
Expand Down Expand Up @@ -120,7 +119,12 @@ export class SpecHttpApi extends HttpApiBase {

export type SpecHttpApiProps = Omit<
HttpApiProps,
"corsPreflight" | "description"
| "corsPreflight"
| "description"
| "apiName"
| "defaultIntegration"
| "defaultAuthorizer"
| "defaultAuthorizationScopes"
> & {
/**
* An OpenAPI definition compatible with API Gateway.
Expand Down
3 changes: 3 additions & 0 deletions packages/@eventual/aws-cdk/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
} from "./bucket-service";
import { BuildOutput, buildServiceSync } from "./build";
import {
ApiOverrides,
CommandProps,
CommandService,
Commands,
Expand Down Expand Up @@ -150,6 +151,7 @@ export interface ServiceProps<Service = any> {
* Keep in mind that the output must be valid for APIGateway.
*/
openApi?: CommandsProps<Service>["openApi"];
api?: ApiOverrides;
/**
* Customize the configuration of the OpenSearch clusters and each of the OpenSearch Indices.
*/
Expand Down Expand Up @@ -429,6 +431,7 @@ export class Service<S = any> extends Construct {
cors: props.cors,
local: this.local,
openApi,
apiOverrides: props.api,
...workerConstructProps,
});
proxyCommandService._bind(this.commandService);
Expand Down

0 comments on commit 9e17a69

Please sign in to comment.