-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinterfaces.go
62 lines (47 loc) · 1.09 KB
/
interfaces.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package openrpc
import (
"encoding/json"
jptr "github.com/qri-io/jsonpointer"
jsch "github.com/qri-io/jsonschema"
)
// Pointer represents a generic json pointer
type Pointer interface {
//Refs returns a slice containing all the (ordered) references of a pointer
Refs() []string
//String formats the references as a slash-separated string
String() string
json.Marshaler
}
type jsonPointer struct {
p jptr.Pointer
}
func (jp *jsonPointer) Refs() []string {
return jp.p
}
func (jp *jsonPointer) String() string {
return jp.p.String()
}
func (jp *jsonPointer) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]string{"$ref": "#" + jp.String()})
}
func NewPointer(path string) (Pointer, error) {
p, err := jptr.Parse(path)
return &jsonPointer{p: p}, err
}
func newPointerFromRefs(refs []string) Pointer {
if refs == nil {
refs = []string{}
}
return &jsonPointer{p: refs}
}
//Schema is a json schema
type Schema interface {
json.Marshaler
json.Unmarshaler
}
type jsonSchema struct {
jsch.Schema
}
func NewSchema() Schema {
return &jsonSchema{Schema: jsch.Schema{}}
}