Skip to content

Commit

Permalink
fix openapi >= 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
duguiping committed Apr 17, 2019
1 parent f843d38 commit 2dcf447
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
25 changes: 25 additions & 0 deletions examples/conf/test3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
openapi: 3.0.1
info:
title: python-swagger-ui test api
description: python-swagger-ui test api
version: 1.0.0
servers:
- url: http://127.0.0.1:8989/api
tags:
- name: default
description: default tag
paths:
/hello/world:
get:
tags:
- default
summary: output hello world.
responses:
200:
description: OK
content:
application/text:
schema:
type: object
example: Hello World!!!
components: {}
5 changes: 2 additions & 3 deletions swagger_ui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from .core import Interface as api_doc

from .old import TornadoInterface as tornado_api_doc
from .old import AiohttpInterface as aiohttp_api_doc
from .old import FlaskInterface as flask_api_doc
from .old import SanicInterface as sanic_api_doc
from .old import QuartInterface as quart_api_doc
from .old import SanicInterface as sanic_api_doc
from .old import TornadoInterface as tornado_api_doc
8 changes: 7 additions & 1 deletion swagger_ui/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
import re
import sys
import urllib.request
from distutils.version import StrictVersion
from pathlib import Path

import yaml
Expand Down Expand Up @@ -73,7 +75,11 @@ def get_config(self, host):
with urllib.request.urlopen(self._config_url) as config_file:
config = self._load_config(config_file.read())

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

def _uri(self, suffix=''):
Expand Down

0 comments on commit 2dcf447

Please sign in to comment.