Scenario · target: fake data for api testing
Seed CRM customers API from OpenAPI: fake data for Guide
QA engineer needs realistic-looking payloads without a manual fixture maintenance job.
Direct answer
SchemaSeed (a Node.js CLI) turns an OpenAPI 3.x document into a PostgreSQL seed script for CRM customers 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: 30 Stack Overflow questions, 31 Hacker News stories, fake-indexeddb at 45,141,518 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 — CRM customers
Running the generator over the CRM customers API fixture produces 3 tables and 14 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 19, 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 CRM customers 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 contacts 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 CRM customers API, the range probe on contacts.marketing_opt_in uses the value 2, which the constraint "marketing_opt_in" IN (0,1) rejects. The engine produced "CHECK constraint failed: marketing_opt_in IN (0,1)" 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 CRM customers 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 accounts, contacts, addresses, and each of those tables appears exactly once per seed file.
When a different tool fits better
If the CRM customers 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.
| Failure class | Column | SQLSTATE | Error name | Engine message (verbatim) |
|---|---|---|---|---|
| Missing required field | accounts.name | 23502 | not_null_violation | NOT NULL constraint failed: accounts.name |
| Out-of-contract value | contacts.marketing_opt_in | 23514 | check_violation | CHECK constraint failed: marketing_opt_in IN (0,1) |
| Dangling foreign key | contacts.account_id | 23503 | foreign_key_violation | FOREIGN KEY constraint failed |
| Table | Referenced by | Written |
|---|---|---|
| accounts | contacts | after contacts |
| contacts | addresses | after addresses |
| addresses | — | first, no dependencies |
npx --yes @wenlu8848/schemaseed generate --input ./crm_customers.openapi.yaml --out ./seed --formats ts --count 10 --seed 42
Download crm_customers.openapi.yaml
// Generated by schemaseed.
export * from './accounts.js';
export * from './contacts.js';
export * from './addresses.js';
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 CRM customers 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 CRM customers API fixture that covers 19 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 CRM customers API the decisive one is "marketing_opt_in" IN (0,1) on contacts.marketing_opt_in, 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 CRM customers API fixture, yes: the reference engine accepted the 3-table DDL and every row satisfied its 19 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