Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yaml: implement basic Swagger/OpenAPI subparser #3245

Closed
wants to merge 16 commits into from
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about tagging the title?

description: test
version: '1.0'

servers:
- url: http://example.com
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about tagging the URLs under servers?

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about tagging the title?

Copy link
Author

@segoon segoon Jan 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it makes sense to tag all user-defined entities, then ok.
But then more fields must be tagged:

  • info itself
  • servers children
  • webhooks children
  • security children
  • tags children

I don't think the following entities worth adding tags (too minor IMHO):

  • openapi
  • jsonSchemaDialect
  • externalDocs

https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object

What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I wrote is wrong.
In 97915e7, your parser extracts "title".
However, what I expected is your parser extract "test" in "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