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
30 changes: 30 additions & 0 deletions Units/parser-openapi.r/openapi.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/sample/other/path input.yaml /^ \/sample\/other\/path:$/;" p
/sample/path input.yaml /^ \/sample\/path:$/;" p
Body1 input.yaml /^ Body1:$/;" B
Body2 input.yaml /^ Body2:$/;" B
Callback1 input.yaml /^ Callback1: {}$/;" c
Callback2 input.yaml /^ Callback2: {}$/;" c
CustomHeader input.yaml /^ CustomHeader:$/;" P
Example1 input.yaml /^ Example1:$/;" e
Example2 input.yaml /^ Example2:$/;" e
Header1 input.yaml /^ Header1:$/;" h
Header2 input.yaml /^ Header2:$/;" h
Link1 input.yaml /^ Link1: {}$/;" l
Link2 input.yaml /^ Link2: {}$/;" l
NullableField input.yaml /^ NullableField:$/;" d
NullableFieldStringEnum input.yaml /^ NullableFieldStringEnum:$/;" d
PathItem1 input.yaml /^ PathItem1: {}$/;" A
PathItem2 input.yaml /^ PathItem2: {}$/;" A
Response1 input.yaml /^ Response1:$/;" R
Response2 input.yaml /^ Response2:$/;" R
SSchema1 input.yaml /^ SSchema1:$/;" C
SSchema2 input.yaml /^ SSchema2:$/;" C
SomeApiKey input.yaml /^ - SomeApiKey:$/;" s
android_handler input.yaml /^ - name: android_handler$/;" t
description input.yaml /^ description: test$/;" I
http://example.com input.yaml /^ url: http:\/\/example.com$/;" D
http://example.com input.yaml /^ - url: http:\/\/example.com$/;" S
http://example2.com input.yaml /^ - url: http:\/\/example2.com$/;" S
ios_handler input.yaml /^ - name: ios_handler$/;" t
title input.yaml /^ title: test$/;" I
version input.yaml /^ version: '1.0'$/;" I
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
119 changes: 119 additions & 0 deletions Units/parser-openapi.r/openapi.d/input.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
openapi: 3.1.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
- url: http://example2.com
description: testing

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: {}
examples:
Example1:
summary: xxx
value: yyyyy
Example2:
summary: xxx
value: yyyyy
requestBodies:
Body1:
description: bla bla bla
content:
application/json:
schema:
type: string
Body2:
description: bla bla bla
content:
application/json:
schema:
type: integer
headers:
Header1:
schema:
type: string
Header2:
schema:
type: string
securitySchemes:
SSchema1:
type: http
scheme: basic
SSchema2:
type: http
scheme: basic
links:
Link1: {}
Link2: {}
callbacks:
Callback1: {}
Callback2: {}
# pathItems is allowed in 3.1.0
pathItems:
PathItem1: {}
PathItem2: {}



security:
- {}
- SomeApiKey:
- foo:read
- foo:write

tags:
- name: android_handler
description: Handler for Android clients
- name: ios_handler
description: Handler for iOS clients

externalDocs:
description: some docs
url: http://example.com
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
11 changes: 11 additions & 0 deletions Units/parser-openapi.r/swagger.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/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
description input.yaml /^ description: test$/;" I
title input.yaml /^ title: test$/;" I
version input.yaml /^ version: '1.0'$/;" I
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