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

Closed
russwyte opened this issue Apr 21, 2024 · 10 comments · Fixed by #2922
Closed

Regression - OpenAPIGen breaks with String output examples #2789

russwyte opened this issue Apr 21, 2024 · 10 comments · Fixed by #2922
Labels
💎 Bounty bug Something isn't working 💰 Rewarded

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

@jdegoes
Copy link
Member

jdegoes commented Jun 5, 2024

/bounty $75

Copy link

algora-pbc bot commented Jun 5, 2024

💎 $75 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #2789 with your implementation plan
  2. Submit work: Create a pull request including /claim #2789 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-http!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🟢 @987Nabil #2922

@guersam
Copy link
Contributor

guersam commented Jun 10, 2024

It breaks my endpoint with an example, even if the output is JSON. The test fixtures are missing examplesOut, indicating they are untested. (source)

Copy link

algora-pbc bot commented Jun 20, 2024

💡 @987Nabil submitted a pull request that claims the bounty. You can visit your bounty board to reward.

987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jun 20, 2024
jdegoes pushed a commit that referenced this issue Jun 24, 2024
HttpCodec fallback always eliminates HttpCodec.Halt (#2789)
Copy link

algora-pbc bot commented Jun 24, 2024

🎉🎈 @987Nabil has been awarded $75! 🎈🎊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 Bounty bug Something isn't working 💰 Rewarded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants