@@ -85,6 +85,15 @@ export class Deprecated extends Context.Tag("@effect/platform/OpenApi/Deprecated
8585 */
8686export class Override extends Context . Tag ( "@effect/platform/OpenApi/Override" ) < Override , Record < string , unknown > > ( ) { }
8787
88+ /**
89+ * Transforms the generated OpenAPI specification
90+ * @since 1.0.0
91+ * @category annotations
92+ */
93+ export class Transform
94+ extends Context . Tag ( "@effect/platform/OpenApi/Transform" ) < Transform , ( openApiSpec : OpenAPISpec ) => OpenAPISpec > ( )
95+ { }
96+
8897const contextPartial = < Tags extends Record < string , Context . Tag < any , any > > > ( tags : Tags ) : (
8998 options : {
9099 readonly [ K in keyof Tags ] ?: Context . Tag . Service < Tags [ K ] > | undefined
@@ -118,6 +127,10 @@ export const annotations: (
118127 readonly servers ?: ReadonlyArray < OpenAPISpecServer > | undefined
119128 readonly format ?: string | undefined
120129 readonly override ?: Record < string , unknown > | undefined
130+ /**
131+ * Transforms the generated OpenAPI specification
132+ */
133+ readonly transform ?: ( ( openApiSpec : OpenAPISpec ) => OpenAPISpec ) | undefined
121134 }
122135) => Context . Context < never > = contextPartial ( {
123136 identifier : Identifier ,
@@ -129,7 +142,8 @@ export const annotations: (
129142 externalDocs : ExternalDocs ,
130143 servers : Servers ,
131144 format : Format ,
132- override : Override
145+ override : Override ,
146+ transform : Transform
133147} )
134148
135149const apiCache = globalValue ( "@effect/platform/OpenApi/apiCache" , ( ) => new WeakMap < HttpApi . HttpApi . Any , OpenAPISpec > ( ) )
@@ -144,7 +158,7 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
144158 }
145159 const api = self as unknown as HttpApi . HttpApi . AnyWithProps
146160 const jsonSchemaDefs : Record < string , JsonSchema . JsonSchema > = { }
147- const spec : DeepMutable < OpenAPISpec > = {
161+ let spec : DeepMutable < OpenAPISpec > = {
148162 openapi : "3.0.3" ,
149163 info : {
150164 title : Context . getOrElse ( api . annotations , Title , ( ) => "Api" ) ,
@@ -359,6 +373,10 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
359373 }
360374 } )
361375
376+ Option . map ( Context . getOption ( api . annotations , Transform ) , ( transformFn ) => {
377+ spec = transformFn ( spec )
378+ } )
379+
362380 apiCache . set ( self , spec )
363381
364382 return spec
0 commit comments