API Contract Until Passing
This loop ensures that the API implementation aligns with the OpenAPI specification by repeatedly validating the contract using swagger-cli until all requirements are met or the maximum iteration limit is reached.
Goal
API implementation matches OpenAPI specification
How to Run
Run this loop in a coding environment to validate your OpenAPI spec compliance through iterative corrections.
- 01
Set Up Environment
Ensure `openapi.yaml` exists in your project root and `swagger-cli` is installed globally or available in your PATH.
- 02
Initiate Loop
Use the kickoff prompt to start the loop. The agent will attempt to correct validation issues in each iteration.
- 03
Monitor Iterations
The loop runs up to 10 times. If it exits early due to success, review changes made. If it hits max iterations, manual intervention may be needed.
- 04
Verify Final Output
After exit, confirm the `openapi.yaml` passes validation independently using `swagger-cli validate openapi.yaml`.
Workflow Steps
- 01
Act
The agent attempts to fix any validation issues in the API implementation based on the current state of openapi.yaml.
- 02
Run Check
Execute `swagger-cli validate openapi.yaml` to assess conformance with OpenAPI standards.
- 03
Inspect Result
Analyze validation output for errors. If none, exit loop; otherwise, proceed to next iteration.
- 04
Repeat
If validation failed and iterations remain under 10, return to Act step with updated context.
Kickoff Prompt
Start the "API Contract Until Passing" loop. Goal: API implementation matches OpenAPI specification Max iterations: 10 Between iterations run: swagger-cli validate openapi.yaml Exit when: Contract validation succeeds Please validate the API implementation against the OpenAPI specification defined in 'openapi.yaml'. Run swagger-cli to check for compliance and fix any issues found until validation passes or 10 iterations are completed. Self-pace this loop. After each iteration, run `swagger-cli validate openapi.yaml` and evaluate the output, and only continue if the exit condition is not met (Contract validation succeeds). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.
Guardrails
hardcoded- ·Do not modify the original OpenAPI specification file directly unless explicitly instructed.
- ·Ensure all generated code adheres strictly to the OpenAPI contract.
- ·Handle validation errors gracefully without exceeding iteration limits.
- ·Maintain idempotent behavior across loop iterations to prevent regression.
Flow Diagram
Related loops — API
API
Resolve API Error Responses
This loop standardizes API error responses across the application to improve client-side error handling and debugging. It ensures all error responses follow a consistent structure (e.g., RFC 7807 Problem Details format) with appropriate HTTP status codes and machine-readable error codes.
API
Fix Failing Integration Endpoints
Automatically detects and resolves issues in failing API integration endpoints through iterative testing and code modifications.
API
API Performance Budget
A coding loop focused on optimizing API performance to ensure P95 latency stays under a defined target threshold. This loop iteratively runs load tests, analyzes bottlenecks, and implements optimizations until the goal is achieved or maximum iterations are reached.