Effect CommunityEC
Effect Community8mo ago
5 replies
debaser

Workaround for Swagger Annotations with Union Types in HttpApi Module

Nativly, the HttpApi Module can't generate Swagger Annotations for Union types in specific scenarios

const customRoute = HttpApiEndpoint.get(
  "route",
  "/route",
)
  .addSuccess(Schema.Void, { status: 302 })
  .setUrlParams(
    Schema.Union( 
         Schema.Struct(
          {
            success: Schema.String,
            success_description: Schema.optional(Schema.String),
          }
        ),
         Schema.Struct({
            error: Schema.String,
            error_cause: Schema.String,
            error_additional_message: Schema.String
        }),
    )
  )

Is there some workaround, to get the urlParams displayed?
The typesystem of course just works fine,
When using structs, the generated swagger annotations do work
Could I somehow add information, so that swagger recognizes this as a "oneOf" Schema?
Is "oneOf" even a thing for path parameters?
Was this page helpful?