Automates the creation of new PaaSTA API endpoints following established patterns. This skill guides you through adding a new endpoint to the PaaSTA API, including view function, route registration, Swagger/OpenAPI documentation, and comprehensive tests.
Usage
/paasta-api-endpoint
What This Skill Does
This skill will:
Gather endpoint requirements interactively
Generate a view function in paasta_tools/api/views/
Register the route in paasta_tools/api/api.py
Add Swagger 2.0 documentation to swagger.json
Add OpenAPI 3.0 documentation to oapi.yaml
Generate unit tests following PaaSTA conventions
Run the OpenAPI code generator
Run tests to verify the implementation
When to Use This Skill
Use this skill when you need to:
Add a new GET/POST/PUT/DELETE endpoint to the PaaSTA API
Ensure consistency with existing API patterns
Automatically generate boilerplate code and documentation
Get comprehensive test coverage from the start
Instructions
When this skill is invoked, follow these steps:
Step 1: Gather Requirements
Ask the user the following questions (use AskUserQuestion tool for better UX):
Endpoint purpose: What does this endpoint do? (brief description)
HTTP method: GET, POST, PUT, or DELETE?
URL pattern: What's the URL path? (e.g., /v1/services/{service}/instances/{instance}/status)
Path parameters: What path parameters are needed? (e.g., service, instance, deploy_group)
Query parameters: Any query parameters? (optional)
Request body: Does this endpoint accept a request body? If yes, what fields?
Response structure: What does the response look like? (e.g., {"status": "running", "count": 5})
Error cases: What error scenarios should be handled? (e.g., 404 not found, 500 config error)
View file: Which view file should contain this endpoint?
Use existing: service.py, instance.py, autoscaler.py, etc.
Or create new: provide filename
Utility functions: What existing utility functions from paasta_tools/utils.py will be used?
Step 2: Generate View Function
Create the view function following this template:
@view_config(route_name="<route_name>", request_method="<METHOD>", renderer="json")def <function_name>(request):
"""<Docstring describing what this endpoint does>."""# Extract parameters from request
param1 = request.swagger_data.get("param1")
param2 = request.swagger_data.get("param2")
soa_dir = settings.soa_dir
try:
# Call utility functions to get data
result = some_utility_function(param1, param2, soa_dir=soa_dir)
# Build response
response_body = {"key": result}
return Response(json_body=response_body, status_code=200)
except SpecificException as e:
raise ApiFailure(str(e), 404)
except AnotherException as e:
raise ApiFailure(str(e), 500)
Important conventions:
Import Response from pyramid.response for explicit status codes
Import ApiFailure from paasta_tools.api.views.exception for error handling
All imports at the top of the file (no inline imports)
Use settings.soa_dir to get the SOA configuration directory
Return 200 for success, 404 for not found, 500 for server errors
Always include proper error handling with try/except
Step 3: Register Route
Add route registration to paasta_tools/api/api.py: