File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ class Api(object):
94
94
:param FormatChecker format_checker: A jsonschema.FormatChecker object that is hooked into
95
95
the Model validator. A default or a custom FormatChecker can be provided (e.g., with custom
96
96
checkers), otherwise the default action is to not enforce any format validation.
97
+ :param str default_swagger_filename: The default swagger filename.
97
98
"""
98
99
99
100
def __init__ (
@@ -123,6 +124,7 @@ def __init__(
123
124
catch_all_404s = False ,
124
125
serve_challenge_on_401 = False ,
125
126
format_checker = None ,
127
+ default_swagger_filename = "swagger.json" ,
126
128
** kwargs
127
129
):
128
130
self .version = version
@@ -153,6 +155,7 @@ def __init__(
153
155
self ._refresolver = None
154
156
self .format_checker = format_checker
155
157
self .namespaces = []
158
+ self .default_swagger_filename = default_swagger_filename
156
159
157
160
self .ns_paths = dict ()
158
161
@@ -293,7 +296,7 @@ def _register_specs(self, app_or_blueprint):
293
296
app_or_blueprint ,
294
297
SwaggerView ,
295
298
self .default_namespace ,
296
- "/swagger.json" ,
299
+ "/" + self . default_swagger_filename ,
297
300
endpoint = endpoint ,
298
301
resource_class_args = (self ,),
299
302
)
Original file line number Diff line number Diff line change @@ -3323,3 +3323,25 @@ def get(self):
3323
3323
3324
3324
path = data ["paths" ]["/with-parser/" ]
3325
3325
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