-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp1.py
More file actions
38 lines (29 loc) · 846 Bytes
/
app1.py
File metadata and controls
38 lines (29 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from flask import Flask, jsonify
from flask_restful import Resource, Api
from flask_swagger_ui import get_swaggerui_blueprint
import json
app = Flask(__name__)
api = Api(app)
# Define a sample resource
class HelloWorld(Resource):
def get(self):
return jsonify({'message': 'Hello, World!'})
# Add the resource to the API
api.add_resource(HelloWorld, '/hello')
# Configure Swagger UI
SWAGGER_URL = '/swagger'
API_URL = 'http://127.0.0.1:5000/swagger.json'
swaggerui_blueprint = get_swaggerui_blueprint(
SWAGGER_URL,
API_URL,
config={
'app_name': "Sample API"
}
)
app.register_blueprint(swaggerui_blueprint, url_prefix=SWAGGER_URL)
@app.route('/swagger.json')
def swagger():
with open('swagger.json', 'r') as f:
return jsonify(json.load(f))
if __name__ == '__main__':
app.run(debug=True)