Skip to content

Commit

Permalink
yaml: implement basic Swagger/OpenAPI subparser
Browse files Browse the repository at this point in the history
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',
                        \          ]
                        \ }
  • Loading branch information
segoon committed Dec 31, 2021
1 parent 8215492 commit 36a38b0
Show file tree
Hide file tree
Showing 13 changed files with 507 additions and 1 deletion.
1 change: 1 addition & 0 deletions Tmain/list-subparsers-all.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ IPythonCell Python base => sub {shared}
ITcl Tcl base <> sub {bidirectional}
Maven2 XML base <> sub {bidirectional}
Moose Perl base <> sub {bidirectional}
OpenApi Yaml base <> sub {bidirectional}
PlistXML XML base <> sub {bidirectional}
PythonLoggingConfig Iniconf base <> sub {bidirectional}
QtMoc C++ base <> sub {bidirectional}
Expand Down
1 change: 1 addition & 0 deletions Units/parser-openapi.r/openapi.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--language-force=openapi
7 changes: 7 additions & 0 deletions Units/parser-openapi.r/openapi.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/sample/other/path input.yaml /^ \/sample\/other\/path:$/;" p
/sample/path input.yaml /^ \/sample\/path:$/;" p
CustomHeader input.yaml /^ CustomHeader:$/;" P
NullableField input.yaml /^ NullableField:$/;" d
NullableFieldStringEnum input.yaml /^ NullableFieldStringEnum:$/;" d
Response1 input.yaml /^ Response1:$/;" R
Response2 input.yaml /^ Response2:$/;" R
1 change: 1 addition & 0 deletions Units/parser-openapi.r/openapi.d/features
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yaml
55 changes: 55 additions & 0 deletions Units/parser-openapi.r/openapi.d/input.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
openapi: 3.0.0
info:
title: test
description: test
version: '1.0'

servers:
- url: http://example.com
description: production

paths:
/sample/path:
get:
summary: simple handler
responses: {}

/sample/other/path:
get:
responses: {}
post:
summary: xxx
responses: {}

components:
schemas:
NullableField:
type: object
properties: {}
NullableFieldStringEnum:
type: object
properties: {}

parameters:
CustomHeader:
in: header
name: X-Custom-Header
required: false
schema:
type: string

responses:
Response1:
description: Payment Required
content:
application/json:
schema:
type: object
properties: {}
Response2:
description: smth 2
content:
application/json:
schema:
type: object
properties: {}
1 change: 1 addition & 0 deletions Units/parser-openapi.r/swagger.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--language-force=openapi
8 changes: 8 additions & 0 deletions Units/parser-openapi.r/swagger.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/sample/other/path input.yaml /^ \/sample\/other\/path:$/;" p
/sample/path input.yaml /^ \/sample\/path:$/;" p
Param1 input.yaml /^ Param1:$/;" P
Param2 input.yaml /^ Param2:$/;" P
PolymorphicInteger input.yaml /^ PolymorphicInteger:$/;" d
PolymorphicString input.yaml /^ PolymorphicString:$/;" d
Response1 input.yaml /^ Response1:$/;" R
Response2 input.yaml /^ Response2:$/;" R
1 change: 1 addition & 0 deletions Units/parser-openapi.r/swagger.d/features
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yaml
64 changes: 64 additions & 0 deletions Units/parser-openapi.r/swagger.d/input.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
swagger: '2.0'
info:
description: test
title: test
version: '1.0'
host: example.com

paths:
/sample/path:
post:
description: test
responses:
200:
description: xxx

/sample/other/path:
get:
description: smth
responses:
200:
description: xxx

definitions:
PolymorphicString:
type: object
required:
- type
- value
additionalProperties: false
properties:
type:
type: string
value:
type: string

PolymorphicInteger:
type: object
required:
- type
- value
additionalProperties: false
properties:
type:
type: string
value:
type: integer

parameters:
Param1:
name: test1
in: query
type: boolean

Param2:
name: test2
in: query
type: boolean

responses:
Response1:
description: aaa

Response2:
description: bbb
1 change: 1 addition & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ The following parsers have been added:
* M4
* NSIS
* ObjectiveC
* OpenAPI 3.x.x / Swagger 2.0
* Passwd *optlib*
* PuppetManifest *optlib*
* Perl6
Expand Down
3 changes: 2 additions & 1 deletion main/parsers_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
#ifdef HAVE_LIBYAML
#define YAML_PARSER_LIST \
YamlParser, \
AnsiblePlaybookParser
AnsiblePlaybookParser, \
OpenApiParser
#else
#define YAML_PARSER_LIST
#endif
Expand Down
Loading

0 comments on commit 36a38b0

Please sign in to comment.