blob: 83cb564fa582a3f3430e2c3487a3b11d38e425a4 [file] [log] [blame]
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001syntax = "proto3";
2
3package grpc.gateway.protoc_gen_swagger.options;
4
5option go_package = "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options";
6
7import "google/protobuf/any.proto";
8import "google/protobuf/struct.proto";
9
10// `Swagger` is a representation of OpenAPI v2 specification's Swagger object.
11//
12// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#swaggerObject
13//
14// TODO(ivucica): document fields
15message Swagger {
16 string swagger = 1;
17 Info info = 2;
18 string host = 3;
19 // `base_path` is the common prefix path used on all API endpoints (ie. /api, /v1, etc.). By adding this,
20 // it allows you to remove this portion from the path endpoints in your Swagger file making them easier
21 // to read. Note that using `base_path` does not change the endpoint paths that are generated in the resulting
22 // Swagger file. If you wish to use `base_path` with relatively generated Swagger paths, the
23 // `base_path` prefix must be manually removed from your `google.api.http` paths and your code changed to
24 // serve the API from the `base_path`.
25 string base_path = 4;
26 enum SwaggerScheme {
27 UNKNOWN = 0;
28 HTTP = 1;
29 HTTPS = 2;
30 WS = 3;
31 WSS = 4;
32 }
33 repeated SwaggerScheme schemes = 5;
34 repeated string consumes = 6;
35 repeated string produces = 7;
36 // field 8 is reserved for 'paths'.
37 reserved 8;
38 // field 9 is reserved for 'definitions', which at this time are already
39 // exposed as and customizable as proto messages.
40 reserved 9;
41 map<string, Response> responses = 10;
42 SecurityDefinitions security_definitions = 11;
43 repeated SecurityRequirement security = 12;
44 // field 13 is reserved for 'tags', which are supposed to be exposed as and
45 // customizable as proto services. TODO(ivucica): add processing of proto
46 // service objects into OpenAPI v2 Tag objects.
47 reserved 13;
48 ExternalDocumentation external_docs = 14;
49 map<string, google.protobuf.Value> extensions = 15;
50}
51
52// `Operation` is a representation of OpenAPI v2 specification's Operation object.
53//
54// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#operationObject
55//
56// TODO(ivucica): document fields
57message Operation {
58 repeated string tags = 1;
59 string summary = 2;
60 string description = 3;
61 ExternalDocumentation external_docs = 4;
62 string operation_id = 5;
63 repeated string consumes = 6;
64 repeated string produces = 7;
65 // field 8 is reserved for 'parameters'.
66 reserved 8;
67 map<string, Response> responses = 9;
68 repeated string schemes = 10;
69 bool deprecated = 11;
70 repeated SecurityRequirement security = 12;
71 map<string, google.protobuf.Value> extensions = 13;
72}
73
74// `Response` is a representation of OpenAPI v2 specification's Response object.
75//
76// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#responseObject
77//
78message Response {
79 // `Description` is a short description of the response.
80 // GFM syntax can be used for rich text representation.
81 string description = 1;
82 // `Schema` optionally defines the structure of the response.
83 // If `Schema` is not provided, it means there is no content to the response.
84 Schema schema = 2;
85 // field 3 is reserved for 'headers'.
86 reserved 3;
87 // field 3 is reserved for 'example'.
88 reserved 4;
89 map<string, google.protobuf.Value> extensions = 5;
90}
91
92// `Info` is a representation of OpenAPI v2 specification's Info object.
93//
94// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#infoObject
95//
96// TODO(ivucica): document fields
97message Info {
98 string title = 1;
99 string description = 2;
100 string terms_of_service = 3;
101 Contact contact = 4;
102 License license = 5;
103 string version = 6;
104 map<string, google.protobuf.Value> extensions = 7;
105}
106
107// `Contact` is a representation of OpenAPI v2 specification's Contact object.
108//
109// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#contactObject
110//
111// TODO(ivucica): document fields
112message Contact {
113 string name = 1;
114 string url = 2;
115 string email = 3;
116}
117
118// `License` is a representation of OpenAPI v2 specification's License object.
119//
120// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#licenseObject
121//
122message License {
123 // Required. The license name used for the API.
124 string name = 1;
125 // A URL to the license used for the API.
126 string url = 2;
127}
128
129// `ExternalDocumentation` is a representation of OpenAPI v2 specification's
130// ExternalDocumentation object.
131//
132// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#externalDocumentationObject
133//
134// TODO(ivucica): document fields
135message ExternalDocumentation {
136 string description = 1;
137 string url = 2;
138}
139
140// `Schema` is a representation of OpenAPI v2 specification's Schema object.
141//
142// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#schemaObject
143//
144// TODO(ivucica): document fields
145message Schema {
146 JSONSchema json_schema = 1;
147 string discriminator = 2;
148 bool read_only = 3;
149 // field 4 is reserved for 'xml'.
150 reserved 4;
151 ExternalDocumentation external_docs = 5;
152 google.protobuf.Any example = 6;
153}
154
155// `JSONSchema` represents properties from JSON Schema taken, and as used, in
156// the OpenAPI v2 spec.
157//
158// This includes changes made by OpenAPI v2.
159//
160// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#schemaObject
161//
162// See also: https://cswr.github.io/JsonSchema/spec/basic_types/,
163// https://github.com/json-schema-org/json-schema-spec/blob/master/schema.json
164//
165// TODO(ivucica): document fields
166message JSONSchema {
167 // field 1 is reserved for '$id', omitted from OpenAPI v2.
168 reserved 1;
169 // field 2 is reserved for '$schema', omitted from OpenAPI v2.
170 reserved 2;
171 // Ref is used to define an external reference to include in the message.
172 // This could be a fully qualified proto message reference, and that type must be imported
173 // into the protofile. If no message is identified, the Ref will be used verbatim in
174 // the output.
175 // For example:
176 // `ref: ".google.protobuf.Timestamp"`.
177 string ref = 3;
178 // field 4 is reserved for '$comment', omitted from OpenAPI v2.
179 reserved 4;
180 string title = 5;
181 string description = 6;
182 string default = 7;
183 bool read_only = 8;
184 // field 9 is reserved for 'examples', which is omitted from OpenAPI v2 in favor of 'example' field.
185 reserved 9;
186 double multiple_of = 10;
187 double maximum = 11;
188 bool exclusive_maximum = 12;
189 double minimum = 13;
190 bool exclusive_minimum = 14;
191 uint64 max_length = 15;
192 uint64 min_length = 16;
193 string pattern = 17;
194 // field 18 is reserved for 'additionalItems', omitted from OpenAPI v2.
195 reserved 18;
196 // field 19 is reserved for 'items', but in OpenAPI-specific way. TODO(ivucica): add 'items'?
197 reserved 19;
198 uint64 max_items = 20;
199 uint64 min_items = 21;
200 bool unique_items = 22;
201 // field 23 is reserved for 'contains', omitted from OpenAPI v2.
202 reserved 23;
203 uint64 max_properties = 24;
204 uint64 min_properties = 25;
205 repeated string required = 26;
206 // field 27 is reserved for 'additionalProperties', but in OpenAPI-specific way. TODO(ivucica): add 'additionalProperties'?
207 reserved 27;
208 // field 28 is reserved for 'definitions', omitted from OpenAPI v2.
209 reserved 28;
210 // field 29 is reserved for 'properties', but in OpenAPI-specific way. TODO(ivucica): add 'additionalProperties'?
211 reserved 29;
212 // following fields are reserved, as the properties have been omitted from OpenAPI v2:
213 // patternProperties, dependencies, propertyNames, const
214 reserved 30 to 33;
215 // Items in 'array' must be unique.
216 repeated string array = 34;
217
218 enum JSONSchemaSimpleTypes {
219 UNKNOWN = 0;
220 ARRAY = 1;
221 BOOLEAN = 2;
222 INTEGER = 3;
223 NULL = 4;
224 NUMBER = 5;
225 OBJECT = 6;
226 STRING = 7;
227 }
228
229 repeated JSONSchemaSimpleTypes type = 35;
230 // following fields are reserved, as the properties have been omitted from OpenAPI v2:
231 // format, contentMediaType, contentEncoding, if, then, else
232 reserved 36 to 41;
233 // field 42 is reserved for 'allOf', but in OpenAPI-specific way. TODO(ivucica): add 'allOf'?
234 reserved 42;
235 // following fields are reserved, as the properties have been omitted from OpenAPI v2:
236 // anyOf, oneOf, not
237 reserved 43 to 45;
238}
239
240// `Tag` is a representation of OpenAPI v2 specification's Tag object.
241//
242// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#tagObject
243//
244// TODO(ivucica): document fields
245message Tag {
246 // field 1 is reserved for 'name'. In our generator, this is (to be) extracted
247 // from the name of proto service, and thus not exposed to the user, as
248 // changing tag object's name would break the link to the references to the
249 // tag in individual operation specifications.
250 //
251 // TODO(ivucica): Add 'name' property. Use it to allow override of the name of
252 // global Tag object, then use that name to reference the tag throughout the
253 // Swagger file.
254 reserved 1;
255 // TODO(ivucica): Description should be extracted from comments on the proto
256 // service object.
257 string description = 2;
258 ExternalDocumentation external_docs = 3;
259}
260
261// `SecurityDefinitions` is a representation of OpenAPI v2 specification's
262// Security Definitions object.
263//
264// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#securityDefinitionsObject
265//
266// A declaration of the security schemes available to be used in the
267// specification. This does not enforce the security schemes on the operations
268// and only serves to provide the relevant details for each scheme.
269message SecurityDefinitions {
270 // A single security scheme definition, mapping a "name" to the scheme it defines.
271 map<string, SecurityScheme> security = 1;
272}
273
274// `SecurityScheme` is a representation of OpenAPI v2 specification's
275// Security Scheme object.
276//
277// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#securitySchemeObject
278//
279// Allows the definition of a security scheme that can be used by the
280// operations. Supported schemes are basic authentication, an API key (either as
281// a header or as a query parameter) and OAuth2's common flows (implicit,
282// password, application and access code).
283message SecurityScheme {
284 // Required. The type of the security scheme. Valid values are "basic",
285 // "apiKey" or "oauth2".
286 enum Type {
287 TYPE_INVALID = 0;
288 TYPE_BASIC = 1;
289 TYPE_API_KEY = 2;
290 TYPE_OAUTH2 = 3;
291 }
292
293 // Required. The location of the API key. Valid values are "query" or "header".
294 enum In {
295 IN_INVALID = 0;
296 IN_QUERY = 1;
297 IN_HEADER = 2;
298 }
299
300 // Required. The flow used by the OAuth2 security scheme. Valid values are
301 // "implicit", "password", "application" or "accessCode".
302 enum Flow {
303 FLOW_INVALID = 0;
304 FLOW_IMPLICIT = 1;
305 FLOW_PASSWORD = 2;
306 FLOW_APPLICATION = 3;
307 FLOW_ACCESS_CODE = 4;
308 }
309
310 // Required. The type of the security scheme. Valid values are "basic",
311 // "apiKey" or "oauth2".
312 Type type = 1;
313 // A short description for security scheme.
314 string description = 2;
315 // Required. The name of the header or query parameter to be used.
316 //
317 // Valid for apiKey.
318 string name = 3;
319 // Required. The location of the API key. Valid values are "query" or "header".
320 //
321 // Valid for apiKey.
322 In in = 4;
323 // Required. The flow used by the OAuth2 security scheme. Valid values are
324 // "implicit", "password", "application" or "accessCode".
325 //
326 // Valid for oauth2.
327 Flow flow = 5;
328 // Required. The authorization URL to be used for this flow. This SHOULD be in
329 // the form of a URL.
330 //
331 // Valid for oauth2/implicit and oauth2/accessCode.
332 string authorization_url = 6;
333 // Required. The token URL to be used for this flow. This SHOULD be in the
334 // form of a URL.
335 //
336 // Valid for oauth2/password, oauth2/application and oauth2/accessCode.
337 string token_url = 7;
338 // Required. The available scopes for the OAuth2 security scheme.
339 //
340 // Valid for oauth2.
341 Scopes scopes = 8;
342 map<string, google.protobuf.Value> extensions = 9;
343}
344
345// `SecurityRequirement` is a representation of OpenAPI v2 specification's
346// Security Requirement object.
347//
348// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#securityRequirementObject
349//
350// Lists the required security schemes to execute this operation. The object can
351// have multiple security schemes declared in it which are all required (that
352// is, there is a logical AND between the schemes).
353//
354// The name used for each property MUST correspond to a security scheme
355// declared in the Security Definitions.
356message SecurityRequirement {
357 // If the security scheme is of type "oauth2", then the value is a list of
358 // scope names required for the execution. For other security scheme types,
359 // the array MUST be empty.
360 message SecurityRequirementValue {
361 repeated string scope = 1;
362 }
363 // Each name must correspond to a security scheme which is declared in
364 // the Security Definitions. If the security scheme is of type "oauth2",
365 // then the value is a list of scope names required for the execution.
366 // For other security scheme types, the array MUST be empty.
367 map<string, SecurityRequirementValue> security_requirement = 1;
368}
369
370// `Scopes` is a representation of OpenAPI v2 specification's Scopes object.
371//
372// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#scopesObject
373//
374// Lists the available scopes for an OAuth2 security scheme.
375message Scopes {
376 // Maps between a name of a scope to a short description of it (as the value
377 // of the property).
378 map<string, string> scope = 1;
379}