-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlicense_struct.go
36 lines (30 loc) · 1.13 KB
/
license_struct.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
package openapi
import (
"errors"
"net/url"
"github.com/MarkRosemaker/errpath"
)
// License information for the exposed API.
// ([Specification])
//
// [Specification]: https://spec.openapis.org/oas/v3.1.0#license-object
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.
// See: https://spdx.org/licenses/
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 *url.URL `json:"url,omitempty" yaml:"url,omitempty"`
// This object MAY be extended with Specification Extensions.
Extensions Extensions `json:",inline" yaml:",inline"`
}
func (l *License) Validate() error {
if l.Name == "" {
return &errpath.ErrField{Field: "name", Err: &errpath.ErrRequired{}}
}
if l.URL != nil && l.Identifier != "" {
return errors.New("url and identifier are mutually exclusive")
}
return validateExtensions(l.Extensions)
}