Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noop filter needed when I want to merge jsonSchema annotation, not replace #3951

Open
ryskajakub opened this issue Nov 15, 2024 · 0 comments
Labels
bug Something isn't working platform

Comments

@ryskajakub
Copy link
Contributor

What version of Effect is running?

"@effect/platform": "^0.69.24"

What steps can reproduce the bug?

add a schema to a handler in http platform

  const s1 = Schema.Union(Schema.Struct({ _tag: Schema.Literal('s1') }), Schema.Struct({ _tag: Schema.Literal('s2') }));

  const s1Annotated = s1.annotations({
    jsonSchema: {
      discriminator: {
        propertyName: '_tag',
      },
    },
  });

use in a api:

HttpApiGroup.make('resource')
  .add(
    HttpApiEndpoint.put('myResource', '/res')
      .setPayload(s1Annotated)

generate swagger docs:

const HttpLive = HttpApiBuilder.serve(errorLogger).pipe(
  Layer.provide(HttpApiSwagger.layer()),

then extract the openapi definition from the generated docs and inspect it

What is the expected behavior?

add the discriminator clause to the part describing the data structure like this

          anyOf:
            - $ref: '#/components/schemas/S1'
            - $ref: '#/components/schemas/S2'
          discriminator:
            propertyName: _tag

What do you see instead?

only the discriminator clause, without the anyOf clause

          discriminator:
            propertyName: _tag

Additional information

this can actually be fixed by adding noop filter to the data structure and attaching the jsonSchema to it.

  return union.pipe(Schema.filter((x) => true)).annotations({
    jsonSchema: {
      discriminator: {
        propertyName: '_tag',
        mapping,
      },
    },
  });

this is because the jsonSchema annotation is handled differently for the refinements
https://github.com/Effect-TS/effect/blame/c8d20b0827a30e95a0fe192113e82b72c8bfb5cd/packages/platform/src/OpenApiJsonSchema.ts#L350

@ryskajakub ryskajakub added the bug Something isn't working label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working platform
Projects
None yet
Development

No branches or pull requests

2 participants