guardrail-dev / guardrail-dev/guardrail

Incorrect encoding of nullable non-required field with default

Open
#2,025 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
541
Forks
138
PR merge metrics
No merged PRs in 30d

Description

using spec like this
```
{
"openapi": "3.0.2",
"components": {
"schemas": {
"test": {
"type": "object",
"properties": {
"method": {
"type": "string",
"default": "",
"example": "TEXT",
"nullable": true
}
},
"required": [
]
}
}
}
}
```
and config like
```
addSbtPlugin("dev.guardrail" % "sbt-guardrail" % "1.0.0-M1")

libraryDependencies ++= Seq(
"dev.guardrail" %% "guardrail-scala-pekko-http" % "1.0.0-M1",
)
```
```
Compile / guardrailTasks := List(
ScalaClient(
(Compile / resourceDirectory).value / "openapi" / "asd.json",
pkg = "test",
modules = List("pekko-http", "circe"),
)
)
```

i get a compilation error
```
[error] 11 |case class Test(method: _root_.test.support.Presence[Option[String]] = _root_.test.support.Presence.Present(""))
[error] | Found: ("" : String)
[error] | Required: Option[String]
[```

Contributor guide

Open the contributing guide

Research direction

Start with the OpenAPI schema and sbt Guardrail configuration shown in the issue, then run Compile / guardrailTasks to reproduce the generated Test case and compilation error. Trace how a nullable, optional field with a string default is encoded, and consider the issue done when the generated Scala code compiles with the expected optional value handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, scala
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.