-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader_yaml.go
44 lines (33 loc) · 1.09 KB
/
loader_yaml.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
package openapi
import (
"io"
"github.com/MarkRosemaker/yaml"
)
// LoadFromReaderYAML reads an OpenAPI specification in YAML format from an io.Reader and parses it into a structured format.
func (l *loader) LoadFromReaderYAML(r io.Reader) (*Document, error) {
l.reset()
doc := &Document{}
if err := yaml.UnmarshalRead(r, doc, jsonOpts); err != nil {
return nil, err
}
if err := l.collectResolveRefs(doc); err != nil {
return nil, err
}
return doc, doc.Validate()
}
// LoadFromDataYAML reads an OpenAPI specification from a byte array in YAML format and parses it into a structured format.
func LoadFromDataYAML(data []byte) (*Document, error) {
return newLoader().LoadFromDataYAML(data)
}
// LoadFromDataYAML reads an OpenAPI specification from a byte array in YAML format and parses it into a structured format.
func (l *loader) LoadFromDataYAML(data []byte) (*Document, error) {
l.reset()
doc := &Document{}
if err := yaml.Unmarshal(data, doc, jsonOpts); err != nil {
return nil, err
}
if err := l.collectResolveRefs(doc); err != nil {
return nil, err
}
return doc, doc.Validate()
}