-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.go
63 lines (51 loc) · 1.76 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
53
54
55
56
57
58
59
60
61
62
63
package arazzo
import (
"context"
"github.com/speakeasy-api/openapi/arazzo/core"
"github.com/speakeasy-api/openapi/extensions"
"github.com/speakeasy-api/openapi/validation"
)
// Info represents metadata about the Arazzo document
type Info struct {
// Title is the name of the Arazzo document
Title string
// Summary is a short description of the Arazzo document
Summary *string
// Description is a longer description of the Arazzo document. May contain CommonMark syntax.
Description *string
// Version is the version of the Arazzo document
Version string
// Extensions provides a list of extensions to the Info object.
Extensions *extensions.Extensions
// Valid indicates whether this model passed validation.
Valid bool
core core.Info
}
var _ model[core.Info] = (*Info)(nil)
// GetCore will return the low level representation of the info object.
// Useful for accessing line and column numbers for various nodes in the backing yaml/json document.
func (i *Info) GetCore() *core.Info {
return &i.core
}
// Validate will validate the Info object against the Arazzo Specification.
func (i *Info) Validate(ctx context.Context, opts ...validation.Option) []error {
errs := []error{}
if i.core.Title.Present && i.Title == "" {
errs = append(errs, &validation.Error{
Message: "title is required",
Line: i.core.Title.GetValueNodeOrRoot(i.core.RootNode).Line,
Column: i.core.Title.GetValueNodeOrRoot(i.core.RootNode).Column,
})
}
if i.core.Version.Present && i.Version == "" {
errs = append(errs, &validation.Error{
Message: "version is required",
Line: i.core.Version.GetValueNodeOrRoot(i.core.RootNode).Line,
Column: i.core.Version.GetValueNodeOrRoot(i.core.RootNode).Column,
})
}
if len(errs) == 0 {
i.Valid = true
}
return errs
}