zio-http icon indicating copy to clipboard operation
zio-http copied to clipboard

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

Open jiramares opened this issue 1 year ago • 9 comments

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 avatar Dec 19 '24 09:12 jiramares

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

jiramares avatar Dec 19 '24 09:12 jiramares

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

987Nabil avatar Jan 18 '25 10:01 987Nabil

/bounty $150

jdegoes avatar Jan 22 '25 16:01 jdegoes

💎 $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

❗ Important guidelines:

  • To claim a bounty, you need to provide a short demo video of your changes in your pull request
  • If anything is unclear, ask for clarification before starting as this will help avoid potential rework
  • Low quality AI PRs will not receive review and will be closed
  • Do not ask to be assigned unless you've contributed before

Thank you for contributing to zio/zio-http!

Attempt Started (UTC) Solution Actions
🟢 @AltuisticIsopod Nov 01, 2025, 05:39:35 AM #3775 Reward
🟢 @luffy-orf Jun 05, 2025, 06:34:12 AM WIP
🟢 @ffprivacy Jan 24, 2025, 08:17:51 PM WIP
🟢 @Pranav-P-S Sep 26, 2025, 02:16:14 PM WIP

algora-pbc[bot] avatar Jan 22 '25 16:01 algora-pbc[bot]

/attempt #3260

Options

ffprivacy avatar Jan 24 '25 20:01 ffprivacy

/attempt #3260

luffy-orf avatar Jun 05 '25 06:06 luffy-orf

/attempt #3260

Pranav-P-S avatar Sep 26 '25 14:09 Pranav-P-S

/attempt #3260

AltuisticIsopod avatar Nov 01 '25 05:11 AltuisticIsopod