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

Function resolveSpecForInput

packages/plugins/openapi/src/sdk/plugin.ts:648–701  ·  view source on GitHub ↗
(
    config: Pick<
      OpenApiSpecConfig,
      "spec" | "specFormat" | "specOverrides" | "headers" | "queryParams" | "baseUrl"
    > & {
      readonly authenticationTemplate?: readonly (Authentication | AuthenticationInput)[];
    },
    httpClientLayer: Layer.Layer<HttpClient.HttpClient, never, never>,
  )

Source from the content-addressed store, hash-verified

646 });
647
648 const resolveSpecForInput = (
649 config: Pick<
650 OpenApiSpecConfig,
651 "spec" | "specFormat" | "specOverrides" | "headers" | "queryParams" | "baseUrl"
652 > & {
653 readonly authenticationTemplate?: readonly (Authentication | AuthenticationInput)[];
654 },
655 httpClientLayer: Layer.Layer<HttpClient.HttpClient, never, never>,
656 ): Effect.Effect<
657 ResolvedSpec,
658 OpenApiParseError | OpenApiExtractionError | OpenApiOAuthError | OpenApiSpecOverrideError
659 > =>
660 Effect.gen(function* () {
661 const adapter = yield* resolveSpecFormatAdapter(
662 options?.specFormats ?? [],
663 config.specFormat,
664 );
665 if (adapter) {
666 if (config.spec.kind !== "url") {
667 return yield* new OpenApiParseError({
668 message: "Spec format adapters require a URL spec input",
669 });
670 }
671 const resolved = yield* adapter.fetch({
672 urls: [config.spec.url],
673 credentials: {
674 ...(config.headers ? { headers: config.headers } : {}),
675 ...(config.queryParams ? { queryParams: config.queryParams } : {}),
676 },
677 ...(config.authenticationTemplate
678 ? {
679 consentScopes: config.authenticationTemplate.flatMap((template) =>
680 "kind" in template && template.kind === "oauth2" ? template.scopes : [],
681 ),
682 }
683 : {}),
684 httpClientLayer,
685 });
686 return yield* applyOverridesToResolvedSpec(resolved, config.specOverrides);
687 }
688 if (config.spec.kind === "url") {
689 const specText = yield* resolveSpecText(config.spec.url).pipe(
690 Effect.provide(httpClientLayer),
691 );
692 return yield* applyOverridesToResolvedSpec(
693 { specText, specUrl: config.spec.url },
694 config.specOverrides,
695 );
696 }
697 return yield* applyOverridesToResolvedSpec(
698 { specText: config.spec.value },
699 config.specOverrides,
700 );
701 });
702
703 return {
704 id: "openapi" as const,

Callers 3

addSpecFunction · 0.85
updateSpecFunction · 0.85
plugin.tsFile · 0.85

Calls 3

resolveSpecFormatAdapterFunction · 0.90
resolveSpecTextFunction · 0.90
fetchMethod · 0.65

Tested by

no test coverage detected