Skip to content

Commit f21310f

Browse files
authored
Merge branch 'cue-lang:master' into master
2 parents f5a485e + 19eea7f commit f21310f

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

encoding/jsonschema/ref.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (s *state) makeCUERef(n cue.Value, u *url.URL, fragmentParts []string) (_e
138138
return s.rootRef()
139139
}
140140

141-
ident, fragmentParts = s.getNextIdent(n, fragmentParts)
141+
ident, fragmentParts = s.getNextIdent(n.Pos(), fragmentParts)
142142

143143
case u.Host != "":
144144
// Reference not found within scope. Create an import reference.
@@ -206,22 +206,22 @@ func (s *state) makeCUERef(n cue.Value, u *url.URL, fragmentParts []string) (_e
206206
}
207207
return newSel(e, s.idRef[1])
208208
}
209-
ident, fragmentParts = s.getNextIdent(n, fragmentParts)
209+
ident, fragmentParts = s.getNextIdent(n.Pos(), fragmentParts)
210210
ident.Node = s.obj
211211
break
212212
}
213213
}
214214

215-
return s.newSel(ident, n, fragmentParts)
215+
return s.newSel(n.Pos(), ident, fragmentParts)
216216
}
217217

218218
// getNextSelector translates a JSON Reference path into a CUE path by consuming
219219
// the first path elements and returning the corresponding CUE label.
220-
func (s *state) getNextSelector(v cue.Value, a []string) (l label, tail []string) {
220+
func (s *state) getNextSelector(pos token.Pos, a []string) (l label, tail []string) {
221221
switch elem := a[0]; elem {
222222
case "$defs", "definitions":
223223
if len(a) == 1 {
224-
s.errf(v, "cannot refer to %s section: must refer to one of its elements", a[0])
224+
s.warnf(pos, "cannot refer to %s section: must refer to one of its elements", a[0])
225225
return label{}, nil
226226
}
227227

@@ -233,7 +233,7 @@ func (s *state) getNextSelector(v cue.Value, a []string) (l label, tail []string
233233

234234
case "properties":
235235
if len(a) == 1 {
236-
s.errf(v, "cannot refer to %s section: must refer to one of its elements", a[0])
236+
s.warnf(pos, "cannot refer to %s section: must refer to one of its elements", a[0])
237237
return label{}, nil
238238
}
239239

@@ -245,7 +245,7 @@ func (s *state) getNextSelector(v cue.Value, a []string) (l label, tail []string
245245
"additionalItems":
246246
// TODO: as a temporary workaround, include the schema verbatim.
247247
// TODO: provide definitions for these in CUE.
248-
s.errf(v, "referring to field %q not yet supported", elem)
248+
s.warnf(pos, "referring to field %q not yet supported", elem)
249249

250250
// Other known fields cannot be supported.
251251
return label{}, nil
@@ -255,12 +255,12 @@ func (s *state) getNextSelector(v cue.Value, a []string) (l label, tail []string
255255
}
256256
}
257257

258-
// newSel converts a JSON Reference path and initial CUE identifier to
259-
// a CUE selection path.
260-
func (s *state) newSel(e ast.Expr, v cue.Value, a []string) ast.Expr {
258+
// newSel converts an initial CUE identifier and a relative JSON Reference path
259+
// to a CUE selection path.
260+
func (s *state) newSel(pos token.Pos, e ast.Expr, a []string) ast.Expr {
261261
for len(a) > 0 {
262262
var label label
263-
label, a = s.getNextSelector(v, a)
263+
label, a = s.getNextSelector(pos, a)
264264
e = newSel(e, label)
265265
}
266266
return e
@@ -310,8 +310,8 @@ func (s *state) setRef(lab label, r refs) {
310310

311311
// getNextIdent gets the first CUE reference from a JSON Reference path and
312312
// converts it to a CUE identifier.
313-
func (s *state) getNextIdent(v cue.Value, a []string) (resolved *ast.Ident, tail []string) {
314-
lab, a := s.getNextSelector(v, a)
313+
func (s *state) getNextIdent(pos token.Pos, a []string) (resolved *ast.Ident, tail []string) {
314+
lab, a := s.getNextSelector(pos, a)
315315

316316
x := s.getRef(lab)
317317
ident := ast.NewIdent(x.ident)

0 commit comments

Comments
 (0)