Skip to content

Commit 36a38b0

Browse files
committed
yaml: implement basic Swagger/OpenAPI subparser
The parser is able to parse both Swagger 2.0 and Openapi 3.0.x. The code is partly based on ansible playbook parser. It was tested using the following vim's TagBar parser declaration: let g:tagbar_type_yaml = { \ 'ctagstype': 'openapi', \ 'kinds': [ \ 'p:path', \ 'd:schema', \ 'P:parameter', \ 'R:response', \ ] \ }
1 parent 8215492 commit 36a38b0

File tree

13 files changed

+507
-1
lines changed

13 files changed

+507
-1
lines changed

Tmain/list-subparsers-all.d/stdout-expected.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ IPythonCell Python base => sub {shared}
1010
ITcl Tcl base <> sub {bidirectional}
1111
Maven2 XML base <> sub {bidirectional}
1212
Moose Perl base <> sub {bidirectional}
13+
OpenApi Yaml base <> sub {bidirectional}
1314
PlistXML XML base <> sub {bidirectional}
1415
PythonLoggingConfig Iniconf base <> sub {bidirectional}
1516
QtMoc C++ base <> sub {bidirectional}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--language-force=openapi
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/sample/other/path input.yaml /^ \/sample\/other\/path:$/;" p
2+
/sample/path input.yaml /^ \/sample\/path:$/;" p
3+
CustomHeader input.yaml /^ CustomHeader:$/;" P
4+
NullableField input.yaml /^ NullableField:$/;" d
5+
NullableFieldStringEnum input.yaml /^ NullableFieldStringEnum:$/;" d
6+
Response1 input.yaml /^ Response1:$/;" R
7+
Response2 input.yaml /^ Response2:$/;" R
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yaml
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
openapi: 3.0.0
2+
info:
3+
title: test
4+
description: test
5+
version: '1.0'
6+
7+
servers:
8+
- url: http://example.com
9+
description: production
10+
11+
paths:
12+
/sample/path:
13+
get:
14+
summary: simple handler
15+
responses: {}
16+
17+
/sample/other/path:
18+
get:
19+
responses: {}
20+
post:
21+
summary: xxx
22+
responses: {}
23+
24+
components:
25+
schemas:
26+
NullableField:
27+
type: object
28+
properties: {}
29+
NullableFieldStringEnum:
30+
type: object
31+
properties: {}
32+
33+
parameters:
34+
CustomHeader:
35+
in: header
36+
name: X-Custom-Header
37+
required: false
38+
schema:
39+
type: string
40+
41+
responses:
42+
Response1:
43+
description: Payment Required
44+
content:
45+
application/json:
46+
schema:
47+
type: object
48+
properties: {}
49+
Response2:
50+
description: smth 2
51+
content:
52+
application/json:
53+
schema:
54+
type: object
55+
properties: {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--language-force=openapi
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/sample/other/path input.yaml /^ \/sample\/other\/path:$/;" p
2+
/sample/path input.yaml /^ \/sample\/path:$/;" p
3+
Param1 input.yaml /^ Param1:$/;" P
4+
Param2 input.yaml /^ Param2:$/;" P
5+
PolymorphicInteger input.yaml /^ PolymorphicInteger:$/;" d
6+
PolymorphicString input.yaml /^ PolymorphicString:$/;" d
7+
Response1 input.yaml /^ Response1:$/;" R
8+
Response2 input.yaml /^ Response2:$/;" R
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yaml
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
swagger: '2.0'
2+
info:
3+
description: test
4+
title: test
5+
version: '1.0'
6+
host: example.com
7+
8+
paths:
9+
/sample/path:
10+
post:
11+
description: test
12+
responses:
13+
200:
14+
description: xxx
15+
16+
/sample/other/path:
17+
get:
18+
description: smth
19+
responses:
20+
200:
21+
description: xxx
22+
23+
definitions:
24+
PolymorphicString:
25+
type: object
26+
required:
27+
- type
28+
- value
29+
additionalProperties: false
30+
properties:
31+
type:
32+
type: string
33+
value:
34+
type: string
35+
36+
PolymorphicInteger:
37+
type: object
38+
required:
39+
- type
40+
- value
41+
additionalProperties: false
42+
properties:
43+
type:
44+
type: string
45+
value:
46+
type: integer
47+
48+
parameters:
49+
Param1:
50+
name: test1
51+
in: query
52+
type: boolean
53+
54+
Param2:
55+
name: test2
56+
in: query
57+
type: boolean
58+
59+
responses:
60+
Response1:
61+
description: aaa
62+
63+
Response2:
64+
description: bbb

docs/news.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ The following parsers have been added:
439439
* M4
440440
* NSIS
441441
* ObjectiveC
442+
* OpenAPI 3.x.x / Swagger 2.0
442443
* Passwd *optlib*
443444
* PuppetManifest *optlib*
444445
* Perl6

0 commit comments

Comments
 (0)