Skip to content

Commit

Permalink
Fix get_config to be compatible with openapi spec
Browse files Browse the repository at this point in the history
  • Loading branch information
b3n4kh committed Aug 30, 2023
1 parent 1dde0c4 commit 9316672
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Project
tools/*/
tools/*.tar.gz
.vscode
.envrc

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import platform
from pathlib import Path

from packaging.version import Version
from setuptools import find_packages
from setuptools import setup

if Version(platform.python_version()) < Version('3.0.0'):
raise Exception("`swagger-ui-py` support python version >= 3.0.0 only.")

setup(
name='swagger-ui-py',
version='23.8.23',
python_requires='>3.8.0',
description=(
'Swagger UI for Python web framework, '
'such as Tornado, Flask, Quart, Sanic and Falcon.'
Expand Down
6 changes: 3 additions & 3 deletions swagger_ui/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import copy
import importlib
import re
import urllib.request
from pathlib import Path

Expand Down Expand Up @@ -142,12 +141,13 @@ def get_config(self, host):
config = _load_config(config_file.read())
elif self.config_spec:
config = _load_config(self.config_spec)
else:
raise RuntimeError('No config found!')

version = config.get('openapi', '2.0.0')
if Version(version) >= Version('3.0.0'):
for server in config.get('servers', []):
server['url'] = re.sub(r'//[a-z0-9\-\.:]+/?',
'//{}/'.format(host), server['url'])
server['url'] = server['url']
elif 'host' not in config:
config['host'] = host
return config
Expand Down

0 comments on commit 9316672

Please sign in to comment.