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

[gen] Endpoint path modification in EndpointGen when having - in the path. #3217

Open
wi101 opened this issue Nov 22, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@wi101
Copy link

wi101 commented Nov 22, 2024

Describe the bug

When generating Scala endpoints from an OpenAPI JSON file using EndpointGen, any path segments containing - are automatically replaced with _.
This behavior alters the expected endpoint paths and may lead to discrepancies between the OpenAPI specification and the generated code.

To Reproduce
Steps to reproduce the behaviour:

  1. Define an example api.json with an endpoint that contains -
{
  "paths": {
    "/example-path": {
      "get": {
        "summary": "Example endpoint",
        ...
      }
    }
  }
}
  1. Generate scala code and the endpoints from api.json file.
for {
      json                        <- readJsonFileAsString("/api.json")
      openApi                     <- ZIO.fromEither(OpenAPI.fromJson(json))
      endpointsAndComponentsFiles <- ZIO.attempt(EndpointGen.fromOpenAPI(openApi))
      directory                   <- ZIO.attempt(Files.createDirectories(Paths.get("src")))
      _                           <- ZIO
                                       .attempt(
                                         CodeGen.writeFiles(
                                           endpointsAndComponentsFiles,
                                           java.nio.file.Paths.get(directory.toString, "main", "scala", "codegen"),
                                           "codegen",
                                          None
                                         )
                                       )
    } yield ()
  1. Observe that the generated endpoint path becomes /example_path.
val post = Endpoint(Method.POST / "example_path")
    .in[Types]
    .out[Unit](status = Status.Ok)

Expected behaviour
The generated endpoint should retain the original - character in the path as defined in the OpenAPI JSON file

Used version
zio-http version: 3.0.1

@wi101 wi101 added the bug Something isn't working label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant