Skip to content

Commit

Permalink
Merge pull request #63 from nedbat/nedbat/group-2.0
Browse files Browse the repository at this point in the history
Support :group: for OpenAPI 2.0
  • Loading branch information
ikalnytskyi committed Dec 19, 2019
2 parents 9306435 + 6801923 commit 8152352
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions sphinxcontrib/openapi/openapi20.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from __future__ import unicode_literals

import collections
import itertools
import re

Expand Down Expand Up @@ -166,6 +167,12 @@ def is_2xx_response(status):
return False


def _header(title):
yield title
yield '=' * len(title)
yield ''


def openapihttpdomain(spec, **options):
if 'examples' in options:
raise ValueError(
Expand Down Expand Up @@ -219,13 +226,34 @@ def openapihttpdomain(spec, **options):
_paths.append(path)
paths = _paths

for endpoint in paths:
for method, properties in spec['paths'][endpoint].items():
generators.append(_httpresource(
endpoint,
method,
properties,
utils.get_text_converter(options),
))
if 'group' in options:
groups = collections.defaultdict(list)

for endpoint in paths:
for method, properties in spec['paths'][endpoint].items():
key = properties.get('tags', [''])[0]
groups[key].append(_httpresource(
endpoint,
method,
properties,
utils.get_text_converter(options),
))

for key in sorted(groups.keys()):
if key:
generators.append(_header(key))
else:
generators.append(_header('default'))

generators.extend(groups[key])
else:
for endpoint in paths:
for method, properties in spec['paths'][endpoint].items():
generators.append(_httpresource(
endpoint,
method,
properties,
utils.get_text_converter(options),
))

return iter(itertools.chain(*generators))

0 comments on commit 8152352

Please sign in to comment.