add swagger configuration in config.ini
add swagger.docs() process in server.py
add swagger configuration parse in config.py
add basePath() in settings.py
change 'basePath' item assignment in views.py
JIRA: FUNCTEST-305
Change-Id: I049991d4d53b78755ee971021ec0ad2458f5da60
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
# Mongo auth url => mongodb://user1:pwd1@host1/?authSource=db1
url = mongodb://127.0.0.1:27017/
dbname = test_results_collection
# Mongo auth url => mongodb://user1:pwd1@host1/?authSource=db1
url = mongodb://127.0.0.1:27017/
dbname = test_results_collection
[api]
# Listening port
port = 8000
# With debug_on set to true, error traces will be shown in HTTP responses
[api]
# Listening port
port = 8000
# With debug_on set to true, error traces will be shown in HTTP responses
-debug = True
\ No newline at end of file
+debug = True
+
+[swagger]
+base_url = http://testresults.opnfv.org/test
\ No newline at end of file
client = motor.MotorClient(CONF.mongo_url)
db = client[CONF.mongo_dbname]
client = motor.MotorClient(CONF.mongo_url)
db = client[CONF.mongo_dbname]
+swagger.docs(base_url=CONF.swagger_base_url)
+
def make_app():
return swagger.Application(
def make_app():
return swagger.Application(
self.api_port = None
self.api_debug_on = None
self._parser = None
self.api_port = None
self.api_debug_on = None
self._parser = None
+ self.swagger_base_url = None
def _get_parameter(self, section, param):
try:
def _get_parameter(self, section, param):
try:
obj.api_port = obj._get_int_parameter("api", "port")
obj.api_debug_on = obj._get_bool_parameter("api", "debug")
obj.api_port = obj._get_int_parameter("api", "port")
obj.api_debug_on = obj._get_bool_parameter("api", "debug")
+ obj.swagger_base_url = obj._get_parameter("swagger", "base_url")
return "mongo_url = %s \n" \
"mongo_dbname = %s \n" \
"api_port = %s \n" \
return "mongo_url = %s \n" \
"mongo_dbname = %s \n" \
"api_port = %s \n" \
- "api_debug_on = %s \n" % (self.mongo_url,
- self.mongo_dbname,
- self.api_port,
- self.api_debug_on)
+ "api_debug_on = %s \n" \
+ "swagger_base_url = %s \n" % (self.mongo_url,
+ self.mongo_dbname,
+ self.api_port,
+ self.api_debug_on,
+ self.swagger_base_url)
'static')
default_settings = {
'static')
default_settings = {
'static_path': STATIC_PATH,
'swagger_prefix': '/swagger',
'api_version': 'v1.0',
'static_path': STATIC_PATH,
'swagger_prefix': '/swagger',
'api_version': 'v1.0',
+
+
+def basePath():
+ return default_settings.get('base_url')
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-import urlparse
-import json
from settings import SWAGGER_VERSION, SWAGGER_API_LIST, SWAGGER_API_SPEC
from settings import SWAGGER_VERSION, SWAGGER_API_LIST, SWAGGER_API_SPEC
-from settings import models
+from settings import models, basePath
def json_dumps(obj, pretty=False):
def json_dumps(obj, pretty=False):
return self.static_path
def get(self):
return self.static_path
def get(self):
- discovery_url = \
- urlparse.urljoin(self.request.full_url(),
- self.reverse_url(SWAGGER_API_LIST))
+ discovery_url = basePath() + self.reverse_url(SWAGGER_API_LIST)
self.render('index.html', discovery_url=discovery_url)
self.render('index.html', discovery_url=discovery_url)
def get(self):
self.set_header('content-type', 'application/json')
def get(self):
self.set_header('content-type', 'application/json')
- u = urlparse.urlparse(self.request.full_url())
resources = {
'apiVersion': self.api_version,
'swaggerVersion': SWAGGER_VERSION,
resources = {
'apiVersion': self.api_version,
'swaggerVersion': SWAGGER_VERSION,
- 'basePath': '%s://%s' % (u.scheme, u.netloc),
+ 'basePath': basePath(),
'produces': ["application/json"],
'description': 'Test Api Spec',
'apis': [{
'produces': ["application/json"],
'description': 'Test Api Spec',
'apis': [{
if apis is None:
raise tornado.web.HTTPError(404)
if apis is None:
raise tornado.web.HTTPError(404)
- base_path = urlparse.urljoin(self.request.full_url(),
- self.base_url)[:-1]
specs = {
'apiVersion': self.api_version,
'swaggerVersion': SWAGGER_VERSION,
specs = {
'apiVersion': self.api_version,
'swaggerVersion': SWAGGER_VERSION,
+ 'basePath': basePath(),
'apis': [self.__get_api_spec__(path, spec, operations)
for path, spec, operations in apis],
'models': self.__get_models_spec(models)
'apis': [self.__get_api_spec__(path, spec, operations)
for path, spec, operations in apis],
'models': self.__get_models_spec(models)