Skip to content

HttpApi is discarding annotations from Union and Literal schemas #6245

@matheuspuel

Description

@matheuspuel

What version of Effect is running?

3.21.2

What steps can reproduce the bug?

import { HttpApi, HttpApiEndpoint, HttpApiGroup, OpenApi } from "@effect/platform"
import { Schema } from "effect"

const Api = HttpApi.make("Api").add(
  HttpApiGroup.make("group").add(
    HttpApiEndpoint.get("endpoint")`/`
      .addSuccess(Schema.Literal("a", "b").annotations({ title: "Letter" }))
  )
)

const spec = OpenApi.fromApi(Api)
console.dir(spec.paths["/"].get?.responses["200"].content?.["application/json"]?.schema, { depth: null })

What is the expected behavior?

Should log { type: 'string', enum: [ 'a', 'b' ], title: 'Letter' }, with the title annotation.

What do you see instead?

Logs { type: 'string', enum: [ 'a', 'b' ] }, without the title annotation.

Additional information

In the internal process of unifying ASTs of Union types, it is recreating the Union AST, therefore discarding its annotations.
It can cause problems like missing information in OpenApi specs and not respecting the encoding method and HTTP status declared as annotations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions