From OpenAPI spec to a tested collection with an AI agent
Importing an OpenAPI spec gives you a folder per tag and a request per operation in seconds (see OpenAPI to a working collection). What it doesn't give you is tests: every request is a blank page. An AI agent with the Requestarium MCP server can fill those pages, because it can read the spec, send the requests and see what comes back.
1. Import
With the MCP server connected and your API running locally:
Import
./openapi.yamlinto Requestarium as "Orders API". Do a dry run first and show me what it will create.
The agent calls import_collection with dryRun, shows the folders and requests, and imports when you say so. The import_api prompt does the same in one step (see four MCP prompts).
2. Environment
Which variables do the requests need? Create a "Local" environment with baseUrl http://localhost:8080. Ask me for anything secret.
The agent lists the variables it found, such as {{baseUrl}} and {{bearerToken}}, and creates the environment with create_environment. For a token it should ask you, and store it as a secret. Environment values are never shown back to the agent.
3. Tests, one folder at a time
For each GET request in the "Orders" folder: send it once against Local, then write a test script. Check the status code, the content type, and the required fields and their types from the spec's response schema. Use the real response for example values only where the spec doesn't say. Show me the scripts before saving.
Ask for one folder, not the whole spec. You'll review every script, and twenty is a lot to review.
A typical result:
pm.test('returns 200 with JSON', () => {
pm.response.to.have.status(200);
pm.response.to.have.header('Content-Type');
});
const body = pm.response.json();
pm.test('has the required order fields', () => {
pm.expect(body).to.have.property('id');
pm.expect(body.status).to.be.oneOf(['pending', 'paid', 'shipped', 'cancelled']);
pm.expect(body.total).to.be.a('number');
});4. Write requests, carefully
POST, PUT and DELETE change data. Don't let the agent fire them blindly:
For the POST /orders request, write a body from the spec's example, send it to Local once, and add tests. Then add a DELETE request that removes the order it created, so the folder cleans up after itself.
Now the folder can run repeatedly without filling your database. See setup and cleanup steps.
What to check in the review
- Spec vs reality. If a test fails on the first run, either the API or the spec is wrong. Decide which; don't let the agent "fix" a test to match a bug.
- Over-specific values.
to.equal('pending')on a field that can have four values will break tomorrow.oneOffrom the spec's enum is better. - Types and required fields from the schema are the most valuable checks. Exact example values are the least.
Then run it like any other collection
requestarium run-collection "Orders API" --env LocalFrom here it's a normal collection: it runs in the app, the CLI and CI.