Use the following prompt with an AI to generate feature files and step definitions from a Swagger JSON file that match this project's structure:
You are an API test automation expert. Analyze the provided Swagger JSON file and create Cucumber feature files and step definitions following the project structure below.
- Feature files:
src/features/{feature-name}/{feature-name}.feature - Step definition files:
src/features/steps/{feature-name}/{feature-name}.step.ts - Service files:
src/services/{feature-name}Service.ts - Model files:
src/models/{feature-name}.model.ts - Endpoint management:
src/config/{featureName}.endpoints.ts(one file per API, not a shared endpoints.ts) - Keycloak token path only:
src/config/keycloak.endpoints.ts(framework auth, do not edit per feature)
@{tagName}
Feature: {API Name} API
Scenario: {Scenario description}
Given I have authentication credentials for the configured test user
When I send a POST request to get access token
And I have a valid authorization token from the response
And I initialize {service-name} service with authorization token
When I send a {METHOD} request to the {endpoint-name} endpoint
Then the response status should be {status-code}
And the response should contain {validation}import { Given, When, Then } from '@cucumber/cucumber';
import { logger } from '../../../utils/logger';
import { ServiceHelper } from '../../../utils/serviceHelper';
import { ResponseHelper } from '../../../utils/responseHelper';
import { {ServiceName}Service } from '../../../services/{serviceName}Service';
import { endpoints } from '../../../config/{featureName}.endpoints';
let {serviceName}Service: {ServiceName}Service;
let response: any;
let queryParams: { [key: string]: any } = {};
Given('I initialize {service-name} service with authorization token', async () => {
logger.logStep('Given', 'I initialize {service-name} service with authorization token');
{serviceName}Service = await ServiceHelper.initialize{ServiceName}Service();
});
When('I send a {METHOD} request to the {endpoint-name} endpoint', async () => {
logger.logStep('When', 'I send a {METHOD} request to the {endpoint-name} endpoint');
response = await {serviceName}Service.{methodName}({params});
await ResponseHelper.logAndSetResponse(response, '{METHOD}', endpoints.{path}.{endpoint}, {params});
});
Then('the response status should be {int}', async (status: number) => {
// This step is defined in common.step.ts, don't redefine here
});
Then('the response should contain {validation}', async () => {
logger.logStep('Then', 'the response should contain {validation}');
await ResponseHelper.validateArrayResponse(response, '{ItemName}');
});import { ApiClient } from '../core/api/apiClient';
import { {ModelName} } from '../models/{modelName}.model';
import { endpoints } from '../config/{featureName}.endpoints';
export class {ServiceName}Service {
constructor(private api: ApiClient) {}
{methodName}({params}) {
return this.api.{httpMethod}(endpoints.{path}.{endpoint}, {body}, {options});
}
}Each API gets its own src/config/{featureName}.endpoints.ts (full baseURI from Swagger servers + resource paths). Do NOT use or create src/config/endpoints.ts.
export const endpoints = {
{apiGroup}: {
baseURI: 'https://host/api/{apiGroup}/v{version}',
{resource}: {
list: '/{resource}',
create: '/{resource}',
byId: (id: string) => `/{resource}/${id}`,
}
}
} as const;-
ServiceHelper: For service initialization
initialize{ServiceName}Service(token?: string)getTokenFromTestDataOrEnv()getTokenFromAuthResponse()
-
ResponseHelper: For response handling
logAndSetResponse(response, method, url, params?)validateStatus(response, expectedStatus)validateContentType(response, expectedType)validateArrayResponse(response, itemName)validateItemCount(response, maxCount)getResponseBody(response)
-
AuthHelper: For authentication
getConfiguredCredentials()— uses credentials from the test-run UI (never hardcode usernames in features)getCredentialsForUser(username)— legacy; prefer the configured test user stepgetToken(credentials)getAccessToken()
Use logger in every step:
logger.logStep('Given|When|Then', 'step description');
logger.logRequest(method, url, headers, body);
logger.logResponse(status, statusText, headers);
logger.info('message');
logger.debug('message');
logger.error('message', error);For query parameters:
let queryParams: { [key: string]: string | number } = {};
When('I send a GET request with {string} parameter', async (param: string) => {
queryParams = { paramName: param };
response = await service.method(queryParams);
await ResponseHelper.logAndSetResponse(response, 'GET', endpoint, queryParams);
});For POST/PUT requests:
When('I send a POST request with body', async () => {
const body = { /* test data */ };
response = await service.create(body);
await ResponseHelper.logAndSetResponse(response, 'POST', endpoint, body);
});Create TypeScript interface/model for each API resource:
export interface {ModelName} {
id?: string;
// All fields from Swagger
}This platform does not always match generic Swagger defaults. Use these in every generated feature:
| Operation | Expected status in Then the response status should be {code} |
|---|---|
| GET list or GET by id | Then the response status should be 200 or 206 (accept either) |
| POST create success | 201 |
| PATCH/PUT update success | 200 or 204 (per Swagger) |
| DELETE success | 204 or 200 (per Swagger) |
| Validation / missing required field | 400 |
- For every GET list or GET retrieve scenario, assert with
Then the response status should be 200 or 206(shared step incommon.step.ts). - PATCH service methods must send
Content-Type: application/merge-patch+json(plainapplication/jsonon PATCH returns 400 on GCU). - For POST bodies that reference another resource by
id, create that parent in the step first and use the realidfrom the create response (never fake IDs).
-
Analyze Swagger JSON and extract:
- All endpoints (path, method, parameters, request body, responses)
- Required authentication for each endpoint
- Response schemas
- Query parameters
- Path parameters
-
Group endpoints (e.g., productCatalogManagement, userManagement, etc.)
-
For each endpoint, create:
- Feature file (at least 2-3 scenarios: success, validation error, edge cases)
- Step definition file
- Service class
- Model interface (if request/response body exists)
- Add
src/config/{featureName}.endpoints.tsfor that API
-
Scenarios should include:
- Authentication setup (always)
- Service initialization
- API call
- Status validation
- Response validation (data structure, content type, etc.)
-
Use tags:
- Meaningful tags for each feature (@get{Resource}List, @create{Resource}, etc.)
If Swagger has this endpoint:
{
"paths": {
"/api/v1/products": {
"get": {
"summary": "Get products list",
"parameters": [
{"name": "limit", "in": "query", "type": "integer"},
{"name": "sort", "in": "query", "type": "string"}
],
"responses": {
"206": {
"description": "Partial Content (list)",
"schema": {"type": "array", "items": {"$ref": "#/definitions/Product"}}
}
}
}
}
}
}Create:
src/config/product.endpoints.ts- Products API pathssrc/models/product.model.ts- Product interfacesrc/services/productService.ts- ProductService classsrc/features/products/products.feature- Feature filesrc/features/steps/products/products.step.ts- Step definitions
- Step defs: import only
Given,When,Thenfrom@cucumber/cucumber— neverAnd()orBut() - Strict TS:
requireResponseId()fromsrc/utils/strictHelpers.tsfor ids; no rawprocess.env→string - Services:
buildApiUrl(baseURI, path)fromsrc/utils/apiUrl.ts— never call API with path-only URL - Step defs: every step pattern ends with
for <featureName>(e.g.for partyManagement4); useconst FEATURE = 'partyManagement4'in step file; feature Gherkin must match - Use logger in all steps
- Use util classes, avoid code duplication
- Use ResponseHelper methods for response validation
- Use ServiceHelper for service initialization
- Don't hardcode URLs; use the feature's
{featureName}.endpoints.tsfile - Pay attention to TypeScript type safety
- Create at least 2-3 scenarios per endpoint (success, error, edge case)
- GET list/retrieve scenarios:
Then the response status should be 200 or 206; create scenarios assert 201
Now analyze the provided Swagger JSON file and create all files according to the rules above.
- Prepare your Swagger JSON file
- Paste the prompt above to an AI
- Add your Swagger JSON
- The AI will generate all files for you:
- Feature files
- Step definitions
- Service classes
- Model interfaces
- Endpoint configurations
[Paste the prompt above]
Swagger JSON:
{
"swagger": "2.0",
"info": { ... },
"paths": { ... },
"definitions": { ... }
}