-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathexternal-docs.go
More file actions
64 lines (55 loc) · 1.66 KB
/
external-docs.go
File metadata and controls
64 lines (55 loc) · 1.66 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
package openapi
// ExternalDocs allows referencing an external resource for extended documentation.
//
// https://spec.openapis.org/oas/v3.1.1#external-documentation-object
//
// Example:
//
// description: Find more info here
// url: https://example.com
type ExternalDocs struct {
// A description of the target documentation.
// CommonMark syntax MAY be used for rich text representation.
Description string `json:"description" yaml:"description"`
// REQUIRED.
// The URL for the target documentation.
// This MUST be in the form of a URL.
URL string `json:"url" yaml:"url"`
}
func (o *ExternalDocs) validateSpec(location string, _ *Validator) []*validationError {
var errs []*validationError
if o.URL == "" {
errs = append(errs, newValidationError(joinLoc(location, "url"), ErrRequired))
}
if err := checkURL(o.URL); err != nil {
errs = append(errs, newValidationError(joinLoc(location, "url"), err))
}
return errs
}
type ExternalDocsBuilder struct {
spec *Extendable[ExternalDocs]
}
func NewExternalDocsBuilder() *ExternalDocsBuilder {
return &ExternalDocsBuilder{
spec: NewExtendable[ExternalDocs](&ExternalDocs{}),
}
}
func (b *ExternalDocsBuilder) Build() *Extendable[ExternalDocs] {
return b.spec
}
func (b *ExternalDocsBuilder) Extensions(v map[string]any) *ExternalDocsBuilder {
b.spec.Extensions = v
return b
}
func (b *ExternalDocsBuilder) AddExt(name string, value any) *ExternalDocsBuilder {
b.spec.AddExt(name, value)
return b
}
func (b *ExternalDocsBuilder) Description(v string) *ExternalDocsBuilder {
b.spec.Spec.Description = v
return b
}
func (b *ExternalDocsBuilder) URL(v string) *ExternalDocsBuilder {
b.spec.Spec.URL = v
return b
}