Skip to content

Commit 8d77ed4

Browse files
authored
fix missing empty object type, add redis specs to test (#11)
* fix missing empty object type, add redis specs to test * make empty object type optional
1 parent 8460001 commit 8d77ed4

File tree

3 files changed

+4827
-11
lines changed

3 files changed

+4827
-11
lines changed

build.sbt

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ lazy val testProjects: CompositeProject = new CompositeProject {
129129
"pubsub" -> "v1",
130130
"storage" -> "v1",
131131
"aiplatform" -> "v1",
132-
"iamcredentials" -> "v1"
132+
"iamcredentials" -> "v1",
133+
"redis" -> "v1"
133134
)
134135
httpSource <- Seq("Sttp4", "Sttp3")
135136
jsonCodec <- Seq("ZioJson", "Jsoniter")

modules/core/shared/src/main/scala/codegen.scala

+21-10
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,28 @@ def generateBySpec(
253253
List(commonCodecsPath.toFile())
254254
}
255255
schemas <- Future
256-
.traverse(specs.schemas.filter(_._2.properties.nonEmpty)) { (schemaPath, schema) =>
256+
.traverse(specs.schemas) { (schemaPath, schema) =>
257257
Future {
258-
val code = schemasCode(
259-
schema = schema,
260-
pkg = schemasPkg,
261-
jsonCodec = config.jsonCodec,
262-
dialect = config.dialect,
263-
hasProps = p => specs.hasProps(p),
264-
arrType = config.arrayType,
265-
commonCodecsPkg = if commonCodecs.nonEmpty && schema.hasArrays then Some(commonCodecsPkg) else None
266-
)
258+
val code =
259+
(if schema.properties.nonEmpty then
260+
schemasCode(
261+
schema = schema,
262+
pkg = schemasPkg,
263+
jsonCodec = config.jsonCodec,
264+
dialect = config.dialect,
265+
hasProps = p => specs.hasProps(p),
266+
arrType = config.arrayType,
267+
commonCodecsPkg =
268+
if commonCodecs.nonEmpty && schema.hasArrays then Some(commonCodecsPkg) else None
269+
)
270+
else
271+
// create a type alias for objects without properties
272+
val comment = toComment(schema.description)
273+
s"""|package $schemasPkg
274+
|
275+
|${comment}type ${schema.id.scalaName} = Option[""]""".stripMargin
276+
)
277+
267278
val path = schemasPath / s"${schemaPath.scalaName}.scala"
268279
Files.writeString(path, code)
269280
path.toFile()

0 commit comments

Comments
 (0)