@@ -94,6 +94,9 @@ class Api(object):
9494 :param FormatChecker format_checker: A jsonschema.FormatChecker object that is hooked into
9595 the Model validator. A default or a custom FormatChecker can be provided (e.g., with custom
9696 checkers), otherwise the default action is to not enforce any format validation.
97+ :param specs_url_scheme: If set to a string (e.g. http, https), then the specs_url will explicitly use this scheme
98+ regardless of how the application is deployed. This is necessary for some deployments such as behind an
99+ AWS elastic load balancer so that the user recieves the full swagger URL.
97100 """
98101
99102 def __init__ (
@@ -123,6 +126,7 @@ def __init__(
123126 catch_all_404s = False ,
124127 serve_challenge_on_401 = False ,
125128 format_checker = None ,
129+ specs_url_scheme = None ,
126130 ** kwargs
127131 ):
128132 self .version = version
@@ -144,10 +148,12 @@ def __init__(
144148 self ._default_error_handler = None
145149 self .tags = tags or []
146150
147- self .error_handlers = OrderedDict ({
148- ParseError : mask_parse_error_handler ,
149- MaskError : mask_error_handler ,
150- })
151+ self .error_handlers = OrderedDict (
152+ {
153+ ParseError : mask_parse_error_handler ,
154+ MaskError : mask_error_handler ,
155+ }
156+ )
151157 self ._schema = None
152158 self .models = {}
153159 self ._refresolver = None
@@ -178,6 +184,7 @@ def __init__(
178184 api = self ,
179185 path = "/" ,
180186 )
187+ self .specs_url_scheme = specs_url_scheme
181188 if app is not None :
182189 self .app = app
183190 self .init_app (app )
@@ -220,7 +227,6 @@ def init_app(self, app, **kwargs):
220227 else :
221228 self .blueprint = app
222229
223-
224230 def _init_app (self , app ):
225231 """
226232 Perform initialization actions with the given :class:`flask.Flask` object.
@@ -254,14 +260,13 @@ def _init_app(self, app):
254260
255261 # check for deprecated config variable names
256262 if "ERROR_404_HELP" in app .config :
257- app .config [' RESTX_ERROR_404_HELP' ] = app .config [' ERROR_404_HELP' ]
263+ app .config [" RESTX_ERROR_404_HELP" ] = app .config [" ERROR_404_HELP" ]
258264 warnings .warn (
259265 "'ERROR_404_HELP' config setting is deprecated and will be "
260266 "removed in the future. Use 'RESTX_ERROR_404_HELP' instead." ,
261- DeprecationWarning
267+ DeprecationWarning ,
262268 )
263269
264-
265270 def __getattr__ (self , name ):
266271 try :
267272 return getattr (self .default_namespace , name )
@@ -407,7 +412,8 @@ def make_response(self, data, *args, **kwargs):
407412 kwargs .pop ("fallback_mediatype" , None ) or self .default_mediatype
408413 )
409414 mediatype = request .accept_mimetypes .best_match (
410- self .representations , default = default_mediatype ,
415+ self .representations ,
416+ default = default_mediatype ,
411417 )
412418 if mediatype is None :
413419 raise NotAcceptable ()
@@ -515,11 +521,16 @@ def endpoint(self, name):
515521 @property
516522 def specs_url (self ):
517523 """
518- The Swagger specifications relative url (ie. `swagger.json`)
524+ The Swagger specifications relative url (ie. `swagger.json`). If
525+ the spec_url_scheme attribute is set, then the full url is provided instead
526+ (e.g. http://localhost/swaggger.json).
519527
520528 :rtype: str
521529 """
522- return url_for (self .endpoint ("specs" ))
530+ external = None if self .specs_url_scheme is None else True
531+ return url_for (
532+ self .endpoint ("specs" ), _scheme = self .specs_url_scheme , _external = external
533+ )
523534
524535 @property
525536 def base_url (self ):
0 commit comments