Skip to content

Commit ebeb2ba

Browse files
committed
anchor
1 parent 417b4e7 commit ebeb2ba

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

schema.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ type Schema struct {
267267
// "$id", the base URI is that of the entire document, as
268268
// determined per RFC 3986 section 5 [RFC3986].
269269
ID string `json:"$id,omitempty"`
270+
Anchor string `json:"$anchor,omitempty"`
270271
// Title and description can be used to decorate a user interface
271272
// with information about the data produced by this user interface.
272273
// A title will preferably be short.
@@ -405,6 +406,8 @@ func (s Schema) JSONProp(name string) interface{} {
405406
switch name {
406407
case "$id":
407408
return s.ID
409+
case "$anchor":
410+
return s.ID
408411
case "title":
409412
return s.Title
410413
case "description":
@@ -465,6 +468,7 @@ func (s Schema) JSONChildren() (ch map[string]JSONPather) {
465468
// _schema is an internal struct for encoding & decoding purposes
466469
type _schema struct {
467470
ID string `json:"$id,omitempty"`
471+
Anchor string `json:"$anchor,omitempty"`
468472
Title string `json:"title,omitempty"`
469473
Description string `json:"description,omitempty"`
470474
Default interface{} `json:"default,omitempty"`
@@ -500,6 +504,7 @@ func (s *Schema) UnmarshalJSON(data []byte) error {
500504

501505
sch := &Schema{
502506
ID: _s.ID,
507+
Anchor: _s.Anchor,
503508
Title: _s.Title,
504509
Description: _s.Description,
505510
Default: _s.Default,
@@ -537,7 +542,7 @@ func (s *Schema) UnmarshalJSON(data []byte) error {
537542
} else {
538543
switch prop {
539544
// skip any already-parsed props
540-
case "$vocabulary", "$recursiveAnchor", "$schema", "$id", "title", "description", "default", "examples", "extends", "readOnly", "writeOnly", "$comment", "$ref", "$recursiveRef", "$defs", "format":
545+
case "$anchor", "$vocabulary", "$recursiveAnchor", "$schema", "$id", "title", "description", "default", "examples", "extends", "readOnly", "writeOnly", "$comment", "$ref", "$recursiveRef", "$defs", "format":
541546
continue
542547
default:
543548
// assume non-specified props are "extra definitions"
@@ -597,6 +602,9 @@ func (s Schema) MarshalJSON() ([]byte, error) {
597602
if s.ID != "" {
598603
obj["$id"] = s.ID
599604
}
605+
if s.Anchor != "" {
606+
obj["$anchor"] = s.Anchor
607+
}
600608
if s.Title != "" {
601609
obj["title"] = s.Title
602610
}

schema_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ func TestDraft2019_09(t *testing.T) {
475475
"testdata/draft2019-09/optional/format/uri.json",
476476

477477
// TODO
478-
// "testdata/draft2019-09/anchor.json",
478+
"testdata/draft2019-09/anchor.json",
479479
// "testdata/draft2019-09/defs.json",
480480
// "testdata/draft2019-09/dependentRequired.json",
481481
// "testdata/draft2019-09/dependentSchemas.json",

0 commit comments

Comments
 (0)