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

Too aggressive field name sanitization #2622

Closed
nikolaiser opened this issue Jan 14, 2024 · 5 comments
Closed

Too aggressive field name sanitization #2622

nikolaiser opened this issue Jan 14, 2024 · 5 comments
Labels
💎 Bounty bug Something isn't working 💰 Rewarded

Comments

@nikolaiser
Copy link

Describe the bug
When generating endpoints from OpenAPI schema, all vals in field names are removed, which affects valid names like value

To Reproduce

The following scala-cli script

//> using scala 2.13.12
//> using repository sonatype:snapshots
//> using dep dev.zio::zio-http-gen:3.0.0-RC4+41-2d267b56-SNAPSHOT
//> using dep dev.zio::zio-json-yaml:0.6.2

import zio.http.gen.openapi.EndpointGen
import zio.http.endpoint.openapi.OpenAPI
import zio.http.endpoint.openapi.JsonSchema
import zio.json.yaml._
import zio.schema.codec.JsonCodec
import zio.http.gen.scala.CodeGen
import java.nio.file.Paths

object Main {

  val openapiYaml = """
                      |openapi: 3.0.3
                      |info:
                      | title: Example
                      | description: Example API documentation
                      | version: 1.0.0
                      |paths:
                      | /foo:
                      |   post:
                      |     requestBody:
                      |       content:
                      |         application/json:
                      |           schema:
                      |             $ref: '#/components/schemas/Bar' 
                      |     responses:
                      |       '200':
                      |         description: Success
                      |
                      |components:
                      | schemas:
                      |   Bar:
                      |     type: object
                      |     properties:
                      |       value:
                      |         type: string
  """.stripMargin

  implicit val openapiDecoder = JsonCodec.jsonDecoder(OpenAPI.schema)

  def main(args: Array[String]) = {
    val openapi = openapiYaml.fromYaml[OpenAPI].toOption.get
    val files = EndpointGen.fromOpenAPI(openapi)
    CodeGen.writeFiles(
      files,
      Paths.get("./sanitization-output"),
      "foo.bar",
      None
    )
  }
}

Generates a file ./sanitization-output/component/Bar.scala

package foo.bar.component

import zio.schema._

case class Bar(
 ue: Option[String]
)
object Bar {


 implicit val codec: Schema[Bar] = DeriveSchema.gen[Bar]



}

Expected behaviour
Valid field names like value should not be changed

@nikolaiser nikolaiser added the bug Something isn't working label Jan 14, 2024
@jdegoes
Copy link
Member

jdegoes commented Jan 18, 2024

/bounty $50

Copy link

algora-pbc bot commented Jan 18, 2024

💎 $50 bounty created by ZIO
🙋 If you start working on this, comment /attempt #2622 to notify everyone
👉 To claim this bounty, submit a pull request that includes the text /claim #2622 somewhere in its body
📝 Before proceeding, please make sure you can receive payouts in your country
💵 Payment arrives in your account 2-5 days after the bounty is rewarded
💯 You keep 100% of the bounty award
🙏 Thank you for contributing to zio/zio-http!

👉 Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🟢 @ekhov Jan 18, 2024, 4:45:50 PM #2634

@ekhov
Copy link
Contributor

ekhov commented Jan 18, 2024

/attempt #2622

Algora profile Completed bounties Tech Active attempts Options
@ekhov    1 ZIO bounty
+ 0 bounties from 0 projects
Python, Scala
Cancel attempt

Copy link

algora-pbc bot commented Jan 18, 2024

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

Copy link

algora-pbc bot commented Jan 20, 2024

🎉🎈 @ekhov has been awarded $50! 🎈🎊

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

No branches or pull requests

4 participants