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

Generated openAPI shows example in application/json instead of specified text/plain #3260

Open
jiramares opened this issue Dec 19, 2024 · 6 comments
Labels
💎 Bounty bug Something isn't working

Comments

@jiramares
Copy link

Describe the bug
Specifying text/plain media type for response causes openAPI shows response example in wrong media type (stilll uses application/json).

To Reproduce
Following endpoint specifies response media type to text/plain:

val ep2 = Endpoint(RoutePattern.GET / "greeting" / string("name"))
    .outCodec(HttpCodec.content[Greeting](MediaType.text.plain))

and generated openAPI shows response as (the media type is right text/plain):

{
  "msg": "string"
}

Expected behaviour
The response example should be:

string

Dependencies:

    "dev.zio" %% "zio" % "2.1.9",
    "dev.zio" %% "zio-http" % "3.0.1"
    "dev.zio" %% "zio-schema" % "1.4.1"
@jiramares jiramares added the bug Something isn't working label Dec 19, 2024
@jiramares
Copy link
Author

The same is also true for error channel:

val ep5 = Endpoint(RoutePattern.GET / "greeting3" / nameParam / "exclamation" / boolParam)
        .copy(error = HttpCodec.content[Greeting](MediaType.text.plain) ++ HttpCodec.status(Status.NotFound))
        .outCodec(HttpCodec.content[Greeting](MediaType.text.plain))

the example error response is

{
  "msg": "string"
}

not plain text

string

@987Nabil
Copy link
Contributor

The examples are currently explicitly created for json. We need to make this dynamic by the media type in the codec

@jdegoes
Copy link
Member

jdegoes commented Jan 22, 2025

/bounty $150

Copy link

algora-pbc bot commented Jan 22, 2025

💎 $150 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #3260 with your implementation plan
  2. Submit work: Create a pull request including /claim #3260 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
🟢 @ffprivacy Jan 24, 2025, 8:17:51 PM #3283

@ffprivacy
Copy link

ffprivacy commented Jan 24, 2025

/attempt #3260

Copy link

algora-pbc bot commented Jan 24, 2025

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

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
Projects
None yet
Development

No branches or pull requests

4 participants