MCPcopy Create free account
hub / github.com/Effect-TS/effect / middlewareOpenApi

Function middlewareOpenApi

packages/platform/src/HttpApiBuilder.ts:994–1011  ·  view source on GitHub ↗
(
  options?: {
    readonly path?: HttpApiEndpoint.PathSegment | undefined
    readonly additionalPropertiesStrategy?: OpenApi.AdditionalPropertiesStrategy | undefined
  } | undefined
)

Source from the content-addressed store, hash-verified

992 * @category middleware
993 */
994export 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
1013const bearerLen = `Bearer `.length
1014const basicLen = `Basic `.length

Callers

nothing calls this directly

Calls 3

pipeMethod · 0.65
getMethod · 0.65
jsonMethod · 0.45

Tested by

no test coverage detected