-
Notifications
You must be signed in to change notification settings - Fork 2
/
license.go
110 lines (95 loc) · 2.53 KB
/
license.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package openapi
import (
"encoding/json"
"github.com/chanced/transcode"
"github.com/chanced/uri"
"gopkg.in/yaml.v3"
)
// License information for the exposed API.
type License struct {
Location `json:"-"`
// The license name used for the API.
//
// *required*
Name Text `json:"name"`
// An SPDX license expression for the API. The identifier field is mutually
// exclusive of the url field.
Identifier Text `json:"identifier,omitempty"`
// A URL to the license used for the API. This MUST be in the form of a URL.
// The url field is mutually exclusive of the identifier field.
URL *uri.URI `json:"url,omitempty"`
}
func (*License) Anchors() (*Anchors, error) { return nil, nil }
// Kind returns KindLicense
func (*License) Kind() Kind { return KindLicense }
func (*License) sliceKind() Kind { return KindUndefined }
func (*License) mapKind() Kind { return KindUndefined }
func (*License) nodes() []node { return nil }
func (l *License) isNil() bool { return l == nil }
func (l *License) location() Location { return l.Location }
func (*License) Refs() []Ref { return nil }
// func (l *License) ResolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if err := ptr.Validate(); err != nil {
// return nil, err
// }
// return l.resolveNodeByPointer(ptr)
// }
//
// func (l *License) resolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
// if ptr.IsRoot() {
// return l, nil
// }
// tok, _ := ptr.NextToken()
// return nil, newErrNotResolvable(l.absolute, tok)
// }
//
// MarshalJSON marshals JSON
func (l License) MarshalJSON() ([]byte, error) {
type license License
return json.Marshal(license(l))
}
// UnmarshalJSON unmarshals JSON
func (l *License) UnmarshalJSON(data []byte) error {
*l = License{}
type license License
var a license
err := json.Unmarshal(data, &a)
if err != nil {
return err
}
*l = License(a)
return nil
}
// MarshalYAML implements yaml.Marshaler
func (l License) MarshalYAML() (interface{}, error) {
j, err := l.MarshalJSON()
if err != nil {
return nil, err
}
var v interface{}
err = json.Unmarshal(j, &v)
if err != nil {
return nil, err
}
return v, nil
}
// UnmarshalYAML implements yaml.Unmarshaler
func (l *License) UnmarshalYAML(value *yaml.Node) error {
v, err := yaml.Marshal(value)
if err != nil {
return err
}
j, err := transcode.JSONFromYAML(v)
if err != nil {
return err
}
return json.Unmarshal(j, l)
}
func (l *License) setLocation(loc Location) error {
if l == nil {
return nil
}
l.Location = loc
return nil
}
var _ node = (*License)(nil)