11package docs
22
3+ // WARNING:
4+ // Most structures in here are an representation of what is defined in default
5+ // Open API Specification documentation, v3.0.3.
6+ //
7+ // [More about it can be found on this link](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md)
8+
9+ // New returns a new instance of OAS structure.
310func New () OAS {
411 initRoutes := RegRoutes {}
512
@@ -9,7 +16,7 @@ func New() OAS {
916}
1017
1118const (
12- OASAnnotationInit = "// @OAS "
19+ oasAnnotationInit = "// @OAS "
1320)
1421
1522// OAS - represents Open API Specification structure, in its approximated Go form.
@@ -24,13 +31,18 @@ type OAS struct {
2431 RegisteredRoutes RegRoutes `yaml:"-"`
2532}
2633
27- // Version is represented in SemVer format.
2834type (
29- Version string
30- URL string
35+ // Version represents a SemVer version.
36+ Version string
37+
38+ // URL represents and URL which is casted from string.
39+ URL string
40+
41+ // OASVersion represents the OpenAPISpecification version which will be used.
3142 OASVersion Version
3243)
3344
45+ // Info represents OAS info object.
3446type Info struct {
3547 Title string `yaml:"title"`
3648 Description string `yaml:"description"`
@@ -40,36 +52,47 @@ type Info struct {
4052 Version Version `yaml:"version"`
4153}
4254
55+ // Contact represents OAS contact object, used by Info.
4356type Contact struct {
4457 Email string `yaml:"email"`
4558}
4659
60+ // License represents OAS license object, used by Info.
4761type License struct {
4862 Name string `yaml:"name"`
4963 URL URL `yaml:"url"`
5064}
5165
66+ // ExternalDocs represents OAS externalDocs object.
67+ //
68+ // Aside from base OAS structure, this is also used by Tag object.
5269type ExternalDocs struct {
5370 Description string `yaml:"description"`
5471 URL URL `yaml:"url"`
5572}
5673
74+ // Servers is a slice of Server objects.
5775type Servers []Server
5876
77+ // Server represents OAS server object.
5978type Server struct {
6079 URL URL `yaml:"url"`
6180}
6281
82+ // Tags is a slice of Tag objects.
6383type Tags []Tag
6484
85+ // Tag represents OAS tag object.
6586type Tag struct {
6687 Name string `yaml:"name"`
6788 Description string `yaml:"description"`
6889 ExternalDocs ExternalDocs `yaml:"externalDocs"`
6990}
7091
92+ // Paths is a slice of Path objects.
7193type Paths []Path
7294
95+ // Path represents OAS path object.
7396type Path struct {
7497 Route string `yaml:"route"`
7598 HTTPMethod string `yaml:"httpMethod"`
@@ -82,43 +105,54 @@ type Path struct {
82105 HandlerFuncName string `yaml:"-"`
83106}
84107
108+ // RequestBody represents OAS requestBody object, used by Path.
85109type RequestBody struct {
86110 Description string `yaml:"description"`
87111 Content ContentTypes `yaml:"content"`
88112 Required bool `yaml:"required"`
89113}
90114
115+ // ContentTypes is a slice of ContentType objects.
91116type ContentTypes []ContentType
92117
118+ // ContentType represents OAS content type object, used by RequestBody and Response.
93119type ContentType struct {
94120 Name string `yaml:"ct-name"` // e.g. application/json
95121 Schema string `yaml:"ct-schema"` // e.g. $ref: '#/components/schemas/Pet'
96122}
97123
124+ // Responses is a slice of Response objects.
98125type Responses []Response
99126
127+ // Response represents OAS response object, used by Path.
100128type Response struct {
101129 Code uint `yaml:"code"`
102130 Description string `yaml:"description"`
103131 Content ContentTypes `yaml:"content"`
104132}
105133
134+ // SecurityEntities is a slice of Security objects.
106135type SecurityEntities []Security
107136
137+ // Security represents OAS security object.
108138type Security struct {
109139 AuthName string
110140 PermTypes []string // write:pets , read:pets etc.
111141}
112142
143+ // Components is a slice of Component objects.
113144type Components []Component
114145
146+ // Component represents OAS component object.
115147type Component struct {
116148 Schemas Schemas `yaml:"schemas"`
117149 SecuritySchemes SecuritySchemes `yaml:"securitySchemes"`
118150}
119151
152+ // Schemas is a slice of Schema objects.
120153type Schemas []Schema
121154
155+ // Schema represents OAS schema object, used by Component.
122156type Schema struct {
123157 Name string
124158 Type string
@@ -127,11 +161,15 @@ type Schema struct {
127161 Ref string // $ref: '#/components/schemas/Pet' // TODO: Should this be omitted if empty?
128162}
129163
164+ // XMLEntry represents name of XML entry in Schema object.
130165type XMLEntry struct {
131166 Name string
132167}
168+
169+ // SchemaProperties is a slice of SchemaProperty objects.
133170type SchemaProperties []SchemaProperty
134171
172+ // SchemaProperty represents OAS schema object, used by Schema.
135173type SchemaProperty struct {
136174 Name string `yaml:"-"`
137175 Type string // OAS3.0 data types - e.g. integer, boolean, string
@@ -141,30 +179,37 @@ type SchemaProperty struct {
141179 Default interface {} `yaml:"default,omitempty"`
142180}
143181
182+ // SecuritySchemes is a slice of SecuritySchemes objects.
144183type SecuritySchemes []SecurityScheme
145184
185+ // SecurityScheme represents OAS security object, used by Component.
146186type SecurityScheme struct {
147187 Name string `yaml:"name,omitempty"`
148188 Type string `yaml:"type,omitempty"`
149189 In string `yaml:"in,omitempty"`
150190 Flows SecurityFlows `yaml:"flows,omitempty"`
151191}
152192
193+ // SecurityFlows is a slice of SecurityFlow objects.
153194type SecurityFlows []SecurityFlow
154195
196+ // SecurityFlow represents OAS Flows object, used by SecurityScheme.
155197type SecurityFlow struct {
156198 Type string `yaml:"type,omitempty"`
157199 AuthURL URL `yaml:"authorizationUrl,omitempty"`
158200 Scopes SecurityScopes `yaml:"scopes,omitempty"`
159201}
160202
203+ // SecurityScopes is a slice of SecurityScope objects.
161204type SecurityScopes []SecurityScope
162205
206+ // SecurityScope represents OAS SecurityScope object, used by SecurityFlow.
163207type SecurityScope struct {
164208 Name string `yaml:"name,omitempty"`
165209 Description string `yaml:"description,omitempty"`
166210}
167211
212+ // isEmpty checks if *ExternalDocs struct is empty.
168213func (ed * ExternalDocs ) isEmpty () bool {
169214 if ed == nil {
170215 return true
0 commit comments