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

Function addSpec

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

Source from the content-addressed store, hash-verified

697 });
698
699 const addSpec = (config: OpenApiSpecConfig) =>
700 Effect.gen(function* () {
701 // Resolve URL → text and parse BEFORE opening a transaction. Holding
702 // `BEGIN` across a network fetch is the Hyperdrive deadlock path.
703 const resolved = yield* resolveSpecForInput(config, httpClientLayer);
704 const compiled = resolved.keepPathItem
705 ? undefined
706 : yield* compileOpenApiSpec(resolved.specText);
707 const adapter = yield* resolveSpecFormatAdapter(
708 options?.specFormats ?? [],
709 config.specFormat,
710 );
711 const derivedIdentity =
712 adapter?.deriveIdentity && resolved.document
713 ? adapter.deriveIdentity(resolved.document)
714 : null;
715 const resolvedSlug = config.slug?.trim() || derivedIdentity?.slug;
716 if (!resolvedSlug) {
717 return yield* new OpenApiParseError({
718 message: "OpenAPI integration slug is required",
719 });
720 }
721
722 // Defaults the add page derives from its preview, applied here so
723 // headless callers (MCP, API) get the same integration the UI's
724 // add flow would produce - see e2e/scenarios/connect-handoff.test.ts:
725 // - effectiveBaseUrl: the spec's first server, used to anchor the
726 // derived auth template's absolute URLs. It is NOT stored as the
727 // connection baseUrl - the request host is resolved per call from
728 // the operation's extracted `servers`.
729 // - authenticationTemplate: the spec's declared security schemes
730 // (else the Add-connection modal is a dead "No authentication"
731 // end with nowhere to paste a credential)
732 // An explicit input always wins; for auth, an explicit EMPTY array
733 // means "no auth methods" and suppresses the derivation.
734 const explicitBaseUrl = config.baseUrl ?? resolved.baseUrl;
735 const needsDerivedBaseUrl = explicitBaseUrl == null;
736 const needsDerivedAuth = config.authenticationTemplate == null;
737 const preview =
738 needsDerivedBaseUrl || needsDerivedAuth
739 ? yield* previewSpecText(resolved.specText).pipe(
740 Effect.flatMap((rawPreview) =>
741 enrichPreviewWithDiscoveredOAuth({
742 specText: resolved.specText,
743 preview: rawPreview,
744 specUrl: resolved.specUrl ?? specInputToSpecUrl(config.spec),
745 baseUrl: explicitBaseUrl,
746 }),
747 ),
748 )
749 : undefined;
750 const derivedBaseUrl =
751 needsDerivedBaseUrl && preview ? firstBaseUrlForPreview(preview) : undefined;
752 const effectiveBaseUrl = explicitBaseUrl ?? (derivedBaseUrl || undefined);
753 const derivedAuthenticationTemplate =
754 needsDerivedAuth && preview
755 ? deriveAuthenticationTemplateFromPreview(preview, effectiveBaseUrl)
756 : 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