diff --git a/zio-http-gen/src/main/scala/zio/http/gen/scala/CodeGen.scala b/zio-http-gen/src/main/scala/zio/http/gen/scala/CodeGen.scala index 20713a764..082fc981f 100644 --- a/zio-http-gen/src/main/scala/zio/http/gen/scala/CodeGen.scala +++ b/zio-http-gen/src/main/scala/zio/http/gen/scala/CodeGen.scala @@ -69,7 +69,7 @@ object CodeGen { case Code.CaseClass(name, fields, companionObject) => s"case class $name(\n" + - fields.map(render(basePackage)).mkString(",\n").replace("val", "") + + fields.map(render(basePackage)).mkString(",\n").replace("val ", " ") + "\n)" + companionObject.map(render(basePackage)).map("\n" + _).getOrElse("") case Code.Enum(name, cases, caseNames, discriminator, noDiscriminator, schema) => diff --git a/zio-http-gen/src/test/resources/GeneratedValues.scala b/zio-http-gen/src/test/resources/GeneratedValues.scala new file mode 100644 index 000000000..c451c1145 --- /dev/null +++ b/zio-http-gen/src/test/resources/GeneratedValues.scala @@ -0,0 +1,13 @@ +package test.component + +import zio.schema._ + +case class Values( + value1: Int, + value2: String, +) +object Values { + + implicit val codec: Schema[Values] = DeriveSchema.gen[Values] + +} diff --git a/zio-http-gen/src/test/scala/zio/http/gen/model/Values.scala b/zio-http-gen/src/test/scala/zio/http/gen/model/Values.scala new file mode 100644 index 000000000..8481a3c77 --- /dev/null +++ b/zio-http-gen/src/test/scala/zio/http/gen/model/Values.scala @@ -0,0 +1,8 @@ +package zio.http.gen.model + +import zio.schema.{DeriveSchema, Schema} + +case class Values(value1: Int, value2: String) +object Values { + implicit val codec: Schema[Values] = DeriveSchema.gen[Values] +} diff --git a/zio-http-gen/src/test/scala/zio/http/gen/scala/CodeGenSpec.scala b/zio-http-gen/src/test/scala/zio/http/gen/scala/CodeGenSpec.scala index d0d1fcf1a..129264e25 100644 --- a/zio-http-gen/src/test/scala/zio/http/gen/scala/CodeGenSpec.scala +++ b/zio-http-gen/src/test/scala/zio/http/gen/scala/CodeGenSpec.scala @@ -200,5 +200,19 @@ object CodeGenSpec extends ZIOSpecDefault { "/GeneratedPaymentNoDiscriminator.scala", ) }, + test("Endpoint with case class with field named 'value'") { + val endpoint = Endpoint(Method.POST / "values").out[Values] + val openAPI = OpenAPIGen.fromEndpoints(endpoint) + val code = EndpointGen.fromOpenAPI(openAPI) + + val tempDir = Files.createTempDirectory("codegen") + CodeGen.writeFiles(code, java.nio.file.Paths.get(tempDir.toString, "test"), "test", Some(scalaFmtPath)) + + fileShouldBe( + tempDir, + "test/component/Values.scala", + "/GeneratedValues.scala", + ) + }, ) @@ java11OrNewer @@ flaky // Downloading scalafmt on CI is flaky }