liveBook · Manning

OpenAPI specification

As explained in Software Testing with Generative AI

OpenAPI is a standard for describing HTTP APIs and their operations, data structures, and constraints in a machine-readable format.

An OpenAPI specification describes API data structures and rules in a standardized, machine-readable format. In prompts, it provides explicit constraints for generating structured test data instead of requiring custom field definitions. section 6.2.1

Using OpenAPI in data-generation prompts provides:

  • Ready-made structure for names, types, required fields, patterns, and numeric limits. section 6.2.1
  • A widely adopted format that can improve an LLM’s chance of producing useful output. section 6.2.1
  • A basis for checking generated objects against schema rules before using them. section 6.2.1

Schema-driven JSON generation

A prompt can request three randomized JSON objects based on a delimited OpenAPI 3.0 schema and require confirmation that every object matches its rules. A Room schema can constrain accessibility, room types, features, required properties, and room-price bounds. section 6.2.1

###
openapi: 3.0.0
components:
  schemas:
    Room:
      title: Room
      type: object
      properties:
        accessible:
          type: boolean
        description:
          type: string
        type:
          type: string
          pattern: Single|Double|Twin|Family|Suite
        features:
          type: array
          items:
            type: string
            pattern: WiFi|TV|Radio|Refreshments|Safe|
        image:
          type: string
        roomNumber:
          type: string
        roomPrice:
          type: integer
          format: int32
          minimum: 0
          maximum: 999
          exclusiveMinimum: true
          exclusiveMaximum: false
        roomid:
          type: integer
          format: int32
      required:
        - accessible
        - description
        - features
        - image
        - roomNumber
        - roomPrice
###

Inspect a concrete Room schema showing required properties, enumerated patterns, arrays, and numeric constraints. section 6.2.1

How Software Testing with Generative AI covers it

How deep it goes
Demonstrates schema-guided JSON generation and validation, but does not explain OpenAPI semantics beyond data constraints.
Examples
Uses a Room schema, a three-object JSON-generation prompt, and generated hotel-room records.
What it assumes
Assumes familiarity with structured data and prompts while supplying field-level constraints through an existing specification.
What you can do after
Apply it via prompts to generate structured JSON test data and check outputs against declared schema rules.
How it connects
Connects OpenAPI with JSON, XML, XSD, SQL, API specifications, prompts, and test data.

Also explained in

Compare how 12 books explain OpenAPI specification →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Testing with Generative AI. The section links point to the parts of the book it draws on.