Skip to content

Commit bf5586c

Browse files
committed
fix indentations and optional enum types
1 parent a394056 commit bf5586c

4 files changed

Lines changed: 38763 additions & 31047 deletions

File tree

build.sbt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -229,22 +229,7 @@ def codegenTask(
229229
}
230230

231231
val files = listFilesRec(List(outDir), Nil)
232-
233-
// formatting (may need to find another way...)
234-
val fmtCmd = s"scala-cli fmt --scalafmt-conf=./.scalafmt.conf ${outDir.absolutePath}"
235-
logger.info(s"Formatting with '$fmtCmd'")
236-
val fmtErrs = scala.collection.mutable.ListBuffer.empty[String]
237-
fmtCmd ! ProcessLogger(
238-
_ => (),
239-
e => fmtErrs += e
240-
) match {
241-
case 0 => ()
242-
case c => throw new InterruptedException(s"Failure on code formatting: ${errs.mkString("\n")}")
243-
}
244-
245232
IO.delete(outDir / ".scala-build")
246-
logger.success(s"Formatting sources in $outPathRel done")
247-
248233
files
249234
}
250235
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,14 @@ def resourceCode(
368368
case None => None
369369

370370
val (requiredParams, optParams) = method.scalaParameters.partition(_._2.required)
371-
val params =
372-
requiredParams.map((n, t) => s"${toComment(t.description)}$n: ${t.scalaType(arrType)}") :::
373-
req.toList.map(r => s"request: ${r.scalaType(arrType)}") :::
374-
uploadProtocol.toList.map((typ, default) => s"uploadProtocol: $typ = \"$default\"") :::
375-
optParams.map((n, t) => s"${toComment(t.description)}$n: ${t.scalaType(arrType)} = None") :::
371+
def params(indent: String) =
372+
requiredParams.map((n, t) => s"${toComment(t.description)}$indent$n: ${t.scalaType(arrType)}") :::
373+
req.toList.map(r => s"${indent}request: ${r.scalaType(arrType)}") :::
374+
uploadProtocol.toList.map((typ, default) => s"${indent}uploadProtocol: $typ = \"$default\"") :::
375+
optParams.map((n, t) => s"${toComment(t.description)}$indent$n: ${t.scalaType(arrType)} = None") :::
376376
List(
377-
s"endpointUrl: Uri = $rootPkg.baseUrl",
378-
"commonQueryParams: QueryParameters = " + ((
377+
s"${indent}endpointUrl: Uri = $rootPkg.baseUrl",
378+
s"${indent}commonQueryParams: QueryParameters = " + ((
379379
method.mediaUploads,
380380
commonQueryParams.collectFirst { case ("uploadType", Parameter(_, _, e: SchemaType.Enum, _, _)) => e }
381381
) match {
@@ -431,10 +431,10 @@ def resourceCode(
431431
)
432432
case _ => (responseType("String"), ".response(asEmptyResponse)")
433433

434-
s"""|def ${toScalaName(k)}(\n${params.mkString(",\n")}): $resType = {$queryParams
435-
| $setReqUri
436-
| resourceRequest.${method.httpMethod.toLowerCase()}(requestUri.addParams(params))$body$mapResponse
437-
|}""".stripMargin
434+
s"""| def ${toScalaName(k)}(\n${params(indent = " ").mkString(",\n")}\n ): $resType = {$queryParams
435+
| $setReqUri
436+
| resourceRequest.${method.httpMethod.toLowerCase()}(requestUri.addParams(params))$body$mapResponse
437+
| }""".stripMargin
438438
}
439439
.mkString("\n", "\n\n", "\n") +
440440
"}"
@@ -489,12 +489,12 @@ def schemasCode(
489489
val enumType =
490490
if jsonCodec == JsonCodec.ZioJson then SchemaType.EnumType.Literal
491491
else SchemaType.EnumType.Nominal(s"$scalaName.$n")
492-
s"${toComment(t.withTypeDescription)}$n: ${
492+
s"${toComment(t.withTypeDescription)} $n: ${
493493
(if (t.optional) s"${t.scalaType(arrType, enumType)} = None" else t.scalaType(arrType, enumType))
494494
}"
495495
}
496496
.mkString("", ",\n", "")}
497-
|) {\n${`def toJsonString`(scalaName)}\n}\n
497+
|) {\n ${`def toJsonString`(scalaName)}\n}\n
498498
|
499499
|${jsonDecoder(scalaName)}
500500
|""".stripMargin
@@ -810,7 +810,7 @@ object SchemaType:
810810
read[List[String]](e)
811811
.zip(read[List[String]](o("enumDescriptions")))
812812
.map((v, vd) => EnumValue(value = v, enumDescription = vd)),
813-
false
813+
optional
814814
)
815815
case _ =>
816816
o.value.get("additionalProperties").map(_.obj) match

0 commit comments

Comments
 (0)