-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathlicense.go
More file actions
75 lines (65 loc) · 1.9 KB
/
license.go
File metadata and controls
75 lines (65 loc) · 1.9 KB
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
package openapi
// License information for the exposed API.
//
// https://spec.openapis.org/oas/v3.1.1#license-object
//
// Example:
//
// name: Apache 2.0
// identifier: Apache-2.0
type License struct {
// REQUIRED.
// The license name used for the API.
Name string `json:"name" yaml:"name"`
// An SPDX license expression for the API.
// The identifier field is mutually exclusive of the url field.
Identifier string `json:"identifier,omitempty" yaml:"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 string `json:"url,omitempty" yaml:"url,omitempty"`
}
func (o *License) validateSpec(location string, _ *Validator) []*validationError {
var errs []*validationError
if o.Name == "" {
errs = append(errs, newValidationError(joinLoc(location, "name"), ErrRequired))
}
if o.Identifier != "" && o.URL != "" {
errs = append(errs, newValidationError(joinLoc(location, "identifier&url"), ErrMutuallyExclusive))
}
if err := checkURL(o.URL); err != nil {
errs = append(errs, newValidationError(joinLoc(location, "url"), err))
}
return errs
}
type LicenseBuilder struct {
spec *Extendable[License]
}
func NewLicenseBuilder() *LicenseBuilder {
return &LicenseBuilder{
spec: NewExtendable[License](&License{}),
}
}
func (b *LicenseBuilder) Build() *Extendable[License] {
return b.spec
}
func (b *LicenseBuilder) Extensions(v map[string]any) *LicenseBuilder {
b.spec.Extensions = v
return b
}
func (b *LicenseBuilder) AddExt(name string, value any) *LicenseBuilder {
b.spec.AddExt(name, value)
return b
}
func (b *LicenseBuilder) Name(v string) *LicenseBuilder {
b.spec.Spec.Name = v
return b
}
func (b *LicenseBuilder) Identifier(v string) *LicenseBuilder {
b.spec.Spec.Identifier = v
return b
}
func (b *LicenseBuilder) URL(v string) *LicenseBuilder {
b.spec.Spec.URL = v
return b
}