| 981 | * @category middleware |
| 982 | */ |
| 983 | export const middlewareOpenApi = ( |
| 984 | options?: { |
| 985 | readonly path?: HttpApiEndpoint.PathSegment | undefined |
| 986 | readonly additionalPropertiesStrategy?: OpenApi.AdditionalPropertiesStrategy | undefined |
| 987 | } | undefined |
| 988 | ): Layer.Layer<never, never, HttpApi.Api> => |
| 989 | Router.use((router) => |
| 990 | Effect.gen(function*() { |
| 991 | const { api } = yield* HttpApi.Api |
| 992 | const spec = OpenApi.fromApi(api, { |
| 993 | additionalPropertiesStrategy: options?.additionalPropertiesStrategy |
| 994 | }) |
| 995 | const response = yield* HttpServerResponse.json(spec).pipe( |
| 996 | Effect.orDie |
| 997 | ) |
| 998 | yield* router.get(options?.path ?? "/openapi.json", Effect.succeed(response)) |
| 999 | }) |
| 1000 | ) |
| 1001 | |
| 1002 | const bearerLen = `Bearer `.length |
| 1003 | const basicLen = `Basic `.length |