Modern QA2026The Prompt — tiles
Log inJoin
3 / 89 · 04 API & Contract Testing with AI · From OpenAPI Schema to Test Suite← prev⊞ allnext →☰ Read as one page

1.3The Prompt

Analyze this OpenAPI 3.0 schema and generate a comprehensive test suite.

```yaml
openapi: 3.0.3
paths:
  /api/v2/products/{id}:
    get:
      summary: Get product by ID
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: Product found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Product'
        '404':
          description: Product not found
        '401':
          description: Unauthorized
    put:
      summary: Update product
      security:
        - BearerAuth: [admin]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ProductUpdate'
      responses:
        '200':
          description: Updated
        '400':
          description: Validation error
        '403':
          description: Forbidden (not admin)

components:
  schemas:
    Product:
      type: object
      properties:
        id: { type: string, format: uuid }
        name: { type: string, minLength: 1, maxLength: 200 }
        price: { type: number, minimum: 0 }
        category: { type: string, enum: [electronics, clothing, food, other] }
        in_stock: { type: boolean }
    ProductUpdate:
      type: object
      required: [name, price]
      properties:
        name: { type: string, minLength: 1, maxLength: 200 }
        price: { type: number, minimum: 0 }
        category: { type: string, enum: [electronics, clothing, food, other] }

Generate tests using pytest + httpx. For each endpoint and method, include:

  1. Happy path with valid data
  2. Every documented error response (trigger each status code)
  3. Boundary values for constrained fields (minLength, maxLength, minimum)
  4. Type mismatch tests (string where number expected, etc.)
  5. Missing required field tests
  6. Invalid enum value tests
  7. Auth tests (missing token, expired token, wrong role)