| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
This example demonstrates how to use Graph-sitter to automatically add OpenAPI decorators (@response and @expect) to Flask-RESTx API endpoints. The migration script analyzes existing code patterns and adds appropriate decorators to improve API documentation.
Note
This codemod helps maintain consistent API documentation by automatically analyzing endpoint behavior and adding appropriate OpenAPI decorators.
The script automates the documentation process in several key steps:
Resource Class Detection
for cls in codebase.classes:
if cls.is_subclass_of("Resource"):
# Process Flask-RESTx resource classesResponse Analysis
response_schemas = analyze_method_returns(method)Parameter Analysis
expect_schema = analyze_method_params(method)Automated Analysis
Consistent Documentation
Intelligent Schema Detection
# Before
@ns.route("/endpoint")
class MyResource(Resource):
def get(self):
return {"data": result}
# After
@ns.route("/endpoint")
class MyResource(Resource):
@ns.response(200, "Success", {"data": {"type": "any"}})
def get(self):
return {"data": result}# Before
@ns.route("/endpoint")
class MyResource(Resource):
def post(self):
data = request.json["name"]
return {"status": "success"}
# After
@ns.route("/endpoint")
class MyResource(Resource):
@ns.expect({"name": {"type": "any", "required": True}})
@ns.response(200, "Success", {"status": {"type": "any"}})
def post(self):
data = request.json["name"]
return {"status": "success"}Better API Documentation
Consistent Error Handling
Time Savings
# Install Graph-sitter
pip install graph-sitter
# Run the migration
python run.pyThe script will:
Feel free to submit issues and enhancement requests!
| Back | FazBrowse Home | New Git URL |