| 1 | """ |
| 2 | Example loading all specs from YAML template |
| 3 | """ |
| 4 | from flask import Flask, jsonify |
| 5 | |
| 6 | from flasgger import Swagger |
| 7 | |
| 8 | app = Flask(__name__) |
| 9 | app.config['SWAGGER'] = { |
| 10 | 'title': 'Colors API', |
| 11 | 'uiversion': 2 |
| 12 | } |
| 13 | Swagger(app, template_file='colors_template.yaml') |
| 14 | |
| 15 | |
| 16 | @app.route('/colors/<palette>/') |
| 17 | def colors(palette): |
| 18 | """ |
| 19 | Example using a dictionary as specification |
| 20 | This is the description |
| 21 | You can also set 'summary' and 'description' in |
| 22 | specs_dict |
| 23 | --- |
| 24 | # values here overrides the specs dict |
| 25 | deprecated: true |
| 26 | """ |
| 27 | all_colors = { |
| 28 | 'cmyk': ['cyan', 'magenta', 'yellow', 'black'], |
| 29 | 'rgb': ['red', 'green', 'blue'] |
| 30 | } |
| 31 | if palette == 'all': |
| 32 | result = all_colors |
| 33 | else: |
| 34 | result = {palette: all_colors.get(palette)} |
| 35 | |
| 36 | return jsonify(result) |
| 37 | |
| 38 | if __name__ == "__main__": |
| 39 | app.run(debug=True) |