Skip to content

Commit

Permalink
Merge pull request #568 from Nezisi/cast-null-to-jsnull
Browse files Browse the repository at this point in the history
Match a default value of "null" to JsNull
  • Loading branch information
Javakky-pxv authored Jul 18, 2023
2 parents bac613b + b973fe9 commit 85ec204
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,22 @@ object SwaggerParameterMapper {

val defaultValueO: Option[JsValue] = {
parameter.default.map { value =>
typeName match {
case ci"Int" | ci"Long" => JsNumber(value.toLong)
case ci"Double" | ci"Float" | ci"BigDecimal" => JsNumber(value.toDouble)
case ci"Boolean" => JsBoolean(value.toBoolean)
case ci"String" => {
val noquotes = value match {
case c if c.startsWith("\"\"\"") && c.endsWith("\"\"\"") => c.substring(3, c.length - 3)
case c if c.startsWith("\"") && c.endsWith("\"") => c.substring(1, c.length - 1)
case c => c
}
JsString(noquotes)
if (value.equals("null")) {
JsNull
} else {
typeName match {
case ci"Int" | ci"Long" => JsNumber(value.toLong)
case ci"Double" | ci"Float" | ci"BigDecimal" => JsNumber(value.toDouble)
case ci"Boolean" => JsBoolean(value.toBoolean)
case ci"String" =>
val unquotedString = value match {
case c if c.startsWith("\"\"\"") && c.endsWith("\"\"\"") => c.substring(3, c.length - 3)
case c if c.startsWith("\"") && c.endsWith("\"") => c.substring(1, c.length - 1)
case c => c
}
JsString(unquotedString)
case _ => JsString(value)
}
case _ => JsString(value)
}
}
}
Expand Down

0 comments on commit 85ec204

Please sign in to comment.