Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
encoding/openapi: correctly extract type in the presence of null
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mpvl committed Apr 1, 2021
1 parent 792da39 commit 2115955
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion encoding/openapi/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"cuelang.org/go/cue/errors"
"cuelang.org/go/cue/token"
"cuelang.org/go/internal"
"cuelang.org/go/internal/core/adt"
)

type buildContext struct {
Expand Down Expand Up @@ -591,7 +592,8 @@ func (b *builder) setValueType(v cue.Value) {
return
}

switch v.IncompleteKind() {
k := v.IncompleteKind() &^ adt.NullKind
switch k {
case cue.BoolKind:
b.typ = "boolean"
case cue.FloatKind, cue.NumberKind:
Expand Down
10 changes: 10 additions & 0 deletions encoding/openapi/testdata/nums-v3.1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions encoding/openapi/testdata/nums.cue
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ import "math"

#exMin: >5
#exMax: <6

#int: int64
#intNull: int64 | null
10 changes: 10 additions & 0 deletions encoding/openapi/testdata/nums.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2115955

Please sign in to comment.