-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinfo.go
52 lines (45 loc) · 1.08 KB
/
info.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
package openapi
import (
"net/url"
)
// codebeat:disable[TOO_MANY_IVARS]
// Info Object
type Info struct {
Title string
Description string
TermsOfService string `yaml:"termsOfService"`
Contact *Contact
License *License
Version string
}
// Validate the values of Info object.
func (info Info) Validate() error {
if err := info.validateRequiredFields(); err != nil {
return err
}
return info.validateFields()
}
func (info Info) validateRequiredFields() error {
if info.Title == "" {
return ErrRequired{Target: "info.title"}
}
if info.Version == "" {
return ErrRequired{Target: "info.version"}
}
return nil
}
func (info Info) validateFields() error {
if info.TermsOfService != "" {
if _, err := url.ParseRequestURI(info.TermsOfService); err != nil {
return ErrFormatInvalid{Target: "info.termsOfService", Format: "URL"}
}
}
var validaters []validater
if info.Contact != nil {
validaters = append(validaters, info.Contact)
}
if info.License != nil {
validaters = append(validaters, info.License)
}
return validateAll(validaters)
}