-
Notifications
You must be signed in to change notification settings - Fork 0
/
components.go
76 lines (69 loc) · 2.08 KB
/
components.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
72
73
74
75
76
package chioas
import "github.com/go-andiamo/chioas/yaml"
// CommonRequests is a map of Request, where the key is the name (that can be referenced by Request.Ref)
type CommonRequests map[string]Request
// CommonResponses is a map of Response, where the key is the name (that can be referenced by Response.Ref)
type CommonResponses map[string]Response
// Components represents the OAS components
type Components struct {
// Schemas is the OAS reusable schemas
Schemas Schemas
// Requests is the OAS reusable requests
//
// To reference one of these, use Method.Request.Ref with the name
Requests CommonRequests
// Responses is the OAS reusable responses
//
// To reference one of these, use Method.Response.Ref with the name
Responses CommonResponses
// Examples is the OAS reusable examples
//
// To reference one of these, use Example.Ref with the name
Examples Examples
// Parameters is the OAS reusable parameters
Parameters CommonParameters
// SecuritySchemes is the OAS security schemes
SecuritySchemes SecuritySchemes
// Extensions is extension OAS yaml properties
Extensions Extensions
// Additional is any additional OAS spec yaml to be written
Additional Additional
// Comment is any comment(s) to appear in the OAS spec yaml
Comment string
}
func (c *Components) writeYaml(w yaml.Writer) {
w.WriteComments(c.Comment).WriteTagStart(tagNameComponents)
c.Schemas.writeYaml(w)
if c.Requests != nil {
c.Requests.writeYaml(w)
}
if c.Responses != nil {
c.Responses.writeYaml(w)
}
if c.Parameters != nil {
c.Parameters.writeYaml(w)
}
c.Examples.writeYaml(w)
c.SecuritySchemes.writeYaml(w, false)
writeExtensions(c.Extensions, w)
writeAdditional(c.Additional, c, w)
w.WriteTagEnd()
}
func (r CommonRequests) writeYaml(w yaml.Writer) {
if len(r) > 0 {
w.WriteTagStart(tagNameRequestBodies)
for name, rr := range r {
rr.componentsWriteYaml(name, w)
}
w.WriteTagEnd()
}
}
func (r CommonResponses) writeYaml(w yaml.Writer) {
if len(r) > 0 {
w.WriteTagStart(tagNameResponses)
for name, rr := range r {
rr.componentsWriteYaml(name, w)
}
w.WriteTagEnd()
}
}