Scenario · target: generate sample records for rest api

Seed Shipping and carriers API from OpenAPI: generate sample records Guide

Integrator needs valid example requests and responses to paste into a client.

Direct answer

SchemaSeed (a Node.js CLI) turns an OpenAPI 3.x document into a PostgreSQL seed script for Shipping and carriers 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: 12 Stack Overflow questions, 1 Hacker News stories, csv at 10,685,333 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 — Shipping and

Running the generator over the Shipping and carriers API fixture produces 3 tables and 13 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 17, 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 Shipping and carriers 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 shipments 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 Shipping and carriers API, the range probe on shipments.weight_grams uses the value 0, which the constraint "weight_grams" > 0 rejects. The engine produced "CHECK constraint failed: shipments_weight_grams_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 Shipping and carriers 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 carriers, shipments, shipment_events, and each of those tables appears exactly once per seed file.

When a different tool fits better

If the Shipping and carriers 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 Shipping and carriers 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 fieldcarriers.code23502not_null_violationNOT NULL constraint failed: carriers.code
Out-of-contract valueshipments.weight_grams23514check_violationCHECK constraint failed: shipments_weight_grams_check
Dangling foreign keyshipments.carrier_id23503foreign_key_violationFOREIGN KEY constraint failed
Insert order for Shipping and carriers API, derived from its foreign keysThe generator sorts the tables by this order before writing a single row.
TableReferenced byWritten
carriersshipmentsafter shipments
shipmentsshipment_eventsafter shipment_events
shipment_events—first, no dependencies
carriers.json

npx --yes @wenlu8848/schemaseed generate --input ./logistics.openapi.yaml --out ./seed --formats json --count 10 --seed 42

Download logistics.openapi.yaml

[
  {
    "id": "b972526f-7090-4366-b3e3-adce2d653dd8",
    "code": "iris.fontaine@example.com",
    "name": "umbra-ember-415"
  },
  {
    "id": "59e2c5a3-7a79-4f85-8113-cc3d7e333799",
    "code": "Nairobi, Maple Street 249",
    "name": "Quinn Lund"
  },
  {
    "id": "74551070-2c54-40da-a16c-1db4531d9507",
    "code": "summit willow",
    "name": "Quinn Kaur"
  },
  {
    "id": "7e32a0ef-eb07-4e68-ba11-6f8b9ffd2c69",
    "code": "fay.okafor@example.com",
    "name": "Iris Grant"
  },
  {
    "id": "b14515c1-d9e1-4b39-af32-f120202613d7",
    "code": "zephyr ember",
    "name": "Lisbon, Riverside Lane 34"
  },
  {
    "id": "5861feba-ac70-489b-879a-4e1bf09e98a2",
    "code": "Quinn Kaur",
    "name": "cedar pebble"
  },
  {
    "id": "3a634f4e-ade1-4337-8042-a1bccae207fc",
    "code": "Tara Okafor",
    "name": "kai.jansen@example.com"
  },
  {
    "id": "f0cfbc19-07ef-4cc7-bb56-2f4e5aa06e5f",
    "code": "grove-kelp-35",
    "name": "Bogota, Oak Drive 239"
  },
  {
    "id": "5513dc09-a02e-459b-9025-5a41d4e2382c",
    "code": "Dara Grant",
    "name": "quartz-harbor-175"
  },
  {
    "id": "9b8cb26b-dd9b-4040-acd4-62a64d3094cb",
    "code": "Kai Kaur",
    "name": "Kai Ibarra"
  }
]

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 Shipping and carriers 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 Shipping and carriers API fixture that covers 17 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 Shipping and carriers API the decisive one is "weight_grams" > 0 on shipments.weight_grams, 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 Shipping and carriers API fixture, yes: the reference engine accepted the 3-table DDL and every row satisfied its 17 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