Skip to content

Commit 56d224a

Browse files
authored
Merge pull request #20 from MinaFoundation/disallow-query-params
Specify swagger UI version and disallow query params
2 parents 4ae425d + 91ed609 commit 56d224a

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
*_test.env
1+
*_test*.env
22

33
.env
4+
env.sh

api/minanet_app/flask_api.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,25 @@ def get_snark_conn():
5050
},
5151
"host": BaseConfig.SWAGGER_HOST, # overrides localhost:500
5252
"basePath": "/uptimescore", # base bash for blueprint registration
53-
"schemes": ["https", "http" ],
53+
"schemes": ["https", "http"],
5454
"operationId": "uptimescore",
5555
}
5656

57+
swagger_config = Swagger.DEFAULT_CONFIG
58+
swagger_config["swagger_ui_bundle_js"] = (
59+
"//unpkg.com/[email protected]/swagger-ui-bundle.js"
60+
)
61+
swagger_config["swagger_ui_standalone_preset_js"] = (
62+
"//unpkg.com/[email protected]/swagger-ui-standalone-preset.js"
63+
)
64+
swagger_config["jquery_js"] = "//unpkg.com/[email protected]/dist/jquery.min.js"
65+
swagger_config["swagger_ui_css"] = "//unpkg.com/[email protected]/swagger-ui.css"
5766

5867
# create app instance
5968
app = Flask(__name__)
6069
app.config.from_mapping(config)
6170
cache = Cache(app)
62-
swagger = Swagger(app, template=template)
71+
swagger = Swagger(app, template=template, config=swagger_config)
6372

6473

6574
# 1
@@ -285,5 +294,15 @@ def handle_exception(e):
285294
return jsonify(response), 500
286295

287296

297+
@app.before_request
298+
def disallow_all_get_params():
299+
if request.args:
300+
response = {
301+
"error": "Query parameters are not allowed",
302+
"error_message": "This application does not support query parameters in requests.",
303+
}
304+
return jsonify(response), 400
305+
306+
288307
if __name__ == "__main__":
289308
app.run(host=BaseConfig.API_HOST, port=BaseConfig.API_PORT, debug=BaseConfig.DEBUG)

0 commit comments

Comments
 (0)