generated from sv-tools/go-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcontact.go
71 lines (61 loc) · 1.76 KB
/
contact.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
package openapi
// Contact information for the exposed API.
//
// https://spec.openapis.org/oas/v3.1.1#contact-object
//
// Example:
//
// name: API Support
// url: https://www.example.com/support
// email: [email protected]
type Contact struct {
// The identifying name of the contact person/organization.
Name string `json:"name,omitempty" yaml:"name,omitempty"`
// The URL pointing to the contact information.
// This MUST be in the form of a URL.
URL string `json:"url,omitempty" yaml:"url,omitempty"`
// The email address of the contact person/organization.
// This MUST be in the form of an email address.
Email string `json:"email,omitempty" yaml:"email,omitempty"`
}
func (o *Contact) validateSpec(location string, validator *Validator) []*validationError {
var errs []*validationError
if err := checkURL(o.URL); err != nil {
errs = append(errs, newValidationError(joinLoc(location, "url"), err))
}
if err := checkEmail(o.Email); err != nil {
errs = append(errs, newValidationError(joinLoc(location, "email"), err))
}
return errs
}
type ContactBuilder struct {
spec *Extendable[Contact]
}
func NewContactBuilder() *ContactBuilder {
return &ContactBuilder{
spec: NewExtendable(&Contact{}),
}
}
func (b *ContactBuilder) Build() *Extendable[Contact] {
return b.spec
}
func (b *ContactBuilder) Extensions(v map[string]any) *ContactBuilder {
b.spec.Extensions = v
return b
}
func (b *ContactBuilder) AddExt(name string, value any) *ContactBuilder {
b.spec.AddExt(name, value)
return b
}
func (b *ContactBuilder) Name(v string) *ContactBuilder {
b.spec.Spec.Name = v
return b
}
func (b *ContactBuilder) URL(v string) *ContactBuilder {
b.spec.Spec.URL = v
return b
}
func (b *ContactBuilder) Email(v string) *ContactBuilder {
b.spec.Spec.Email = v
return b
}