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