encoding/openapi: correctly extract type in the presence of null
Change-Id: I181151c387844af3f5a1c4c7cc1e654230b4217e
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9261
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
diff --git a/encoding/openapi/build.go b/encoding/openapi/build.go
index d9d1865..a5330f2 100644
--- a/encoding/openapi/build.go
+++ b/encoding/openapi/build.go
@@ -28,6 +28,7 @@
"cuelang.org/go/cue/errors"
"cuelang.org/go/cue/token"
"cuelang.org/go/internal"
+ "cuelang.org/go/internal/core/adt"
)
type buildContext struct {
@@ -591,7 +592,8 @@
return
}
- switch v.IncompleteKind() {
+ k := v.IncompleteKind() &^ adt.NullKind
+ switch k {
case cue.BoolKind:
b.typ = "boolean"
case cue.FloatKind, cue.NumberKind:
diff --git a/encoding/openapi/testdata/nums-v3.1.0.json b/encoding/openapi/testdata/nums-v3.1.0.json
index 4c3cc67..f752a11 100644
--- a/encoding/openapi/testdata/nums-v3.1.0.json
+++ b/encoding/openapi/testdata/nums-v3.1.0.json
@@ -15,6 +15,16 @@
"type": "number",
"exclusiveMinimum": 5
},
+ "int": {
+ "type": "integer",
+ "format": "int64"
+ },
+ "intNull": {
+ "type": "integer",
+ "minimum": -9223372036854775808,
+ "maximum": 9223372036854775807,
+ "nullable": true
+ },
"mul": {
"type": "number",
"multipleOf": 5
diff --git a/encoding/openapi/testdata/nums.cue b/encoding/openapi/testdata/nums.cue
index 94d178b..3c25531 100644
--- a/encoding/openapi/testdata/nums.cue
+++ b/encoding/openapi/testdata/nums.cue
@@ -6,3 +6,6 @@
#exMin: >5
#exMax: <6
+
+#int: int64
+#intNull: int64 | null
diff --git a/encoding/openapi/testdata/nums.json b/encoding/openapi/testdata/nums.json
index 18332db..81c025c 100644
--- a/encoding/openapi/testdata/nums.json
+++ b/encoding/openapi/testdata/nums.json
@@ -17,6 +17,16 @@
"minimum": 5,
"exclusiveMinimum": true
},
+ "int": {
+ "type": "integer",
+ "format": "int64"
+ },
+ "intNull": {
+ "type": "integer",
+ "minimum": -9223372036854775808,
+ "maximum": 9223372036854775807,
+ "nullable": true
+ },
"mul": {
"type": "number",
"multipleOf": 5