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

Function resolveSpecForInput

packages/plugins/openapi/src/sdk/plugin.ts:655–709  ·  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

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