The Problem: Schema Duplication
You've carefully documented your API with OpenAPI. Every endpoint has request schemas, response schemas, field descriptions, and validation rules. Then you want to create a demo, and suddenly you're writing it all again:
# Traditional approach: manually define every form field
- rest: POST /users
form:
- name: email
label: "Email Address"
type: text
required: true
- name: name
label: "Full Name"
type: text
- name: role
label: "Role"
type: select
options:
- value: user
label: User
- value: admin
label: Admin
results:
- key: id
label: "User ID"
type: mono
- key: email
label: "Email"
- key: createdAt
label: "Created"
type: relative_time
This is tedious, error-prone, and quickly falls out of sync with your actual API. When you add a field to your API, you have to remember to update the demo too.
The Solution: Point to Your OpenAPI Spec
DemoScript can read your OpenAPI specification and automatically generate form fields from request body schemas and result displays from response schemas. Here's how:
# Step 1: Add your OpenAPI spec URL to settings
settings:
base_url: "https://api.example.com"
openapi: "https://api.example.com/docs/openapi.json"
steps:
# Step 2: Just specify the endpoint - forms are auto-generated!
- rest: POST /users
defaults:
email: "demo@example.com"
role: "admin"
That's it. DemoScript will:
- Fetch your OpenAPI spec
- Find the
POST /usersendpoint - Extract the request body schema
- Generate form fields with correct types, labels, and validation
- Apply your
defaults:as pre-filled values
How Form Generation Works
Request Body to Form Fields
DemoScript maps OpenAPI schema types to appropriate form controls:
| OpenAPI Type | Form Field Type | Example |
|---|---|---|
string |
Text input | Name, email, description |
integer / number |
Number input | Age, quantity, price |
boolean |
Select (true/false) | Active, verified |
string + enum |
Dropdown select | Status, role, country |
array / object |
JSON textarea | Tags, metadata, config |
Field labels come from the description property in your schema, or are auto-generated from the property name (e.g., firstName becomes "First Name").
Response Schema to Result Display
When you omit the results: field, DemoScript can auto-generate result displays from the OpenAPI response schema. It uses intelligent type mapping based on field names and formats:
| OpenAPI Schema | Display Type | Rendering |
|---|---|---|
format: date-time |
relative_time |
"2 minutes ago" |
format: uri |
link |
Clickable link |
format: uuid |
mono |
Monospace font |
Name contains id |
mono |
Monospace font |
Name contains price, amount |
currency |
$1,234.56 |
Name contains address, hash |
ref |
Truncated with copy |
type: array or object |
json |
Collapsible tree |
Before vs After
Before (50+ lines of manual config):
- rest: POST /users
form:
- name: email
label: "Email"
type: text
required: true
- name: name
label: "Name"
type: text
- name: role
type: select
options: [...]
results:
- key: id
label: "User ID"
type: mono
- key: createdAt
type: relative_time
# ... more fields
After (3 lines):
- rest: POST /users
defaults:
email: "demo@example.com"
Customization Options
Auto-generation doesn't mean loss of control. You can customize at multiple levels:
1. Pre-fill Values with defaults:
Set default values that appear in the auto-generated form:
- rest: POST /users
defaults:
email: "demo@example.com"
role: "admin"
company: "Acme Corp"
2. Override Specific Fields with form:
Need to customize a label or hide a field? Override just what you need:
- rest: POST /users
defaults:
email: "demo@example.com"
form:
- name: email
label: "Work Email" # Custom label
- name: internal_id
hidden: true # Hide from form
The form: override uses smart merging — you only specify what you want to change. Type, required status, and options are inherited from OpenAPI.
3. Override Results Display
To show specific fields instead of auto-generated results:
- rest: POST /users
results:
- key: id
label: "Your User ID"
type: mono
- key: email
label: "Confirmed Email"
4. Per-Step OpenAPI Override
Calling an external API with a different spec? Override per-step:
- rest: POST /external-service/webhook
openapi: "https://external-api.com/openapi.json"
defaults:
event: "user.created"
Supported Specifications
DemoScript supports both OpenAPI 3.0 and Swagger 2.0 specifications:
- OpenAPI 3.0:
requestBody.content['application/json'].schema - Swagger 2.0:
parameterswithin: body - Schema references:
$refto#/components/schemas/or#/definitions/ - Composition:
allOffor schema inheritance
Tip: Works with Popular API Frameworks
Any framework that generates OpenAPI specs works with DemoScript:
- FastAPI —
/docs/openapi.json - Express + Swagger —
/api-docs/swagger.json - Spring Boot —
/v3/api-docs - Django REST —
/api/schema/ - NestJS —
/api-json
Real-World Example
Here's a complete demo using the Swagger Petstore API — notice how little configuration is needed:
title: "Petstore API Demo"
settings:
base_url: "https://petstore.swagger.io/v2"
openapi: "https://petstore.swagger.io/v2/swagger.json"
steps:
- slide: |
# Welcome to the Pet Store
Let's explore the API with live requests.
- rest: GET /pet/findByStatus?status=available
title: "Find Available Pets"
# Results auto-generated from response schema!
- rest: POST /pet
title: "Add a New Pet"
defaults:
name: "Fluffy"
status: "available"
# Form fields auto-generated from request schema!
- rest: GET /store/inventory
title: "Check Inventory"
# Returns object - displayed as JSON tree
No manual form definitions. No result field mappings. The OpenAPI spec provides everything DemoScript needs.
Try It Yourself
The easiest way to see this in action is with DemoScript's built-in Sandbox API, which includes a complete OpenAPI spec:
settings:
base_url: "/sandbox"
openapi: "/sandbox/openapi.json"
steps:
- rest: POST /auth/login
defaults:
email: "demo@example.com"
password: "demo123"
- rest: POST /users
defaults:
name: "New User"
email: "user@example.com"
Run it locally with npx demoscript serve or check out the example gallery for live demos.
Stop Duplicating Your API Schema
Let DemoScript read your OpenAPI spec and generate demos automatically.
Summary
- Add
openapi:to your settings to enable auto-generation - Form fields are created from request body schemas
- Result displays are inferred from response schemas
- Use
defaults:to pre-fill values - Use
form:orresults:to override when needed - Works with OpenAPI 3.0 and Swagger 2.0
This integration keeps your demos in sync with your API automatically. When your API changes, just update your OpenAPI spec — your demos update too.