| 992 | * @category middleware |
| 993 | */ |
| 994 | export const middlewareOpenApi = ( |
| 995 | options?: { |
| 996 | readonly path?: HttpApiEndpoint.PathSegment | undefined |
| 997 | readonly additionalPropertiesStrategy?: OpenApi.AdditionalPropertiesStrategy | undefined |
| 998 | } | undefined |
| 999 | ): Layer.Layer<never, never, HttpApi.Api> => |
| 1000 | Router.use((router) => |
| 1001 | Effect.gen(function*() { |
| 1002 | const { api } = yield* HttpApi.Api |
| 1003 | const spec = OpenApi.fromApi(api, { |
| 1004 | additionalPropertiesStrategy: options?.additionalPropertiesStrategy |
| 1005 | }) |
| 1006 | const response = yield* HttpServerResponse.json(spec).pipe( |
| 1007 | Effect.orDie |
| 1008 | ) |
| 1009 | yield* router.get(options?.path ?? "/openapi.json", Effect.succeed(response)) |
| 1010 | }) |
| 1011 | ) |
| 1012 | |
| 1013 | const bearerLen = `Bearer `.length |
| 1014 | const basicLen = `Basic `.length |