MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / addSpec

Function addSpec

packages/plugins/openapi/src/sdk/plugin.ts:772–937  ·  view source on GitHub ↗
(config: OpenApiSpecConfig)

Source from the content-addressed store, hash-verified

770 });
771
772 const addSpec = (config: OpenApiSpecConfig) =>
773 Effect.gen(function* () {
774 // Resolve URL → text and parse BEFORE opening a transaction. Holding
775 // `BEGIN` across a network fetch is the Hyperdrive deadlock path.
776 const resolved = yield* resolveSpecForInput(config, httpClientLayer);
777 const compiled = resolved.keepPathItem
778 ? undefined
779 : yield* compileOpenApiSpec(resolved.specText);
780 const adapter = yield* resolveSpecFormatAdapter(
781 options?.specFormats ?? [],
782 config.specFormat,
783 );
784 const derivedIdentity =
785 adapter?.deriveIdentity && resolved.document
786 ? adapter.deriveIdentity(resolved.document)
787 : null;
788 const resolvedSlug = config.slug?.trim() || derivedIdentity?.slug;
789 if (!resolvedSlug) {
790 return yield* new OpenApiParseError({
791 message: "OpenAPI integration slug is required",
792 });
793 }
794
795 // Defaults the add page derives from its preview, applied here so
796 // headless callers (MCP, API) get the same integration the UI's
797 // add flow would produce - see e2e/scenarios/connect-handoff.test.ts:
798 // - effectiveBaseUrl: the spec's first server, used to anchor the
799 // derived auth template's absolute URLs. It is NOT stored as the
800 // connection baseUrl - the request host is resolved per call from
801 // the operation's extracted `servers`.
802 // - authenticationTemplate: the spec's declared security schemes
803 // (else the Add-connection modal is a dead "No authentication"
804 // end with nowhere to paste a credential)
805 // An explicit input always wins; for auth, an explicit EMPTY array
806 // means "no auth methods" and suppresses the derivation.
807 const explicitBaseUrl = config.baseUrl ?? resolved.baseUrl;
808 const needsDerivedBaseUrl = explicitBaseUrl == null;
809 const needsDerivedAuth = config.authenticationTemplate == null;
810 const preview =
811 needsDerivedBaseUrl || needsDerivedAuth
812 ? yield* previewSpecText(resolved.specText).pipe(
813 Effect.flatMap((rawPreview) =>
814 enrichPreviewWithDiscoveredOAuth({
815 specText: resolved.specText,
816 preview: rawPreview,
817 specUrl: resolved.specUrl ?? specInputToSpecUrl(config.spec),
818 baseUrl: explicitBaseUrl,
819 }),
820 ),
821 )
822 : undefined;
823 const derivedBaseUrl =
824 needsDerivedBaseUrl && preview ? firstBaseUrlForPreview(preview) : undefined;
825 const effectiveBaseUrl = explicitBaseUrl ?? (derivedBaseUrl || undefined);
826 const derivedAuthenticationTemplate =
827 needsDerivedAuth && preview
828 ? deriveAuthenticationTemplateFromPreview(preview, effectiveBaseUrl)
829 : undefined;

Callers

nothing calls this directly

Calls 13

compileOpenApiSpecFunction · 0.90
resolveSpecFormatAdapterFunction · 0.90
firstBaseUrlForPreviewFunction · 0.90
sha256HexFunction · 0.90
resolveSpecForInputFunction · 0.85
specInputToSpecUrlFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected