1import type * as agw2 from "@distilled.cloud/aws/apigatewayv2";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { Api } from "./Api.ts";
5
6/**
7 * Request options for {@link ExportApi}. `ApiId` is resolved from the
8 * bound {@link Api}; `Specification` defaults to `OAS30` (the only
9 * supported value — exports are OpenAPI 3.0, HTTP APIs only).
10 */
11export interface ExportApiRequest extends Partial<
12 Omit<agw2.ExportApiRequest, "ApiId">
13> {}
14
15/**
16 * Runtime binding for exporting an HTTP API's OpenAPI 3.0 definition
17 * (`apigateway:GET` on `/apis/{apiId}/exports/{specification}`).
18 *
19 * Bind an {@link Api} inside a function runtime to serve or snapshot the
20 * live API definition — e.g. publishing your own `/openapi.json` route or
21 * diffing deployed routes against the source of truth. The response
22 * `body` is a byte `Stream` of the JSON (or YAML) document. Provide
23 * `ApiGatewayV2.ExportApiHttp` on the Function effect to implement the
24 * binding.
25 *
26 * ### Exporting API definitions
27 * **Example:** Serve the live OpenAPI document
28 * ```typescript
29 * // init
30 * const exportApi = yield* ApiGatewayV2.ExportApi(api);
31 *
32 * // runtime
33 * const exported = yield* exportApi({ OutputType: "JSON" });
34 * const document = yield* Stream.mkString(Stream.decodeText(exported.body!));
35 * ```
36 *
37 * @binding
38 */
39export interface ExportApi extends Binding.Service<
40 ExportApi,
41 "AWS.ApiGatewayV2.ExportApi",
42 <A extends Api>(
43 api: A,
44 ) => Effect.Effect<
45 (
46 request?: ExportApiRequest,
47 ) => Effect.Effect<agw2.ExportApiResponse, agw2.ExportApiError>
48 >
49> {}
50export const ExportApi = Binding.Service<ExportApi>(
51 "AWS.ApiGatewayV2.ExportApi",
52);