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

Why are the schemas different for ToParamSchema UUID and ToSchema UUID #94

Open
sir4ur0n opened this issue Mar 28, 2024 · 0 comments
Open

Comments

@sir4ur0n
Copy link

sir4ur0n commented Mar 28, 2024

Hello,

While writing manual OpenApi instances for a phantom type wrapping UUID today, I noticed that (undeclare (declareNamedSchema (Proxy @UUID)))._namedSchemaSchema /= toParamSchema (Proxy @UUID), which I find surprising (not just for UUID but for any type).

instance ToParamSchema UUID where
  toParamSchema _ = mempty
    & type_ ?~ OpenApiString
    & format ?~ "uuid"

instance ToSchema UUID.UUID where
  declareNamedSchema p = pure $ named "UUID" $ paramSchemaToSchema p
    & example ?~ toJSON (UUID.toText UUID.nil)

Is there a reason why the example is only for ToSchema and not for ToParamSchema?
That looks like a bug to me.

I would expect the implementation to be

instance ToParamSchema UUID where
  toParamSchema _ = mempty
    & type_ ?~ OpenApiString
    & format ?~ "uuid"
    & example ?~ toJSON (UUID.toText UUID.nil)

instance ToSchema UUID.UUID where
  declareNamedSchema p = pure $ named "UUID" $ paramSchemaToSchema p

More generally, is there a scenario where (undeclare (declareNamedSchema (Proxy @a)))._namedSchemaSchema /= toParamSchema (Proxy @a) makes sense for any type a?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant