blob: 9c40833e7da98b0b3aa8a8bc99f15d00ad187c45 [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001// Package swagger implements the structures of the Swagger
2// https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md
3package swagger
4
5const swaggerVersion = "1.2"
6
7// 4.3.3 Data Type Fields
8type DataTypeFields struct {
9 Type *string `json:"type,omitempty"` // if Ref not used
10 Ref *string `json:"$ref,omitempty"` // if Type not used
11 Format string `json:"format,omitempty"`
12 DefaultValue Special `json:"defaultValue,omitempty"`
13 Enum []string `json:"enum,omitempty"`
14 Minimum string `json:"minimum,omitempty"`
15 Maximum string `json:"maximum,omitempty"`
16 Items *Item `json:"items,omitempty"`
17 UniqueItems *bool `json:"uniqueItems,omitempty"`
18}
19
20type Special string
21
22// 4.3.4 Items Object
23type Item struct {
24 Type *string `json:"type,omitempty"`
25 Ref *string `json:"$ref,omitempty"`
26 Format string `json:"format,omitempty"`
27}
28
29// 5.1 Resource Listing
30type ResourceListing struct {
31 SwaggerVersion string `json:"swaggerVersion"` // e.g 1.2
32 Apis []Resource `json:"apis"`
33 ApiVersion string `json:"apiVersion"`
34 Info Info `json:"info"`
35 Authorizations []Authorization `json:"authorizations,omitempty"`
36}
37
38// 5.1.2 Resource Object
39type Resource struct {
40 Path string `json:"path"` // relative or absolute, must start with /
41 Description string `json:"description"`
42}
43
44// 5.1.3 Info Object
45type Info struct {
46 Title string `json:"title"`
47 Description string `json:"description"`
48 TermsOfServiceUrl string `json:"termsOfServiceUrl,omitempty"`
49 Contact string `json:"contact,omitempty"`
50 License string `json:"license,omitempty"`
51 LicenseUrl string `json:"licenseUrl,omitempty"`
52}
53
54// 5.1.5
55type Authorization struct {
56 Type string `json:"type"`
57 PassAs string `json:"passAs"`
58 Keyname string `json:"keyname"`
59 Scopes []Scope `json:"scopes"`
60 GrantTypes []GrantType `json:"grandTypes"`
61}
62
63// 5.1.6, 5.2.11
64type Scope struct {
65 // Required. The name of the scope.
66 Scope string `json:"scope"`
67 // Recommended. A short description of the scope.
68 Description string `json:"description"`
69}
70
71// 5.1.7
72type GrantType struct {
73 Implicit Implicit `json:"implicit"`
74 AuthorizationCode AuthorizationCode `json:"authorization_code"`
75}
76
77// 5.1.8 Implicit Object
78type Implicit struct {
79 // Required. The login endpoint definition.
80 loginEndpoint LoginEndpoint `json:"loginEndpoint"`
81 // An optional alternative name to standard "access_token" OAuth2 parameter.
82 TokenName string `json:"tokenName"`
83}
84
85// 5.1.9 Authorization Code Object
86type AuthorizationCode struct {
87 TokenRequestEndpoint TokenRequestEndpoint `json:"tokenRequestEndpoint"`
88 TokenEndpoint TokenEndpoint `json:"tokenEndpoint"`
89}
90
91// 5.1.10 Login Endpoint Object
92type LoginEndpoint struct {
93 // Required. The URL of the authorization endpoint for the implicit grant flow. The value SHOULD be in a URL format.
94 Url string `json:"url"`
95}
96
97// 5.1.11 Token Request Endpoint Object
98type TokenRequestEndpoint struct {
99 // Required. The URL of the authorization endpoint for the authentication code grant flow. The value SHOULD be in a URL format.
100 Url string `json:"url"`
101 // An optional alternative name to standard "client_id" OAuth2 parameter.
102 ClientIdName string `json:"clientIdName"`
103 // An optional alternative name to the standard "client_secret" OAuth2 parameter.
104 ClientSecretName string `json:"clientSecretName"`
105}
106
107// 5.1.12 Token Endpoint Object
108type TokenEndpoint struct {
109 // Required. The URL of the token endpoint for the authentication code grant flow. The value SHOULD be in a URL format.
110 Url string `json:"url"`
111 // An optional alternative name to standard "access_token" OAuth2 parameter.
112 TokenName string `json:"tokenName"`
113}
114
115// 5.2 API Declaration
116type ApiDeclaration struct {
117 SwaggerVersion string `json:"swaggerVersion"`
118 ApiVersion string `json:"apiVersion"`
119 BasePath string `json:"basePath"`
120 ResourcePath string `json:"resourcePath"` // must start with /
121 Info Info `json:"info"`
122 Apis []Api `json:"apis,omitempty"`
123 Models ModelList `json:"models,omitempty"`
124 Produces []string `json:"produces,omitempty"`
125 Consumes []string `json:"consumes,omitempty"`
126 Authorizations []Authorization `json:"authorizations,omitempty"`
127}
128
129// 5.2.2 API Object
130type Api struct {
131 Path string `json:"path"` // relative or absolute, must start with /
132 Description string `json:"description"`
133 Operations []Operation `json:"operations,omitempty"`
134}
135
136// 5.2.3 Operation Object
137type Operation struct {
138 DataTypeFields
139 Method string `json:"method"`
140 Summary string `json:"summary,omitempty"`
141 Notes string `json:"notes,omitempty"`
142 Nickname string `json:"nickname"`
143 Authorizations []Authorization `json:"authorizations,omitempty"`
144 Parameters []Parameter `json:"parameters"`
145 ResponseMessages []ResponseMessage `json:"responseMessages,omitempty"` // optional
146 Produces []string `json:"produces,omitempty"`
147 Consumes []string `json:"consumes,omitempty"`
148 Deprecated string `json:"deprecated,omitempty"`
149}
150
151// 5.2.4 Parameter Object
152type Parameter struct {
153 DataTypeFields
154 ParamType string `json:"paramType"` // path,query,body,header,form
155 Name string `json:"name"`
156 Description string `json:"description"`
157 Required bool `json:"required"`
158 AllowMultiple bool `json:"allowMultiple"`
159}
160
161// 5.2.5 Response Message Object
162type ResponseMessage struct {
163 Code int `json:"code"`
164 Message string `json:"message"`
165 ResponseModel string `json:"responseModel,omitempty"`
166}
167
168// 5.2.6, 5.2.7 Models Object
169type Model struct {
170 Id string `json:"id"`
171 Description string `json:"description,omitempty"`
172 Required []string `json:"required,omitempty"`
173 Properties ModelPropertyList `json:"properties"`
174 SubTypes []string `json:"subTypes,omitempty"`
175 Discriminator string `json:"discriminator,omitempty"`
176}
177
178// 5.2.8 Properties Object
179type ModelProperty struct {
180 DataTypeFields
181 Description string `json:"description,omitempty"`
182}
183
184// 5.2.10
185type Authorizations map[string]Authorization