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 @@ -97,6 +97,7 @@ class Api(object):
9797 :param url_scheme: If set to a string (e.g. http, https), then the specs_url and base_url will explicitly use this
9898 scheme regardless of how the application is deployed. This is necessary for some deployments behind a reverse
9999 proxy.
100+ :param str default_swagger_filename: The default swagger filename.
100101 """
101102
102103 def __init__ (
@@ -127,6 +128,7 @@ def __init__(
127128 serve_challenge_on_401 = False ,
128129 format_checker = None ,
129130 url_scheme = None ,
131+ default_swagger_filename = "swagger.json" ,
130132 ** kwargs
131133 ):
132134 self .version = version
@@ -157,6 +159,7 @@ def __init__(
157159 self ._refresolver = None
158160 self .format_checker = format_checker
159161 self .namespaces = []
162+ self .default_swagger_filename = default_swagger_filename
160163
161164 self .ns_paths = dict ()
162165
@@ -299,7 +302,7 @@ def _register_specs(self, app_or_blueprint):
299302 app_or_blueprint ,
300303 SwaggerView ,
301304 self .default_namespace ,
302- "/swagger.json" ,
305+ "/" + self . default_swagger_filename ,
303306 endpoint = endpoint ,
304307 resource_class_args = (self ,),
305308 )
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