-
Notifications
You must be signed in to change notification settings - Fork 2
/
raml.d.ts
565 lines (478 loc) · 18.5 KB
/
raml.d.ts
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
// TODO: http://raml.org/spec.html#named-parameters-with-multiple-types
// how is this surface on the parser?
// TODO: this is where we left off in the spec doc:
// http://raml.org/spec.html#resource-types-and-traits
/**
*
*/
declare type MarkdownString = string
/**
* One of HTTP, HTTPS
*/
declare type Protocol = string
/**
* One of the following YAML media types:
* - text/yaml
* - text/x-yaml
* - application/yaml
* - application/x-yaml
*
* Any type from the list of IANA MIME Media Types, http://www.iana.org/assignments/media-types
* A custom type that conforms to the regular expression, "application\/[A-Za-z.-0-1]*+?(json|xml)"
*
*/
declare type MediaType = string
declare type SchemaDefinition = string
/**
* Regular expressions MUST follow the regular expression specification from ECMA 262/Perl 5.
*/
declare type RegexPattern = string
/**
* A valid HTTP method name in lowercase ( "put", "get", ... )
*/
declare type HTTPMethodName = string
/**
* One of:
*
* - OAuth 1.0
* - OAuth 2.0
* - Basic Authentication
* - Digest Authentication
* - x-{other}
*
* @see http://raml.org/spec.html#type-1
*/
declare type SecuritySchemeType = string
interface Api {
// TODO: what do we do with required types?
// is the JS parser failing when such properties are missing?
/**
*
* (Required) The title property is a short plain text description of the RESTful API.
* The title property's value SHOULD be suitable for use as a title for the contained user documentation.
*
* @see http://raml.org/spec.html#api-title
*/
title: string
/**
* (Optional) If the RAML API definition is targeted to a specific API version, the API definition MUST contain a version property. The version property is OPTIONAL and should not be used if:
*
* The API itself is not versioned.
* The API definition does not change between versions. The API architect can decide whether a change to user documentation elements, but no change to the API's resources, constitutes a version change.
* The API architect MAY use any versioning scheme so long as version numbers retain the same format. For example, "v3", "v3.0", and "V3" are all allowed, but are not considered to be equal.
*/
version?: string
/**
*
* @see http://raml.org/spec.html#base-uri-and-baseuriparameters
*/
baseUri?: string
/**
* @see http://raml.org/spec.html#base-uri-and-baseuriparameters
*/
baseUriParameters?: NamedParameterMap
/**
* (Optional) A RESTful API can be reached HTTP, HTTPS, or both.
* The protocols property MAY be used to specify the protocols that an API supports.
* If the protocols property is not specified, the protocol specified at the baseUri property is used.
* The protocols property MUST be an array of strings, of values "HTTP" and/or "HTTPS".
*
* @see http://raml.org/spec.html#protocols
*/
protocols?: Protocol[]
/**
* (Optional) The media types returned by API responses, and expected from API requests that accept a body,
* MAY be defaulted by specifying the mediaType property.
* This property is specified at the root level of the API definition.
* The property's value MAY be a single string with a valid media type
*
* @see http://raml.org/spec.html#default-media-type
*/
mediaType?: MediaType
/**
* (Optional) To better achieve consistency and simplicity,
* the API definition SHOULD include an OPTIONAL schemas property in the root section.
* The schemas property specifies collections of schemas that could be used anywhere in the API definition.
* The value of the schemas property is an array of maps; in each map, the keys are the schema name,
* and the values are schema definitions.
*
* @see http://raml.org/spec.html#schemas
*/
schemas?: {[ schemaName: string ]: SchemaDefinition }[]
// TODO: verify on JS parser output
/**
*
* (Optional) In addition to the reserved URI parameters described in the baseUri property section,
* a Level 1 Template URI can feature custom URI parameters, which are useful in a variety of scenarios.
* For example, let's look at the following API provider that parameterizes the base URI with customer
* information such as the company name.
*
* @see http://raml.org/spec.html#uri-parameters
*/
uriParameters?: NamedParameterMap
/**
* (Optional) The API definition can include a variety of documents that serve as a user guides
* and reference documentation for the API. Such documents can clarify how the API works
* or provide business context.
*
* @see http://raml.org/spec.html#user-documentation
*/
documentation?: DocumentationItem[]
/**
* @see http://raml.org/spec.html#resources-and-nested-resources
*/
resources?: Resource[]
/**
*
* @see http://raml.org/spec.html#resource-types-and-traits
*/
resourceTypes?: {[ resourceTypeName: string ]: ResourceType }[]
securitySchemes?: {[ securitySchemeName: string ]: SecurityScheme }[]
traits?: {[ traitName: string ]: Trait }[]
securedBy?: string[]
}
interface Resource {
relativeUri: string
relativeUriPathSegments: string[]// required?
/**
* The displayName attribute provides a friendly name to the resource and can be used by documentation generation tools.
* The displayName key is OPTIONAL.
*
* If the displayName attribute is not defined for a resource,
* documentation tools SHOULD refer to the resource by its property key (i.e. its relative URI, e.g., "/jobs"),
* which acts as the resource's name.
*
* @see http://raml.org/spec.html#display-name
*/
displayName?: string
/**
* Each resource, whether top-level or nested, MAY contain a description property that briefly describes the resource.
* It is RECOMMENDED that all the API definition's resources includes the description property.
*
* @see http://raml.org/spec.html#description-1
*/
description?: MarkdownString
is?: string | Trait
/**
*
* In a RESTful API, methods are operations that are performed on a resource.
* A method MUST be one of the HTTP methods defined
* in the HTTP version 1.1 specification [RFC2616] and its extension, RFC5789 [RFC5789].
*
* @see http://raml.org/spec.html#methods
*/
methods?: Method[]
type?: string | ResourceType
/**
* @see http://raml.org/spec.html#template-uris-and-uri-parameters
*/
uriParameters?: NamedParameterMap
/**
*
* A resource or a method can override a base URI template's values.
* This is useful to restrict or change the default or parameter selection in the base URI.
* The baseUriParameters property MAY be used to override any or all parameters
* defined at the root level baseUriParameters property,
* as well as base URI parameters not specified at the root level.
*
* @see http://raml.org/spec.html#base-uri-parameters
*/
baseUriParameters?: NamedParameterMap
resources?: Resource[]
securedBy?: string
}
/**
*
* In a RESTful API, methods are operations that are performed on a resource.
* A method MUST be one of the HTTP methods defined in the HTTP version 1.1 specification [RFC2616]
* and its extension, RFC5789 [RFC5789].
*
* @see http://raml.org/spec.html#methods
*/
interface Method {
/**
* The HTTP verb corresponding to this method
*/
method: HTTPMethodName
/**
*
* Each declared method MAY contain a description attribute that briefly describes
* what the method does to the resource.
* It is RECOMMENDED that all API definition methods include the description property.
*
* The value of the description property MAY be formatted using Markdown [MARKDOWN].
*
* @see http://raml.org/spec.html#description-2
*/
description?: MarkdownString
/**
* A method can override an API's protocols value for that single method by setting a different value for the fields.
*
* @see http://raml.org/spec.html#protocols-1
*/
protocols?: Protocol[]
/**
*
* An API's resources MAY be filtered (to return a subset of results)
* or altered (such as transforming a response body from JSON to XML format)
* by the use of query strings.
*
* If the resource or its method supports a query string, the query string
* MUST be defined by the queryParameters property.
*
* @see http://raml.org/spec.html#query-strings
*/
queryParameters?: NamedParameterMap
/**
*
* Resource methods MAY have one or more responses.
* Responses MAY be described using the description property, and MAY include example attributes or schema properties.
*
* @see http://raml.org/spec.html#responses
*/
responses?: Responses
securedBy?: string
/**
*
* Some method verbs expect the resource to be sent as a request body.
* For example, to create a resource, the request must include the details of the resource to create.
*
* Resources CAN have alternate representations.
* For example, an API might support both JSON and XML representations.
*
* If the API's media type is either application/x-www-form-urlencoded or multipart/form-data,
* the formParameters property MUST specify the name-value pairs that the API is expecting.
*
* @see http://raml.org/spec.html#body
*/
body?: Bodies
/**
*
* An API's methods MAY support or require non-standard HTTP headers.
* In the API definition, specify the non-standard HTTP headers by using the headers property.
*
* @see http://raml.org/spec.html#headers
*/
headers?: NamedParameterMap
}
interface ResourceType {
description?: string
uriParameters?: NamedParameterMap
// TODO
"get?"?: Method
"post?"?: Method
"put?"?: Method
"delete?"?: Method
}
/**
* Each document MUST contain title and content attributes,
* both of which are REQUIRED.
* Documentation-generators MUST process the content field as if it was defined using Markdown [MARKDOWN].
*
* @see http://raml.org/spec.html#user-documentation
*/
interface DocumentationItem {
title: string
content: MarkdownString
}
/**
*
* Resource methods MAY have one or more responses.
*
* @see http://raml.org/spec.html#responses
*/
interface Response {
/**
* Responses MAY contain a description property that further clarifies why the response was emitted.
* Response descriptions are particularly useful for describing error conditions.
*/
description?: MarkdownString
/**
* An API's methods may support custom header values in responses.
* The custom, non-standard HTTP headers MUST be specified by the headers property.
*
* @see http://raml.org/spec.html#headers-1
*/
headers?: NamedParameterMap
body?: Bodies
}
/**
* @see http://raml.org/spec.html#security
*/
interface SecurityScheme {
type?: SecuritySchemeType
description?: MarkdownString
settings?: { [ settingName: string ]: string }
describedBy?: SecuritySchemeDescription
}
interface SecuritySchemeDescription {
uriParameters?: NamedParameterMap
headers?: NamedParameterMap
responses?: Responses
}
// TODO
interface Trait {
description?: MarkdownString
}
interface Bodies {
"application/x-www-form-urlencoded"?: WebFormBodyPayload;
"multipart/form-data"?: WebFormBodyPayload;
[ mediaType: string ]: BodyPayload
}
interface BodyPayload {
/**
* The structure of a request or response body MAY be further specified by the schema property under the appropriate media type.
*
* All parsers of RAML MUST be able to interpret JSON Schema [JSON_SCHEMA] and XML Schema [XML_SCHEMA].
*
* Alternatively, the value of the schema field MAY be the name of a schema specified in the
* root-level schemas property
*
* @see http://raml.org/spec.html#schema
*/
schema?: string | SchemaDefinition
/**
* @see http://raml.org/spec.html#example-4
*/
example?: string
}
/**
* @see: http://raml.org/spec.html#web-forms
*/
interface WebFormBodyPayload {
formParameters: NamedParameterMap
/**
* @see http://raml.org/spec.html#example-4
*/
example?: string
}
interface Responses { [ statusCode: string ]: Response } // [statusCode:string]: Response | Null
interface NamedParameterMap { [ parameterName: string ]: NamedParameter | NamedParameter[] }
/**
* @see http://raml.org/spec.html#named-parameters
*/
interface BasicNamedParameter {
/**
* (Optional) The description attribute describes the intended use or meaning of the parameter.
* This value MAY be formatted using Markdown [MARKDOWN].
*
* @see http://raml.org/spec.html#description
*/
description?: MarkdownString
/**
* (Optional) The displayName attribute specifies the parameter's display name.
* It is a friendly name used only for display or documentation purposes.
* If displayName is not specified, it defaults to the property's key (the name of the property itself).
*
* @see http://raml.org/spec.html#displayname
*/
displayName?: string
/**
* (Optional, applicable only for parameters of type string)
* The enum attribute provides an enumeration of the parameter's valid values.
* This MUST be an array.
*
* If the enum attribute is defined, API clients and servers MUST verify
* that a parameter's value matches a value in the enum array.
*
* If there is no matching value, the clients and servers MUST treat this as an error.
*
* @see http://raml.org/spec.html#enum
*/
'enum'?: any[]
// TODO: types should be a string enum. They are not supported by Typescript at the moment
/**
* (Optional) The type attribute specifies the primitive type of the parameter's resolved value.
* API clients MUST return/throw an error if the parameter's resolved value does not match the specified type.
* If type is not specified, it defaults to string.
*
* @see http://raml.org/spec.html#type
*/
type?: string
// TODO: verify on JS parser output
/**
* (Optional) The example attribute shows an example value for the property.
* This can be used, e.g., by documentation generators to generate sample values for the property.
*
* @see http://raml.org/spec.html#example
*/
example?: any // or string?
// TODO: verify on JS parser output
/**
* (Optional) The repeat attribute specifies that the parameter can be repeated.
* If the parameter can be used multiple times, the repeat parameter value MUST be set to 'true'.
* Otherwise, the default value is 'false' and the parameter may not be repeated.
*
* @see http://raml.org/spec.html#repeat
*/
repeat?: boolean
// TODO: verify on JS parser output
/**
* (Optional except as otherwise noted)
* The required attribute specifies whether the parameter and its value MUST be present in the API definition.
* It must be either 'true' if the value MUST be present or 'false' otherwise.
* In general, parameters are optional unless the required attribute is included and its value set to 'true'.
* For a URI parameter, the required attribute MAY be omitted, but its default value is 'true'.
*
* @see http://raml.org/spec.html#required
*/
required?: boolean
// TODO: verify on JS parser output
/**
* (Optional)
* The default attribute specifies the default value to use for the property if the property is omitted
* or its value is not specified.
* This SHOULD NOT be interpreted as a requirement for the client to send the default attribute's value
* if there is no other value to send. Instead, the default attribute's value is the value the server uses
* if the client does not send a value.
*/
'default'?: any
}
interface NumericNamedParameter extends BasicNamedParameter {
// TODO: verify on JS parser output
/**
* (Optional, applicable only for parameters of type number or integer)
* The minimum attribute specifies the parameter's minimum value.
*
* @see http://raml.org/spec.html#minimum
*/
minimum?: number
// TODO: verify on JS parser output
/**
* (Optional, applicable only for parameters of type number or integer)
* The maximum attribute specifies the parameter's maximum value.
*
* @see http://raml.org/spec.html#maximum
*/
maximum?: number
}
interface StringNamedParameter extends BasicNamedParameter {
// TODO: verify on JS parser output
/**
* (Optional, applicable only for parameters of type string)
*
* The pattern attribute is a regular expression that a parameter of type string MUST match.
* The pattern MAY be enclosed in double quotes for readability and clarity.
* ( in the JS parser. are the quotes preserved? )
*
* @see http://raml.org/spec.html#pattern
*/
pattern?: RegexPattern
// TODO: verify on JS parser output
/**
* (Optional, applicable only for parameters of type string)
* The minLength attribute specifies the parameter value's minimum number of characters.
*
* @see http://raml.org/spec.html#minlength
*/
minLength?: number
// TODO: verify on JS parser output
/**
* (Optional, applicable only for parameters of type string)
* The maxLength attribute specifies the parameter value's maximum number of characters.
*
* @see http://raml.org/spec.html#maxlength
*/
maxLength?: number
}
declare type NamedParameter = BasicNamedParameter | NumericNamedParameter | StringNamedParameter