this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

encoding/encoding/jsonschema: allow type number with int enum

This change adjusts the jsonschema logic to allow a number type
to be combined with a numeric enum.

Fixes #3173.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I4e2c63a51135fa3a59ec92d401b03295dc991306
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199214
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+12 -6
+10 -3
encoding/jsonschema/decode.go
··· 243 243 var coreToCUE = []cue.Kind{ 244 244 nullType: cue.NullKind, 245 245 boolType: cue.BoolKind, 246 - numType: cue.FloatKind, 246 + numType: cue.NumberKind, // Note: both int and float. 247 247 stringType: cue.StringKind, 248 248 arrayType: cue.ListKind, 249 249 objectType: cue.StructKind, ··· 256 256 return ast.NewNull() 257 257 case cue.BoolKind: 258 258 return ast.NewIdent("bool") 259 - case cue.FloatKind: 259 + case cue.NumberKind: 260 260 return ast.NewIdent("number") 261 + case cue.IntKind: 262 + return ast.NewIdent("int") 263 + case cue.FloatKind: 264 + return ast.NewIdent("float") 261 265 case cue.StringKind: 262 266 return ast.NewIdent("string") 263 267 case cue.ListKind: ··· 265 269 case cue.StructKind: 266 270 return ast.NewStruct(&ast.Ellipsis{}) 267 271 } 268 - return nil 272 + panic(fmt.Errorf("unexpected kind %v", k)) 269 273 } 270 274 271 275 var coreTypeName = []string{ ··· 303 307 } 304 308 305 309 func (s *state) setTypeUsed(n cue.Value, t coreType) { 310 + if int(t) >= len(s.types) { 311 + panic(fmt.Errorf("type out of range %v/%v", int(t), len(s.types))) 312 + } 306 313 s.types[t].setTypeUsed(n, t) 307 314 } 308 315
+2 -3
encoding/jsonschema/testdata/numericenum.txtar
··· 8 8 "type": "number", 9 9 "enum": [ 1, 2, 3] 10 10 } 11 - -- out/decode/err -- 12 - constraint not allowed because type number is excluded: 13 - type.json:2:5 11 + -- out/decode/cue -- 12 + 1 | 2 | 3