History

Merge pull request #17 from bam4564/codex/openapi-endpoint

Expose the control plane OpenAPI spec at /v1/openapi.json

Rhys Sullivan committed 8 months ago

Commit fba25112 parents 9034249 3d203fc2 files · +22 −1Browse files

Unified · Split

2 files
  1. apps/executor/src/server/server.test.ts +19 −0
  2. packages/server/src/index.ts +3 −1
apps/executor/src/server/server.test.ts+19−0
@@ -17,6 +17,7 @@ import { startMcpElicitationDemoServer } from "@executor/mcp-elicitation-demo"; · 16 unmodified lines
1717 import { makeToolInvokerFromTools, toTool } from "@executor/codemode-core";
1818 import {
1919 createControlPlaneClient,
20+ controlPlaneOpenApiSpec,
2021 type ControlPlaneClient,
2122 type ResolveExecutionEnvironment,
2223 SourceIdSchema,
@@ -601,6 +602,24 @@ const waitForExecutionCompletion = (input: { · 578 unmodified lines
601602 });
602603
603604 describe("local-executor-server", () => {
605+ it.scoped("serves the control-plane OpenAPI spec at /v1/openapi.json", () =>
606+ Effect.gen(function* () {
607+ const server = yield* makeServer;
608+ const response = yield* Effect.promise(() =>
609+ fetch(`${server.baseUrl}/v1/openapi.json`, {
610+ headers: {
611+ accept: "application/json",
612+ },
613+ }),
614+ );
615+ const spec = yield* Effect.promise(() => response.json());
616+
617+ expect(response.status).toBe(200);
618+ expect(response.headers.get("content-type")).toContain("application/json");
619+ expect(spec).toEqual(controlPlaneOpenApiSpec);
620+ }),
621+ );
622+
604623 it.scoped("serves the control-plane API and executes code", () =>
605624 Effect.gen(function* () {
606625 const server = yield* makeServer;
packages/server/src/index.ts+3−1
@@ -212,7 +212,9 @@ const createControlPlaneWebHandler = (runtime: SqlControlPlaneRuntime) => · 211 unmodified lines
212212 Effect.sync(() =>
213213 HttpApiBuilder.toWebHandler(
214214 Layer.merge(
215− createControlPlaneApiLayer(runtime.runtimeLayer),
215+ HttpApiBuilder.middlewareOpenApi({ path: "/v1/openapi.json" }).pipe(
216+ Layer.provideMerge(createControlPlaneApiLayer(runtime.runtimeLayer))
217+ ),
216218 HttpServer.layerContext,
217219 ),
218220 ),