Skip to content

Commit

Permalink
#2419: Use optional OpenAPI parameter if a default value is defined (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
xerial committed May 4, 2022
1 parent c44e6a6 commit ebc7b86
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
Expand Up @@ -434,7 +434,7 @@ private[openapi] object OpenAPIGenerator extends LogSupport {

private def requiredParams(params: Seq[wvlet.airframe.surface.Parameter]): Option[Seq[String]] = {
val required = params
.filter(p => p.isRequired || !p.surface.isOption)
.filter(p => p.isRequired || !(p.getDefaultValue.nonEmpty || p.surface.isOption))
.map(_.name)
if (required.isEmpty) None else Some(required)
}
Expand Down
Expand Up @@ -41,7 +41,7 @@ object OpenAPIRPCExample {
x2: Long,
x3: Boolean,
x4: Float,
x5: Double,
x5: Double = 1.0,
x6: Array[String],
x7: Seq[String],
x8: Map[String, Any],
Expand Down
Expand Up @@ -28,17 +28,17 @@ class OpenAPITest extends AirSpec {
val openapi = OpenAPI
.ofRouter(rpcRouter)
.withInfo(OpenAPI.Info(title = "RPCTest", version = "1.0"))
debug(openapi)
trace(openapi)

openapi.info.title shouldBe "RPCTest"
openapi.info.version shouldBe "1.0"

val json = openapi.toJSON
debug(s"Open API JSON:\n${json}\n")
trace(s"Open API JSON:\n${json}\n")
parseOpenAPI(json)

val yaml = openapi.toYAML
debug(s"Open API Yaml:\n${yaml}\n")
trace(s"Open API Yaml:\n${yaml}\n")
parseOpenAPI(yaml)

// Naive tests for checking YAML fragments.
Expand Down Expand Up @@ -126,7 +126,6 @@ class OpenAPITest extends AirSpec {
| - x2
| - x3
| - x4
| - x5
| - x6
| - x7
| - x8
Expand Down Expand Up @@ -173,7 +172,7 @@ class OpenAPITest extends AirSpec {
)

fragments.foreach { x =>
debug(s"checking ${x}")
debug(s"checking\n${x}")
yaml.contains(x) shouldBe true
}
}
Expand Down

0 comments on commit ebc7b86

Please sign in to comment.