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

The OpenAPI generator may not include all endpoints for every path specified in an OpenAPI specification. #2836

Closed
stanislav-chetvertkov opened this issue May 9, 2024 · 5 comments · Fixed by #2892
Labels
💎 Bounty bug Something isn't working 💰 Rewarded

Comments

@stanislav-chetvertkov
Copy link

Describe the bug

When generating code for the following openapi spec
https://gist.github.com/stanislav-chetvertkov/606cd3143ca839cdbc63fd8231407892

that has 3 paths/endpoints

  • GET /pets
  • POST /pets
  • GET /pets/{petId}

I can only see 1 endpoint in the generated code

package base

import base.component._

object Pets {
import zio.http._
import zio.http.endpoint._
import zio.http.codec._
val createPets=Endpoint(Method.POST / "pets")
  
  
  .in[Pet]
  .out[Unit](status = Status.Created)
  




}

To Reproduce

    libraryDependencies ++= Seq(
      "dev.zio" %% "zio-http" % "3.0.0-RC6",
      "dev.zio" %% "zio-http-gen" % "3.0.0-RC6"
    )

run the following

import zio.http.endpoint.openapi.OpenAPI
import zio.http.gen.scala.{Code, CodeGen}

object Example extends App {

  val jsonString = scala.io.Source.fromResource("petstore-minimal.json").mkString
  val openapi: Either[String, OpenAPI] = OpenAPI.fromJson(jsonString)
  
  val openApiSuccess = openapi match {
    case Right(value) => value
    case Left(value) => throw new Exception(value)
  }
  
  val files: Code.Files = zio.http.gen.openapi.EndpointGen.fromOpenAPI(openApiSuccess)

  // 'target' generated

  val uri = "target/generated-sources"
  CodeGen.writeFiles(files, java.nio.file.Paths.get(uri), "base", None)
  
}

open target/generated-sources/Pets.scala

Expected behaviour
3 separate endpoint definitions in Pets.scala

@stanislav-chetvertkov stanislav-chetvertkov added the bug Something isn't working label May 9, 2024
stanislav-chetvertkov added a commit to stanislav-chetvertkov/zio-http-gen-example that referenced this issue May 9, 2024
@jdegoes
Copy link
Member

jdegoes commented Jun 4, 2024

/bounty $100

Copy link

algora-pbc bot commented Jun 4, 2024

💎 $100 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #2836 with your implementation plan
  2. Submit work: Create a pull request including /claim #2836 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 #2892

@987Nabil
Copy link
Contributor

987Nabil commented Jun 6, 2024

@stanislav-chetvertkov You assumption that all endpoints would be in one file is wrong. The GET /pets/{petId} will be in a separate file base/pets/PetId.scala. But get endpoint should be in Pets.scala.

987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jun 6, 2024
…2836)

Key is imports. And imports can be the same.
We don't need here map semantics, but just a list.
Copy link

algora-pbc bot commented Jun 6, 2024

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

jdegoes pushed a commit that referenced this issue Jun 8, 2024
… (#2892)

Key is imports. And imports can be the same.
We don't need here map semantics, but just a list.
Copy link

algora-pbc bot commented Jun 8, 2024

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

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.

3 participants