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

Function addSpec

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

Source from the content-addressed store, hash-verified

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