Skip to content

Commit

Permalink
fixup! [Web] Add new webapi endpoint and interactive webapi docs with…
Browse files Browse the repository at this point in the history
… Swagger-UI
  • Loading branch information
bendikro committed May 11, 2020
1 parent 7ad1fb1 commit 5dd38ef
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions deluge/ui/web/webapidoc/openapi_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import copy
import logging
import re
import sys

import docstring_parser
import six
from apispec import APISpec, BasePlugin
from apispec.yaml_utils import load_operations_from_docstring
Expand Down Expand Up @@ -153,6 +153,9 @@ def get_pretty(obj):
return

try:
# Import docstring_parser here as it only supports python >= 3.6
import docstring_parser # noqa

docstring = docstring_parser.parse(func_docs)
except ValueError as err:
log.warning(
Expand Down Expand Up @@ -273,7 +276,7 @@ def get_evaled_example(example):
'description': response_description,
'content': {
'application/json': {
'schema': {'type': response_type, 'items': {},},
'schema': {'type': response_type, 'items': {}},
'example': success_response_example,
}
},
Expand Down Expand Up @@ -311,19 +314,20 @@ def get_parameter_pretty(self):
'name': 'pretty',
'in': 'query',
'required': False,
'schema': {'type': 'string', 'example': 'pretty',},
'schema': {'type': 'string', 'example': 'pretty'},
}

def build_spec(self):
plugins = [DeprecatedPlugin(), JsonAPIPlugin(self.json_component)]
# docstring_parser supports >= 3.6
if (sys.version_info.major, sys.version_info.minor) >= (3, 6):
plugins.insert(0, GoogleStyleDocPlugin())

self.spec = APISpec(
title='Deluge Webapi',
version='1.0.0',
openapi_version='3.0.2',
plugins=[
GoogleStyleDocPlugin(),
DeprecatedPlugin(),
JsonAPIPlugin(self.json_component),
],
plugins=plugins,
)

self.add_post_method('json', '/json', '/json')
Expand Down

0 comments on commit 5dd38ef

Please sign in to comment.