forked from jsightapi/jsight-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsight-server-api.jst
381 lines (323 loc) · 11.9 KB
/
jsight-server-api.jst
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
JSIGHT 0.3
INFO
Title "JSight Server API"
Version "2.0.0"
Description
(
# Introduction
The file describes the JSight Server API, which is used in [JSight Online Editor](https://editor.jsight.io/).
# Requirements to this API
Schema must be:
- compact (will be transmitted over network),
- comfortable for document rendering algorithm,
- easy for reading by man (will be used for functional automatically tests).
# Format size optimization options (for the future)
1. Discard fields that are easily calculated, for example, the json Type field is easily calculated from the content.
2. Frequent fields should be named with one letter, for example, 't' instead of 'type'.
3. Abandon structures that are easily calculated, for example, 'allOf'.
)
POST /parse-jsight
Description
You should send JSight code in request.
Request
Headers
{
"X-Browser-UUID": "123e4567-e89b-12d3-a456-426614174000"
}
Body any # JSight code
200 @jdocExchange // Successfully parsed response.
Headers
{
"X-Jdoc-Exchange-Version": "2.0.0"
}
409 @error // Any parsing error.
TYPE @error
{
"Status": "Error", // {const: true}
"Message": "Error message",
"Line": 10, // {optional: true, min: 0}
"Index": 20 // {optional: true, min: 0}
}
TYPE @jdocExchange
{
"jdocExchangeVersion": "2.0.0", // {const: true}
"jsight": "0.3", // {const: true}
"info": { // {optional: true}
"title": "Catsbook API.", // {optional: true}
"version": "0.1", // {optional: true}
"description": "Catsbook social network public REST API." // {optional: true}
},
"servers": { // {additionalProperties: "@server", optional: true}
@serverName: @server // { optional: true }
},
"tags": { // {additionalProperties: "@tag"}
@tagName: @tag // {optional: true}
},
"interactions": { // {additionalProperties: "@interaction"}
@interactionId : @interaction // { optional: true }
},
"userTypes": { // {additionalProperties: "@userType", optional: true}
@userTypeName: @userType // {optional: true}
},
"userEnums": { // {additionalProperties: "@userRule", optional: true}
@userRuleName : @userRule // {optional: true}
}
}
TYPE @interaction
@httpInteraction | @jsonRpcInteraction
TYPE @interactionId
@httpInteractionId | @jsonRpcInteractionId
TYPE @httpInteractionId
"http GET /cats/{id}" // {regex: "^http (?:GET|POST|PUT|PATCH|DELETE) \/.*"}
TYPE @jsonRpcInteractionId
"json-rpc-2.0 /cats foo" // {regex: "^json-rpc-2.0 \/.* .+"}
#---------------------------------------------- TAG -----------------------------------------------
TYPE @tagName regex
/@[A-Za-z0-1_]/
TYPE @tag
{
"name" : "@cats",
"title" : "/cats",
"annotation" : "Brief description of the tag",
"description" : "Tag description", // {optional: true}
"interactionGroups" : [
@tagInteractionGroup,
@tagInteractionGroup
],
"children" : { // {additionalProperties: "@tagName", optional: true}
@tagName : @tag // {optional: true}
}
}
TYPE @tagInteractionGroup
@tagHttpInteractionGroup | @tagJsonRpcInteractionGroup
TYPE @tagJsonRpcInteractionGroup
{
"protocol": "json-rpc-2.0", // {const: true}
"interactions": [
@jsonRpcInteractionId,
@jsonRpcInteractionId
]
}
TYPE @tagHttpInteractionGroup
{
"protocol": "http", // {const: true}
"interactions": [
@httpInteractionId,
@httpInteractionId
]
}
#--------------------------------------------- JSON RPC -------------------------------------------
TYPE @jsonRpcInteraction
{
"id" : "json-rpc-2.0 /cats foo", // {type: "@jsonRpcInteractionId"}
"protocol" : "json-rpc-2.0", // {const: true}
"path" : "/cats", // {type: "@path"}
"method" : "foo",
"pathVariables": { // {optional: true}
"schema": @schema
},
"tags": [
@tagName
],
"annotation" : "Method annotation.", // {optional: true}
"description": "Method description.", // {optional: true}
# "query" : @query, // {optional: true}
"params": @schema, // {optional: true}
"result": @schema // {optional: true}
}
#----------------------------------------------- HTTP ---------------------------------------------
TYPE @httpMethodName
"GET" // {enum: ["GET", "POST", "PUT", "PATCH", "DELETE"]}
TYPE @httpInteraction
{
"id" : "http GET /cats", // {type: "@httpInteractionId"}
"protocol" : "http", // {const: true}
"httpMethod" : "GET", // {type: "@httpMethodName"}
"path" : "/cats", // {type: "@path"}
"pathVariables": { // {optional: true}
"schema": @schema
},
"tags": [
"@cats", // {type: "@tagName"}
"@pets", // {type: "@tagName"}
"@readMethods" // {type: "@tagName"}
],
"annotation" : "Retrieve cats' list.", // {optional: true}
"description": "Allows to retrieve all the cats' list.", // {optional: true}
// Request
"query" : @query, // {optional: true}
"request": @httpRequest, // {optional: true}
// Answers
"responses": [ /* {optional: true}
- An array is used because there can be multiple responses with the same code. */
@httpResponse
]
}
#--------------------------------------------- QUERY ---------------------------------------------
TYPE @query
{
"example": "fields=id,name,size&access_token=qwequhpijdfhhwehuuhsdf", // {optional: true}
"format" : "htmlFormEncoded", // {type: "@serializeFormat"}
"schema" : @schema
}
#--------------------------------------------- REQUEST -------------------------------------------
TYPE @httpRequest
{
"headers": { // {optional: true}
"schema": @schema
},
"body": {
"format": "json", // {type: "@serializeFormat"}
"schema": @schema
}
}
#--------------------------------------------- RESPONSE -------------------------------------------
TYPE @httpResponseCode
"200" // {regex: "\\d\\d\\d"}
TYPE @httpResponse
{
"code" : @httpResponseCode,
"annotation": "Description of the successful response.", // {optional: true}
"headers": {
"schema": @schema
},
"body": {
"format": "json", // {type: "@serializeFormat"}
"schema": @schema
}
}
#---------------------------------------------- PATH ----------------------------------------------
TYPE @path
"/cats/{id}/friends/{friend:id}"
#---------------------------------------------- USER TYPE -----------------------------------------
TYPE @userTypeName
"@cat" // {regex: "@[A-Za-z0-9_]+"}
TYPE @userType
{
"annotation" : "A brief description of the type.", // {optional: true}
"description": "A lengthy description of the type.", // {optional: true}
"schema" : @schema
# "links" : [
# @link,
# @link
# ]
}
#---------------------------------------------- USER RULE -----------------------------------------
TYPE @userRuleName
"@cat" // {regex: "@[A-Za-z0-9_]+"}
TYPE @userRule
{
"annotation" : "A brief description of the named rule",
"description": "Description of the named rule",
"value" : @rule
# "links" : [
# @link,
# @link
# ]
}
#---------------------------------------------- LINK ----------------------------------------------
#TYPE @link
#{
# "type": "response.body", // {type: "@linkTypeEnum"}
# "address": @interactionAddress | @serverAddress
#}
#---------------------------------------------- SERVER --------------------------------------------
TYPE @serverName regex
/@[A-Za-z0-9_]+/
TYPE @server
{
"annotation": "Test server", // {optional: true}
"baseUrl": "https://{env}.catsbook.com/api/{version}/{locale}/"
# "baseUrlVariables": { // {optional: true}
# "schema": @schema
# }
}
#---------------------------------------------- SCHEMA --------------------------------------------
TYPE @schema
{
"notation": "jsight", // {type: "@schemaNotation"}
"content" : @jsightSchemaElement | @regexSchema, // {optional: true} - May not be specified for the `any` and `empty` notations.
"usedUserTypes": [ // {optional: true}
"@cat", // {type: "@userTypeName"}
"@dog" // {type: "@userTypeName"}
],
"usedUserEnums": [ // {optional: true}
"@catSizeEnum" // {type: "@userRuleName"}
],
"example": "{\n \"id\": 123\n}" // {optional: true}
}
TYPE @jsightSchemaElement
{
# "parentJsonType" : "array", // {enum: [null, "object", "array"]}
"key" : "cat", // {optional: true, type: "string"} - Specified only if parent tokenType: "object".
"isKeyUserTypeRef" : true, // {optional: true, const: true} - Specified if reference is located in the key.
# "index" : 0, // {optional: true} - Specified only if "parentType": "array".
"tokenType" : "object", // {type: "@tokenTypeEnum"}
"type" : "@cat", /* Calculated or explicitly specified element type (for an element card or a tabular
description of data). */
"optional" : true, // The calculated or explicitly specified value of the optional rule. By default, false.
"scalarValue" : "123", /* {optional: true, type: "string"} - Specified only if the "tokenType" is specified
"string", "number", "boolean", "annotation", "reference" or "null". */
"inheritedFrom" : "@austronaut",/* {type: "@userTypeName", optional: true} - The source of the object property is
specified if it is inherited through the 'allOf' rule. */
"note" : "Note to the \n element of the example.", // {optional: true} - May contain line breaks.
"rules": [ // {optional: true}
@rule
],
"children": [ // {optional: true} - specified only if tokenType: "array" or "object".
@jsightSchemaElement
]
}
TYPE @rule
{
"key" : @ruleNameEnum,
"tokenType" : "object", // {type: "@tokenTypeEnum"}
"scalarValue": "@cat", /* {optional: true} - Specified only if "tokenType" specifies "string", "number", "boolean",
"annotation" or "null". */
# "note" : "Note to the \n rule.", // {optional: true} - May contain line breaks.
"children" : [ // {optional: true} - specified only if tokenType: "array" or "object".
@rule
]
}
TYPE @ruleNameEnum
"minLength" /* {enum: [
"type",
"optional",
"nullable",
"min",
"max",
"exclusiveMinimum",
"exclusiveMaximum",
"precision",
"minLength",
"maxLength",
"regexp",
"minItems",
"maxItems",
"or",
"additionalProperties",
"const",
"serializeFormat",
"serializedType",
"enum",
"allOf"
]} */
TYPE @tokenTypeEnum
"object" /* [
"object",
"array",
"string",
"number",
"boolean",
"null",
"annotation", // This means an interline annotation.
"reference" // It is used when a reference is inserted into the example, for example,
a type name instead of a value
]
*/
TYPE @schemaNotation
"jsight" // {enum: ["jsight", "regex", "any", "empty"]}
TYPE @serializeFormat
"json" // {enum: ["json", "plainString", "binary", "htmlFormEncoded", "noFormat"]}
TYPE @regexSchema
"/Hello, World!/" // {regex: "/.*/"}