Skip to content

Commit

Permalink
doc(headers): handle headers in swagger doc (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulineribeyre authored Apr 4, 2019
1 parent 89f5b5c commit 7d04d05
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
14 changes: 14 additions & 0 deletions build_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ def translate_to_swag(doc, subs):
]
)

# Headers
args = doc.get("Headers")
spec["parameters"].extend(
[
{
"in": "header",
"name": name,
"type": swagger_types.get(props.type, props.type),
"description": props.description,
}
for name, props in args.iteritems()
]
)

# handle substitutions
for p in spec["parameters"]:
for k, v in subs.iteritems():
Expand Down
5 changes: 3 additions & 2 deletions openapi/docstring_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Argument(object):
name (type): description
"""

re_arg = re.compile(r"([\w_]+)(?: \(([\w_]+)\))?: ([\w\s_.,;:'\"`()|]+)")
re_arg = re.compile(r"([\w_-]+)(?: \(([\w_]+)\))?: ([\w\s_.,;:'\"`()|/-]+)")
# ^ name ^ type ^ description

def __init__(self, name=None, arg_type=None, description=None):
Expand Down Expand Up @@ -40,7 +40,7 @@ class Docstring(object):
Store docstring arguments by section.
"""

section_names = ["Args", "Query Args", "Responses", "Summary", "Tags"]
section_names = ["Args", "Query Args", "Headers", "Responses", "Summary", "Tags"]
single_arg_section_names = ["Summary", "Tags"]

def __init__(self):
Expand Down Expand Up @@ -75,6 +75,7 @@ def parse_section(cls, section, docstring):
pass

args = map(Argument.from_string, filter(bool, section_args.split("\n")))

if section in cls.single_arg_section_names:
return args
else:
Expand Down
22 changes: 21 additions & 1 deletion openapi/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ paths:
name: body
schema:
$ref: '#/definitions/schema_entity'
- description: application/json (default), text/tab-separated-values, text/tsv
or text/csv
in: header
name: Content-Type
type: string
responses:
'201':
description: Entities created successfully
Expand Down Expand Up @@ -356,6 +361,11 @@ paths:
name: body
schema:
$ref: '#/definitions/schema_entity'
- description: application/json (default), text/tab-separated-values, text/tsv
or text/csv
in: header
name: Content-Type
type: string
responses:
'201':
description: Entities created successfully
Expand Down Expand Up @@ -448,6 +458,11 @@ paths:
name: body
schema:
$ref: '#/definitions/schema_entity'
- description: application/json (default), text/tab-separated-values, text/tsv
or text/csv
in: header
name: Content-Type
type: string
responses:
'201':
description: Entities created successfully
Expand Down Expand Up @@ -480,6 +495,11 @@ paths:
name: body
schema:
$ref: '#/definitions/schema_entity'
- description: application/json (default), text/tab-separated-values, text/tsv
or text/csv
in: header
name: Content-Type
type: string
responses:
'201':
description: Entities created successfully
Expand Down Expand Up @@ -625,7 +645,7 @@ paths:
name: project
required: true
type: string
- description: A comma
- description: A comma-separated list of ids specifying the entities to retrieve.
in: path
name: entity_id_string
required: true
Expand Down
3 changes: 3 additions & 0 deletions sheepdog/blueprint/routes/views/program/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def create_entities(program, project):
project (str): |project_id|
body (schema_entity): input body
Headers:
Content-Type (str): application/json (default), text/tab-separated-values, text/tsv or text/csv
Responses:
201: Entities created successfully
404: Resource not found.
Expand Down

0 comments on commit 7d04d05

Please sign in to comment.