### Install flask-classful-apispec via pip Source: https://github.com/dev-rijan/flask-classful-apispec/blob/master/README.rst This command installs the flask-classful-apispec library and its dependencies using pip, the Python package installer. It's the first step to integrate the library into your project. ```bash $ pip install flask-classful-apispec ``` -------------------------------- ### Example Generated OpenAPI Specification Source: https://github.com/dev-rijan/flask-classful-apispec/blob/master/README.rst This JSON snippet shows the OpenAPI 3.0.2 specification generated by the previous Python code. It defines a GET endpoint for '/pet/' with a description and a 200 response schema referencing a 'Pet' component. The 'Pet' schema itself is defined under 'components/schemas', detailing its properties (name, id, category) and their types. ```json { "paths": { "/pet/": { "get": { "description": "Get a list of pets", "responses": { "200": { "schema": { "$ref": "#/components/schemas/Pet" } } } } } }, "info": { "title": "Swagger petstore", "version": "0.1.1" }, "openapi": "3.0.2", "components": { "schemas": { "Pet": { "type": "object", "properties": { "name": { "type": "string" }, "id": { "type": "integer" }, "category": { "type": "string" } } } } } } ``` -------------------------------- ### Generate OpenAPI Spec from Flask-Classful View Source: https://github.com/dev-rijan/flask-classful-apispec/blob/master/README.rst This Python example demonstrates how to integrate flask-classful-apispec with a Flask application. It sets up a Flask app, defines a PetSchema using Marshmallow, and creates a PetView using Flask-Classful. The APISpec instance then parses the docstring of the PetView's index method to automatically generate an OpenAPI 3.0.2 specification, which is then printed to the console. ```python import json from flask import Flask from flask_classful import FlaskView from flask_classful_apispec import APISpec from marshmallow import Schema, fields app = Flask(__name__) app.config["DOC_TITLE"] = "Swagger petstore" app.config["DOC_VERSION"] = "0.1.1" app.config["DOC_OPEN_API_VERSION"] = "3.0.2" spec = APISpec(app) pets = [ {'id': 0, 'name': 'Kitty', 'category': 'cat'}, {'id': 1, 'name': 'Coco', 'category': 'dog'} ] class PetSchema(Schema): id = fields.Integer() name = fields.String() category = fields.String() class PetView(FlaskView): def index(self): """A pet api endpoint. --- description: Get a list of pets responses: 200: schema: PetSchema """ return PetSchema(many=True).dumps(pets) PetView.register(app) spec.paths(PetView) print(json.dumps(spec.to_dict(), indent=2)) if __name__ == "__main__": app.run() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.