(
config: Pick<
OpenApiSpecConfig,
"spec" | "specFormat" | "specOverrides" | "headers" | "queryParams" | "baseUrl"
> & {
readonly authenticationTemplate?: readonly (Authentication | AuthenticationInput)[];
},
httpClientLayer: Layer.Layer<HttpClient.HttpClient, never, never>,
)
| 679 | }); |
| 680 | |
| 681 | const resolveSpecForInput = ( |
| 682 | config: Pick< |
| 683 | OpenApiSpecConfig, |
| 684 | "spec" | "specFormat" | "specOverrides" | "headers" | "queryParams" | "baseUrl" |
| 685 | > & { |
| 686 | readonly authenticationTemplate?: readonly (Authentication | AuthenticationInput)[]; |
| 687 | }, |
| 688 | httpClientLayer: Layer.Layer<HttpClient.HttpClient, never, never>, |
| 689 | ): Effect.Effect< |
| 690 | ResolvedSpec, |
| 691 | OpenApiParseError | OpenApiExtractionError | OpenApiOAuthError | OpenApiSpecOverrideError |
| 692 | > => |
| 693 | Effect.gen(function* () { |
| 694 | const adapter = yield* resolveSpecFormatAdapter( |
| 695 | options?.specFormats ?? [], |
| 696 | config.specFormat, |
| 697 | config.spec.kind === "url" ? config.spec.url : undefined, |
| 698 | ); |
| 699 | if (adapter) { |
| 700 | if (config.spec.kind !== "url") { |
| 701 | return yield* new OpenApiParseError({ |
| 702 | message: "Spec format adapters require a URL spec input", |
| 703 | }); |
| 704 | } |
| 705 | const resolved = yield* adapter.fetch({ |
| 706 | urls: [config.spec.url], |
| 707 | credentials: { |
| 708 | ...(config.headers ? { headers: config.headers } : {}), |
| 709 | ...(config.queryParams ? { queryParams: config.queryParams } : {}), |
| 710 | }, |
| 711 | ...(config.authenticationTemplate |
| 712 | ? { |
| 713 | consentScopes: config.authenticationTemplate.flatMap((template) => |
| 714 | "kind" in template && template.kind === "oauth2" ? template.scopes : [], |
| 715 | ), |
| 716 | } |
| 717 | : {}), |
| 718 | httpClientLayer, |
| 719 | }); |
| 720 | return yield* applyOverridesToResolvedSpec(resolved, config.specOverrides); |
| 721 | } |
| 722 | if (config.spec.kind === "url") { |
| 723 | const specText = yield* resolveSpecText(config.spec.url).pipe( |
| 724 | Effect.provide(httpClientLayer), |
| 725 | ); |
| 726 | return yield* applyOverridesToResolvedSpec( |
| 727 | { specText, specUrl: config.spec.url }, |
| 728 | config.specOverrides, |
| 729 | ); |
| 730 | } |
| 731 | return yield* applyOverridesToResolvedSpec( |
| 732 | { specText: config.spec.value }, |
| 733 | config.specOverrides, |
| 734 | ); |
| 735 | }); |
| 736 | |
| 737 | return { |
| 738 | id: "openapi" as const, |
no test coverage detected