@@ -20,7 +20,7 @@ func (api *API) ToOpenAPI() (*spec.Swagger, error) {
20
20
Produces : []string {"application/json" },
21
21
Info : & spec.Info {
22
22
InfoProps : spec.InfoProps {
23
- Version : "4.0 " ,
23
+ Version : "5.1 " ,
24
24
Title : "Contrail API OpenAPI2.0 Definitions" ,
25
25
License : & spec.License {
26
26
Name : "Apache2.0" ,
@@ -42,18 +42,19 @@ func (api *API) ToOpenAPI() (*spec.Swagger, error) {
42
42
// add reference and back ref
43
43
44
44
for _ , reference := range apiSchema .References {
45
- referenceSchema := spec.Schema {
45
+ referenceSchema := & spec.Schema {
46
46
SchemaProps : spec.SchemaProps {
47
- Description : reference .Description ,
48
47
Properties : map [string ]spec.Schema {
49
48
"uuid" : {
50
49
SchemaProps : spec.SchemaProps {
51
- Type : spec .StringOrArray ([]string {"string" }),
50
+ Description : "UUID of the referenced resource." ,
51
+ Type : spec .StringOrArray ([]string {"string" }),
52
52
},
53
53
},
54
54
"to" : {
55
55
SchemaProps : spec.SchemaProps {
56
- Type : spec .StringOrArray ([]string {"array" }),
56
+ Description : "FQName of the referenced resource." ,
57
+ Type : spec .StringOrArray ([]string {"array" }),
57
58
Items : & spec.SchemaOrArray {
58
59
Schema : & spec.Schema {
59
60
SchemaProps : spec.SchemaProps {
@@ -66,30 +67,38 @@ func (api *API) ToOpenAPI() (*spec.Swagger, error) {
66
67
},
67
68
},
68
69
}
69
- var ref spec.Ref
70
- ref , err = spec .NewRef ("#/definitions/" + reference .RefType )
71
- if err != nil {
72
- return nil , err
73
- }
74
70
if reference .RefType != "" {
71
+ var ref spec.Ref
72
+ ref , err = spec .NewRef ("#/definitions/" + reference .RefType )
73
+ if err != nil {
74
+ return nil , err
75
+ }
75
76
referenceSchema .Properties ["attr" ] = spec.Schema {
76
77
SchemaProps : spec.SchemaProps {
77
78
Ref : ref ,
78
79
},
79
80
}
80
81
}
81
- d .Properties [reference .LinkTo .ID + "_ref" ] = referenceSchema
82
+ d .Properties [reference .LinkTo .ID + "_refs" ] = spec.Schema {
83
+ SchemaProps : spec.SchemaProps {
84
+ Description : reference .Description ,
85
+ Type : spec .StringOrArray ([]string {"array" }),
86
+ Items : & spec.SchemaOrArray {
87
+ Schema : referenceSchema ,
88
+ },
89
+ },
90
+ }
82
91
}
83
92
84
- for _ , backref := range apiSchema .Children {
93
+ for _ , child := range apiSchema .Children {
85
94
var ref spec.Ref
86
- ref , err = spec .NewRef ("#/definitions/" + backref .LinkTo .JSONSchema .GoName + "APIType" )
95
+ ref , err = spec .NewRef ("#/definitions/" + child .LinkTo .JSONSchema .GoName + "APIType" )
87
96
if err != nil {
88
97
return nil , err
89
98
}
90
- d .Properties [backref .LinkTo .ID + "s" ] = spec.Schema {
99
+ d .Properties [child .LinkTo .ID + "s" ] = spec.Schema {
91
100
SchemaProps : spec.SchemaProps {
92
- Description : backref .Description ,
101
+ Description : child .Description ,
93
102
Type : spec .StringOrArray ([]string {"array" }),
94
103
Items : & spec.SchemaOrArray {
95
104
Schema : & spec.Schema {
@@ -119,6 +128,16 @@ func (api *API) ToOpenAPI() (*spec.Swagger, error) {
119
128
120
129
pathItem := spec.PathItem {
121
130
PathItemProps : spec.PathItemProps {
131
+ Parameters : []spec.Parameter {
132
+ {
133
+ SimpleSchema : spec.SimpleSchema {Type : StringType },
134
+ ParamProps : spec.ParamProps {
135
+ Name : "id" ,
136
+ Required : true ,
137
+ In : "path" ,
138
+ },
139
+ },
140
+ },
122
141
Get : & spec.Operation {
123
142
OperationProps : spec.OperationProps {
124
143
//TODO Parameters:
@@ -198,6 +217,7 @@ func (api *API) ToOpenAPI() (*spec.Swagger, error) {
198
217
Parameters : []spec.Parameter {
199
218
{
200
219
ParamProps : spec.ParamProps {
220
+ Name : apiSchema .TypeName ,
201
221
Required : true ,
202
222
In : "body" ,
203
223
Schema : & spec.Schema {
@@ -260,6 +280,7 @@ func (api *API) ToOpenAPI() (*spec.Swagger, error) {
260
280
Parameters : []spec.Parameter {
261
281
{
262
282
ParamProps : spec.ParamProps {
283
+ Name : apiSchema .TypeName ,
263
284
In : "body" ,
264
285
Required : true ,
265
286
Schema : & spec.Schema {
@@ -317,6 +338,7 @@ func (api *API) ToOpenAPI() (*spec.Swagger, error) {
317
338
OperationProps : spec.OperationProps {
318
339
Parameters : []spec.Parameter {
319
340
{
341
+ SimpleSchema : spec.SimpleSchema {Type : StringType },
320
342
ParamProps : spec.ParamProps {
321
343
In : "query" ,
322
344
Name : "parent_id" ,
@@ -325,6 +347,7 @@ func (api *API) ToOpenAPI() (*spec.Swagger, error) {
325
347
},
326
348
},
327
349
{
350
+ SimpleSchema : spec.SimpleSchema {Type : StringType },
328
351
ParamProps : spec.ParamProps {
329
352
In : "query" ,
330
353
Name : "parent_fq_name_str" ,
@@ -333,6 +356,7 @@ func (api *API) ToOpenAPI() (*spec.Swagger, error) {
333
356
},
334
357
},
335
358
{
359
+ SimpleSchema : spec.SimpleSchema {Type : StringType },
336
360
ParamProps : spec.ParamProps {
337
361
In : "query" ,
338
362
Name : "pobj_uuids" ,
@@ -341,6 +365,7 @@ func (api *API) ToOpenAPI() (*spec.Swagger, error) {
341
365
},
342
366
},
343
367
{
368
+ SimpleSchema : spec.SimpleSchema {Type : StringType },
344
369
ParamProps : spec.ParamProps {
345
370
In : "query" ,
346
371
Name : "detail" ,
@@ -349,6 +374,7 @@ func (api *API) ToOpenAPI() (*spec.Swagger, error) {
349
374
},
350
375
},
351
376
{
377
+ SimpleSchema : spec.SimpleSchema {Type : StringType },
352
378
ParamProps : spec.ParamProps {
353
379
In : "query" ,
354
380
Name : "back_ref_id" ,
@@ -357,22 +383,25 @@ func (api *API) ToOpenAPI() (*spec.Swagger, error) {
357
383
},
358
384
},
359
385
{
386
+ SimpleSchema : spec.SimpleSchema {Type : StringType },
360
387
ParamProps : spec.ParamProps {
361
388
In : "query" ,
362
389
Name : "page_marker" ,
363
- Description : "Pagenation start marker" ,
390
+ Description : "Pagination start marker" ,
364
391
Required : false ,
365
392
},
366
393
},
367
394
{
395
+ SimpleSchema : spec.SimpleSchema {Type : StringType },
368
396
ParamProps : spec.ParamProps {
369
397
In : "query" ,
370
398
Name : "page_limit" ,
371
- Description : "Pagenation limit" ,
399
+ Description : "Pagination limit" ,
372
400
Required : false ,
373
401
},
374
402
},
375
403
{
404
+ SimpleSchema : spec.SimpleSchema {Type : StringType },
376
405
ParamProps : spec.ParamProps {
377
406
In : "query" ,
378
407
Name : "count" ,
@@ -381,14 +410,16 @@ func (api *API) ToOpenAPI() (*spec.Swagger, error) {
381
410
},
382
411
},
383
412
{
413
+ SimpleSchema : spec.SimpleSchema {Type : StringType },
384
414
ParamProps : spec.ParamProps {
385
415
In : "query" ,
386
416
Name : "fields" ,
387
- Description : " Comma separated object field list you are interested in" ,
417
+ Description : "Comma separated object field list you are interested in" ,
388
418
Required : false ,
389
419
},
390
420
},
391
421
{
422
+ SimpleSchema : spec.SimpleSchema {Type : StringType },
392
423
ParamProps : spec.ParamProps {
393
424
In : "query" ,
394
425
Name : "shared" ,
@@ -397,6 +428,7 @@ func (api *API) ToOpenAPI() (*spec.Swagger, error) {
397
428
},
398
429
},
399
430
{
431
+ SimpleSchema : spec.SimpleSchema {Type : StringType },
400
432
ParamProps : spec.ParamProps {
401
433
In : "query" ,
402
434
Name : "filters" ,
@@ -405,6 +437,7 @@ func (api *API) ToOpenAPI() (*spec.Swagger, error) {
405
437
},
406
438
},
407
439
{
440
+ SimpleSchema : spec.SimpleSchema {Type : StringType },
408
441
ParamProps : spec.ParamProps {
409
442
In : "query" ,
410
443
Name : "exclude_hrefs" ,
@@ -532,24 +565,37 @@ func (s *JSONSchema) ToOpenAPI() (*spec.Schema, error) {
532
565
}
533
566
properties [key ] = * p
534
567
}
535
- return & spec.Schema {
568
+ result := & spec.Schema {
536
569
SchemaProps : spec.SchemaProps {
537
- ID : s .ID ,
538
570
Description : s .Description ,
539
- Type : spec .StringOrArray ([]string {s .Type }),
571
+ Type : spec .StringOrArray ([]string {typeToOpenAPI ( s .Type ) }),
540
572
Title : s .Title ,
541
573
//TODO(nati) support this.
542
574
//Format: s.Format,
543
575
//Maximum: s.Maximum,
544
576
//Minimum: s.Minimum,
545
577
//Pattern: s.Pattern,
546
578
//Enum: s.Enum,
547
- Default : s .Default ,
548
- Required : s .Required ,
549
- Items : & spec.SchemaOrArray {
550
- Schema : items ,
551
- },
579
+ Default : s .Default ,
580
+ Required : s .Required ,
552
581
Properties : properties ,
553
582
},
554
- }, nil
583
+ }
584
+
585
+ if items != nil {
586
+ result .Items = & spec.SchemaOrArray {
587
+ Schema : items ,
588
+ }
589
+ }
590
+
591
+ return result , nil
592
+ }
593
+
594
+ func typeToOpenAPI (t string ) string {
595
+ switch t {
596
+ case UintType :
597
+ return IntegerType
598
+ default :
599
+ return t
600
+ }
555
601
}
0 commit comments