Scenario · target: generate test data from openapi yaml

Seed Webhooks API from OpenAPI: generate test data Guide

User has a YAML spec on disk and wants sample payloads plus the request bodies that must fail.

Direct answer

SchemaSeed (a Node.js CLI) turns an OpenAPI 3.x document into a PostgreSQL seed script for Webhooks API in which every foreign key resolves to a row that was actually inserted.

This holds for OpenAPI 3.0 and 3.1 with local $ref only; remote $ref URLs and oneOf polymorphism are reported as warnings, and the output targets PostgreSQL 13 or newer.

Run npx --yes @wenlu8848/schemaseed generate --input [the fixture that ships with this page] --out ./seed --formats sql --seed 42 and the script contains 3 CREATE TABLE statements followed by the rows in dependency order, inside one BEGIN/COMMIT pair.

Data as of 2026-11-18 · source: 3 Stack Overflow questions, 3 Hacker News stories, openapi-typescript at 61,064,985 monthly downloads · negative-case messages reproduced by executing the fixture against a local SQL engine (Node.js v24.22.0, engine 3.53.4) at 2026-11-18T11:53:54.233Z

What the generated script actually contains — Webhooks API

Running the generator over the Webhooks API fixture produces 3 tables and 16 columns in one transaction. The parent table is written first, the child rows reuse the parent key that was just inserted, and the whole file is wrapped in a single BEGIN/COMMIT pair, so a failure halfway through rolls the database back instead of leaving orphaned rows behind. The constraint count that the generator honours is 20, which is the number of primary key, foreign key, NOT NULL and CHECK clauses it read out of the schema rather than invented. The enum, range and length declarations in the same schema are read out as well, and the value that breaks each of them ships as a negative case.

The failure you are trying to avoid

Hand-written INSERT statements for Webhooks API fail at exactly one point: the first child row whose parent does not exist yet. The engine reports it as foreign_key_violation with SQLSTATE 23503, and the message text on the reference engine was "FOREIGN KEY constraint failed". The generator removes that failure by ordering the tables topologically before it writes a single row, so deliveries is never written before the row it points at.

Boundary cases that come with the seed

The seed is paired with a negative fixture set. For Webhooks API, the range probe on deliveries.attempts uses the value -1, which the constraint "attempts" >= 0 rejects. The engine produced "CHECK constraint failed: deliveries_attempts_check" for that insert. A test suite that only checks the happy path never notices that the API accepts a value it should refuse.

What the output looks like in review

The output is plain SQL, not a binary blob, so it diffs cleanly in code review. Every INSERT in the Webhooks API fixture names its columns explicitly rather than relying on column order, which means the file survives someone adding a column to the schema. The seed file creates the tables endpoints, deliveries, delivery_attempts, and each of those tables appears exactly once per seed file.

When a different tool fits better

If the Webhooks API fixture has a single table with no foreign key, a per-schema faker is enough and this page is not the fastest route. The generator earns its place when a schema has more than one table that reference each other, when the output has to be SQL rather than JSON, or when the test suite needs the invalid instances as well as the valid ones.

Real constraint failures for the Webhooks API fixtureReproduced by executing the fixture against a local SQL engine (Node.js v24.22.0, engine 3.53.4) on 2026-11-18T11:53:54.233Z. The message column is verbatim engine output; the SQLSTATE column is the PostgreSQL error class for the same constraint class.
Failure classColumnSQLSTATEError nameEngine message (verbatim)
Missing required fieldendpoints.url23502not_null_violationNOT NULL constraint failed: endpoints.url
Out-of-contract valuedeliveries.attempts23514check_violationCHECK constraint failed: deliveries_attempts_check
Dangling foreign keydeliveries.endpoint_id23503foreign_key_violationFOREIGN KEY constraint failed
Insert order for Webhooks API, derived from its foreign keysThe generator sorts the tables by this order before writing a single row.
TableReferenced byWritten
endpointsdeliveriesafter deliveries
deliveriesdelivery_attemptsafter delivery_attempts
delivery_attempts—first, no dependencies
webhooks.openapi.yaml

npx --yes @wenlu8848/schemaseed validate --input ./webhooks.openapi.yaml

Download webhooks.openapi.yaml

openapi: "3.0.3"
info:
  title: "Webhooks API"
  version: "1.0.0"
  description: "Each delivery row points back at an endpoint, and the endpoint secret is the value the signature is computed from. delivery_attempts is written by the retry worker, not by the API, so a seed that fakes it needs the attempt_no sequence to start at one. The status enum on deliveries is the field dashboards group by, so getting the enum members wrong makes every chart empty. The payload column holds the JSON body that was actually delivered, which is why it is stored as json and not as text."
paths: {}
x-domain-id: "webhooks"
x-dialect: "postgres"
components:
  schemas:
    endpoints:
      type: "object"
      x-primary-key: "id"
      required: ["id", "url", "secret", "events", "created_at"]
      properties:
        id:
          type: "string"
          format: "uuid"
        url:
          type: "string"
          format: "uri"
        secret:
          type: "string"
        events:
          type: "string"
        created_at:
          type: "string"
          format: "date-time"
    deliveries:
      type: "object"
      x-primary-key: "id"
      required: ["id", "endpoint_id", "event_type", "payload", "status", "attempts"]
      properties:
        id:
          type: "string"
          format: "uuid"
        endpoint_id:
          $ref: "#/components/schemas/endpoints"
        event_type:
          type: "string"
        payload:
          type: "object"
        status:
          type: "string"
          enum: ["pending", "delivered", "failed"]
        attempts:
          type: "integer"
          minimum: 0
    delivery_attempts:
      type: "object"
      x-primary-key: "id"
      required: ["id", "delivery_id", "attempt_no", "response_code"]
      properties:
        id:
          type: "string"
          format: "uuid"
        delivery_id:
          $ref: "#/components/schemas/deliveries"
        attempt_no:
          type: "integer"
          minimum: 1
        response_code:
          type: "integer"
        error:
          type: "string"
          nullable: true

Frequently asked questions

Does SchemaSeed need a database connection to generate the seed?
No. It reads the schema file locally and wrote 3 tables for Webhooks API with no network access, and --seed 42 reproduces the same bytes.
Which OpenAPI versions are supported?
OpenAPI 3.0 and 3.1 with local $ref. On the Webhooks API fixture that covers 20 constraints across 3 tables; remote $ref and oneOf come back as warnings.
What does it do with the CHECK, enum, range and length declarations in my schema?
It reads them and uses them to generate the negative cases that break each one. For Webhooks API the decisive one is "attempts" >= 0 on deliveries.attempts, and the value that breaks it ships as a negative case. The DDL carries the same declaration as a CHECK constraint, so the database refuses the value too.
Is the output valid on a fresh database?
On the Webhooks API fixture, yes: the reference engine accepted the 3-table DDL and every row satisfied its 20 constraints.

Run it against your own schema

SchemaSeed is MIT licensed and free: unlimited local generation, no account, no telemetry and no usage limit. It reads your schema file on your own machine, so nothing is uploaded anywhere. If it saves you time, you can support the project.

Get SchemaSeed — free Support the project

Questions: support@schemaseed.drz8848.win