History

[codex] Clean up OpenAPI add source API (#843)

* Clean up OpenAPI add source API * Update OpenAPI add source credential UI * Address OpenAPI add source PR feedback * Document OpenAPI credential configuration plan * Fix OpenAPI add flow CI

Rhys Sullivan committed 6 months ago

Commit 529a54f1 parent 1d16b0b20 files · +1477 −467Browse files

Showing the changes to packages/plugins/openapi/src/testing (1 of 20 files). Show all

Unified · Split

packages/plugins/openapi/src/testing/index.ts+52−26
@@ -13,7 +13,7 @@ import { · 12 unmodified lines
1313 OpenApi,
1414 } from "effect/unstable/httpapi";
1515 import { OAuthTestServer, serveTestHttpServerLayer } from "@executor-js/sdk/testing";
16−import { isToolResult, type ScopeId } from "@executor-js/sdk/core";
16+import { isToolResult } from "@executor-js/sdk/core";
1717 import type { OpenApiPluginExtension, OpenApiSpecConfig } from "../sdk/plugin";
1818
1919 export class OpenApiTestServerAddressError extends Data.TaggedError(
@@ -80,22 +80,45 @@ export interface OpenApiEchoTestServerShape extends OpenApiTestServerShape { · 60 unmodified lines
8080 readonly clearRequests: Effect.Effect<void>;
8181 }
8282
83−export type OpenApiTestSourceOptions = Omit<OpenApiSpecConfig, "spec" | "baseUrl"> & {
83+export type OpenApiTestSourceOptions = Omit<
84+ OpenApiSpecConfig,
85+ "spec" | "baseUrl" | "name" | "namespace"
86+> & {
8487 readonly baseUrl?: string | null;
88+ readonly name?: string;
89+ readonly namespace?: string;
8590 };
8691
87−export type OpenApiHttpApiTestSourceOptions = Omit<OpenApiSpecConfig, "spec"> & {
92+export type OpenApiHttpApiTestSourceOptions = Omit<
93+ OpenApiSpecConfig,
94+ "spec" | "name" | "namespace" | "baseUrl"
95+> & {
96+ readonly name?: string;
97+ readonly namespace?: string;
98+ readonly baseUrl?: string | null;
8899 readonly specBaseUrl?: string;
89100 readonly transformSpec?: (spec: Record<string, unknown>) => Record<string, unknown>;
90101 };
91102
103+type OpenApiHttpApiAddSpecCredentialInput =
104+ | string
105+ | {
106+ readonly kind: "secret";
107+ readonly prefix?: string;
108+ };
109+
110+type OpenApiHttpApiAddSpecCredentialsInput = {
111+ readonly headers?: Record<string, OpenApiHttpApiAddSpecCredentialInput>;
112+ readonly queryParams?: Record<string, OpenApiHttpApiAddSpecCredentialInput>;
113+};
114+
92115 export type OpenApiHttpApiTestAddSpecPayloadOptions = Omit<
93116 OpenApiHttpApiTestSourceOptions,
94− "scope" | "credentialTargetScope"
95−> & {
96− readonly targetScope: ScopeId;
97− readonly credentialTargetScope?: ScopeId;
98−};
117+ "scope" | "headers" | "queryParams" | "specFetchCredentials"
118+> &
119+ OpenApiHttpApiAddSpecCredentialsInput & {
120+ readonly specFetchCredentials?: OpenApiHttpApiAddSpecCredentialsInput;
121+ };
99122
100123 export type OpenApiTestSourceExecutor = {
101124 readonly openapi: Pick<OpenApiPluginExtension, "addSpec">;
@@ -125,9 +148,11 @@ export const makeOpenApiTestSourceConfig = ( · 23 unmodified lines
125148 const { baseUrl, ...rest } = options;
126149 return {
127150 ...rest,
128− spec: server.specJson,
151+ spec: { kind: "blob", value: server.specJson },
152+ name: rest.name ?? "Test API",
153+ namespace: rest.namespace ?? "test_api",
129154 ...(baseUrl === null ? {} : { baseUrl: baseUrl ?? server.baseUrl }),
130− };
155+ } as OpenApiSpecConfig;
131156 };
132157
133158 export const addOpenApiTestSource = (
@@ -140,11 +165,17 @@ export const makeOpenApiHttpApiTestSourceConfig = ( · 6 unmodified lines
140165 api: HttpApi.Any,
141166 options: OpenApiHttpApiTestSourceOptions,
142167 ): OpenApiSpecConfig => {
143− const { specBaseUrl, transformSpec, ...config } = options;
168+ const { baseUrl, specBaseUrl, transformSpec, ...config } = options;
144169 return {
145170 ...config,
146− spec: makeOpenApiTestSpecJson(api, { baseUrl: specBaseUrl, transformSpec }),
147− };
171+ spec: {
172+ kind: "blob",
173+ value: makeOpenApiTestSpecJson(api, { baseUrl: specBaseUrl, transformSpec }),
174+ },
175+ name: config.name ?? "Test API",
176+ namespace: config.namespace ?? "test_api",
177+ ...(baseUrl === null ? {} : { baseUrl: baseUrl ?? specBaseUrl ?? "https://api.example.test" }),
178+ } as OpenApiSpecConfig;
148179 };
149180
150181 export const addOpenApiHttpApiTestSource = (
@@ -157,26 +188,21 @@ export const makeOpenApiHttpApiTestAddSpecPayload = ( · 6 unmodified lines
157188 api: HttpApi.Any,
158189 options: OpenApiHttpApiTestAddSpecPayloadOptions,
159190 ) => {
160− const { targetScope, credentialTargetScope, ...sourceOptions } = options;
191+ const { ...sourceOptions } = options;
161192 const config = makeOpenApiHttpApiTestSourceConfig(api, {
162193 ...sourceOptions,
163− scope: String(targetScope),
164− ...(credentialTargetScope !== undefined
165− ? { credentialTargetScope: String(credentialTargetScope) }
166− : {}),
194+ scope: "unused-http-helper-scope",
167195 });
168196 return {
169− targetScope,
170197 spec: config.spec,
171198 namespace: config.namespace,
172− ...(config.name !== undefined ? { name: config.name } : {}),
173− ...(config.baseUrl !== undefined ? { baseUrl: config.baseUrl } : {}),
174− ...(config.headers !== undefined ? { headers: config.headers } : {}),
175− ...(config.queryParams !== undefined ? { queryParams: config.queryParams } : {}),
199+ name: config.name,
200+ baseUrl: config.baseUrl,
201+ ...(sourceOptions.headers !== undefined ? { headers: sourceOptions.headers } : {}),
202+ ...(sourceOptions.queryParams !== undefined ? { queryParams: sourceOptions.queryParams } : {}),
176203 ...(config.oauth2 !== undefined ? { oauth2: config.oauth2 } : {}),
177− ...(credentialTargetScope !== undefined ? { credentialTargetScope } : {}),
178− ...(config.specFetchCredentials !== undefined
179− ? { specFetchCredentials: config.specFetchCredentials }
204+ ...(sourceOptions.specFetchCredentials !== undefined
205+ ? { specFetchCredentials: sourceOptions.specFetchCredentials }
180206 : {}),
181207 };
182208 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t