-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathyang-openapi.yang
More file actions
383 lines (377 loc) · 7.66 KB
/
yang-openapi.yang
File metadata and controls
383 lines (377 loc) · 7.66 KB
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
module yang-openapi {
namespace "urn:ietf:params:xml:ns:yang:yang-openapi";
prefix openapi;
yang-version 1.1;
import ietf-inet-types { prefix inet; }
import ietf-yang-types { prefix yang; }
import yang-json-schema { prefix json; }
import yang-meta-types { prefix meta; }
organization
"Corenova Technologies, Inc.";
contact
"Peter K. Lee <peter@corenova.com>";
reference
"https://openapis.org";
/*
* Identities
*/
identity protocol {
description "describes transfer protocol";
}
identity http {
base protocol;
}
identity https {
base protocol;
}
identity ws {
base protocol;
}
identity wss {
base protocol;
}
/*
* Type definitions
*/
typedef mimetype {
type string {
pattern '^.+\/.+$';
}
}
typedef http-status-code {
type uint16 {
range '100..102 | 200..208 | 226 | 300..308 | 400..431 | 500..511';
}
}
typedef http-method {
type enumeration {
enum get;
enum put;
enum post;
enum delete;
enum options;
enum head;
enum patch;
}
}
typedef grouping-identifier {
type string {
length "1..max";
pattern '[\w\-]*:?[a-zA-Z_][a-zA-Z0-9\-_.]*';
pattern '[\w\-]*:?.|..|[^xX].*|.[^mM].*|..[^lL].*';
}
}
/*
* Groupings
*/
grouping info {
description
"Contains metadata information to describe API.";
leaf title { type meta:title; mandatory true; }
leaf description { type meta:description; }
leaf version { type meta:api-version; mandatory true; }
container contact {
leaf name { type meta:person-name; }
leaf url { type inet:uri; }
leaf email { type meta:email-address; }
}
container license {
leaf name { type meta:license; mandatory true; }
leaf url { type inet:uri; }
}
}
grouping parameters-list {
list parameter {
key "name";
leaf name {
type string;
mandatory true;
}
leaf in {
type enumeration {
enum query;
enum header;
enum path;
enum formData;
enum body;
}
mandatory true;
}
leaf description {
type meta:description;
}
leaf required {
type boolean;
default false;
description "if ../in = 'path' this must be true";
}
uses json:json-datatype;
container schema {
when "../in = 'body'";
uses json:json-schema;
}
/* TODO
* allow-empty-value
* items
* collection-format
* default
* maximum
* exclusive-maximum
* minimum
* exclusive-minimum
* max-length
* min-length
* pattern
* max-items
* min-items
* unique-items
* enum
* multiple-of
*/
}
}
grouping response {
leaf description {
type meta:description;
mandatory true;
}
container schema {
uses json:json-schema;
}
list header {
}
list example {
key mime;
leaf mime {
type mimetype;
mandatory true;
}
container data;
}
}
grouping responses-list {
list response {
key code;
leaf code {
type http-status-code;
}
uses openapi:response;
}
}
grouping operations-list {
grouping operation {
leaf-list tags {
type yang:yang-identifier;
}
leaf summary {
type meta:description {
length 0..120;
}
}
leaf description {
type meta:description;
}
leaf operationId {
type string;
}
leaf-list consumes {
type mimetype;
}
leaf-list produces {
type mimetype;
}
leaf-list schemes {
type identityref {
base protocol;
}
}
leaf deprecated {
type boolean;
default false;
}
uses openapi:parameters-list;
uses openapi:responses-list;
list security {
key name;
leaf name;
// TODO
}
}
list operation {
//node:hash "..";
key method;
leaf method {
type http-method;
}
uses operation;
}
}
grouping paths-list {
grouping path-item {
leaf $ref {
type json:json-schema-ref;
}
uses openapi:operations-list;
uses openapi:parameters-list;
}
list path {
key name;
leaf name {
type inet:uri;
}
uses path-item;
min-elements 1;
}
}
grouping definitions-list {
list definition {
key name;
leaf name {
type openapi:grouping-identifier;
}
container schema {
uses json:json-schema;
}
}
}
grouping responses-def-list {
list response {
key name;
leaf name {
type yang:yang-identifier;
}
uses openapi:response;
}
}
grouping tags-list {
list tag {
key name;
leaf name {
type yang:yang-identifier;
}
leaf description {
type meta:description;
}
container externalDocs {
leaf description {
type meta:description;
}
leaf url {
type inet:uri;
}
}
}
}
grouping specification {
leaf swagger {
type meta:api-version;
mandatory true;
must "current() = '2.0'";
}
container info {
uses openapi:info;
}
leaf host {
type string;
}
leaf base-path {
type inet:uri;
}
leaf-list schemes {
type identityref {
base protocol;
}
}
leaf-list consumes {
type mimetype;
min-elements 1;
}
leaf-list produces {
type mimetype;
min-elements 1;
}
uses openapi:paths-list;
uses openapi:definitions-list;
uses openapi:responses-def-list;
uses openapi:tags-list;
/* TODO
* parameters
* security-definitions
* security
* externalDocs
*/
action serialize {
description
"The serialize converts current Swagger/OpenAPI specification object
into string format based on requested output format.";
input {
leaf format {
type enumeration {
enum json;
enum yaml;
}
default json;
}
}
output {
leaf data {
description "contains the serialized specification data";
type string;
}
}
}
}
/*
* Configuration data nodes
*/
container info {
description
"Contains API description metadata for use during 'transform' output";
uses openapi:info;
}
/*
* Remote procedures
*/
rpc transform {
description
"The transform accepts YANG module names/locations or pre-existing
Swagger specification file contents and converts into YANG
schema-defined Swagger/OpenAPI specification object instance.";
input {
choice source {
case yang-modules {
leaf-list modules {
type yang:yang-identifier;
min-elements 1;
}
}
case swagger-file {
leaf file {
type meta:file-name;
mandatory true;
}
leaf format {
type enumeration {
enum json;
enum yaml;
}
mandatory true;
}
status planned;
}
}
// TODO
// openapi:example 'application/json' {
// value
// '{
// "modules": [ "yang-openapi" ]
// }';
// }
}
output {
container spec {
uses openapi:specification;
}
}
}
}