File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,7 @@ class Api(object):
106106 :param url_scheme: If set to a string (e.g. http, https), then the specs_url and base_url will explicitly use this
107107 scheme regardless of how the application is deployed. This is necessary for some deployments behind a reverse
108108 proxy.
109+ :param str default_swagger_filename: The default swagger filename.
109110 """
110111
111112 def __init__ (
@@ -136,6 +137,7 @@ def __init__(
136137 serve_challenge_on_401 = False ,
137138 format_checker = None ,
138139 url_scheme = None ,
140+ default_swagger_filename = "swagger.json" ,
139141 ** kwargs
140142 ):
141143 self .version = version
@@ -166,6 +168,7 @@ def __init__(
166168 self ._refresolver = None
167169 self .format_checker = format_checker
168170 self .namespaces = []
171+ self .default_swagger_filename = default_swagger_filename
169172
170173 self .ns_paths = dict ()
171174
@@ -308,7 +311,7 @@ def _register_specs(self, app_or_blueprint):
308311 app_or_blueprint ,
309312 SwaggerView ,
310313 self .default_namespace ,
311- "/swagger.json" ,
314+ "/" + self . default_swagger_filename ,
312315 endpoint = endpoint ,
313316 resource_class_args = (self ,),
314317 )
Original file line number Diff line number Diff line change @@ -3323,3 +3323,25 @@ def get(self):
33233323
33243324 path = data ["paths" ]["/with-parser/" ]
33253325 assert "parameters" not in path
3326+
3327+ def test_nondefault_swagger_filename (self , app , client ):
3328+ api = restx .Api (doc = "/doc/test" , default_swagger_filename = "test.json" )
3329+ ns = restx .Namespace ("ns1" )
3330+
3331+ @ns .route ("/test1" )
3332+ class Ns (restx .Resource ):
3333+ @ns .doc ("Docs" )
3334+ def get (self ):
3335+ pass
3336+
3337+ api .add_namespace (ns )
3338+ api .init_app (app )
3339+
3340+ resp = client .get ("/test.json" )
3341+ assert resp .status_code == 200
3342+ assert resp .content_type == "application/json"
3343+ resp = client .get ("/doc/test" )
3344+ assert resp .status_code == 200
3345+ assert resp .content_type == "text/html; charset=utf-8"
3346+ resp = client .get ("/ns1/test1" )
3347+ assert resp .status_code == 200
You can’t perform that action at this time.
0 commit comments