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

Regression - OpenAPIGen breaks with String output examples #2789

Open
russwyte opened this issue Apr 21, 2024 · 5 comments
Open

Regression - OpenAPIGen breaks with String output examples #2789

russwyte opened this issue Apr 21, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@russwyte
Copy link
Contributor

Describe the bug
A recent PR #2714 seems to have broken OpenAPIGen when providing output examples for simple String output.

To Reproduce

        val endpoint = Endpoint(Method.GET / "simple/api/v1.0")
          .out[String]
          .examplesOut("a" -> "hello", "b" -> "world")
        val json     = toJsonAst(OpenAPIGen.fromEndpoints("String Endpoint", "1.0", endpoint))

Expected behaviour
This seems to be a regression - it worked before and I would expect it to work.

Screenshots
image

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@russwyte russwyte added the bug Something isn't working label Apr 21, 2024
@russwyte
Copy link
Contributor Author

If I add an explicit outCodec it seems to work - but this should not be required for a simple string.

        val endpoint = Endpoint(Method.GET / "simple/api/v1.0")
          .outCodec[String](HttpCodec.content(MediaType.text.plain))
          .examplesOut("a" -> "hello", "b" -> "world")

@987Nabil
Copy link
Contributor

I can only assume one default value for the MediaType. And that is Json. We support text plain and protobuf by default as well. But OpenAPI picks Json first. You have to support the explicit MediaType, if you want to only support that one type.
But, this should imho not break the examples.

@russwyte
Copy link
Contributor Author

That sounds sensible - but as you say - even if the MediaType is application/json those examples should be valid - and in fact they are handled without error up until the breaking commit.

@csgero
Copy link

csgero commented May 29, 2024

I have the same issue with a scala 3 enum return value. It worked before RC7, but now it causes a similar exception:

java.lang.ClassCastException: class scala.util.Left cannot be cast to class com.ekata.emailInterpreter.domain.EmailAddressParseResult (scala.util.Left and com.ekata.emailInterpreter.domain.EmailAddressParseResult are in unnamed module of loader 'app')

It looks like the example value gets wrapped in a Left somewhere.

@csgero
Copy link

csgero commented May 29, 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
Projects
None yet
Development

No branches or pull requests

3 participants