Skip to content

Commit

Permalink
Merge pull request #20 from MinaFoundation/disallow-query-params
Browse files Browse the repository at this point in the history
Specify swagger UI version and disallow query params
  • Loading branch information
piotr-iohk authored Jan 10, 2025
2 parents 4ae425d + 91ed609 commit 56d224a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*_test.env
*_test*.env

.env
env.sh
23 changes: 21 additions & 2 deletions api/minanet_app/flask_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,25 @@ def get_snark_conn():
},
"host": BaseConfig.SWAGGER_HOST, # overrides localhost:500
"basePath": "/uptimescore", # base bash for blueprint registration
"schemes": ["https", "http" ],
"schemes": ["https", "http"],
"operationId": "uptimescore",
}

swagger_config = Swagger.DEFAULT_CONFIG
swagger_config["swagger_ui_bundle_js"] = (
"//unpkg.com/[email protected]/swagger-ui-bundle.js"
)
swagger_config["swagger_ui_standalone_preset_js"] = (
"//unpkg.com/[email protected]/swagger-ui-standalone-preset.js"
)
swagger_config["jquery_js"] = "//unpkg.com/[email protected]/dist/jquery.min.js"
swagger_config["swagger_ui_css"] = "//unpkg.com/[email protected]/swagger-ui.css"

# create app instance
app = Flask(__name__)
app.config.from_mapping(config)
cache = Cache(app)
swagger = Swagger(app, template=template)
swagger = Swagger(app, template=template, config=swagger_config)


# 1
Expand Down Expand Up @@ -285,5 +294,15 @@ def handle_exception(e):
return jsonify(response), 500


@app.before_request
def disallow_all_get_params():
if request.args:
response = {
"error": "Query parameters are not allowed",
"error_message": "This application does not support query parameters in requests.",
}
return jsonify(response), 400


if __name__ == "__main__":
app.run(host=BaseConfig.API_HOST, port=BaseConfig.API_PORT, debug=BaseConfig.DEBUG)

0 comments on commit 56d224a

Please sign in to comment.