Scenario · target: deterministic fake data for api tests

Seed Product telemetry API from OpenAPI: deterministic fake data Guide

Test suite is flaky because data changes between runs and snapshots break randomly.

Direct answer

SchemaSeed (a Node.js CLI) turns an OpenAPI 3.x document into a PostgreSQL seed script for Product telemetry 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: 0 Stack Overflow questions, 3 Hacker News stories, drizzle-seed at 2,503,190 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 — Product telemetry

Running the generator over the Product telemetry API fixture produces 3 tables and 11 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 14, 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 Product telemetry 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 sessions 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 Product telemetry API, the range probe on sessions.platform uses the value not_a_real_member, which the constraint platform IN ('web','ios','android') rejects. The engine produced "CHECK constraint failed: sessions_platform_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 Product telemetry 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, sessions, events, and each of those tables appears exactly once per seed file.

When a different tool fits better

If the Product telemetry 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 Product telemetry 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 fieldaccounts.email23502not_null_violationNOT NULL constraint failed: accounts.email
Out-of-contract valuesessions.platform23514check_violationCHECK constraint failed: sessions_platform_check
Dangling foreign keysessions.account_id23503foreign_key_violationFOREIGN KEY constraint failed
Insert order for Product telemetry API, derived from its foreign keysThe generator sorts the tables by this order before writing a single row.
TableReferenced byWritten
accountssessionsafter sessions
sessionseventsafter events
events—first, no dependencies
README.md

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

Download telemetry.openapi.yaml

# Generated pytest suite

Seed: 42 — mode: nested

Run it with:

```
pytest pytest/
```

The suite is self contained: `_validator.py` implements the JSON Schema
keywords the generated data uses, so only pytest is needed.

- `test_accounts.py`: 10 valid rows, 8 negative cases (format-violation, missing-required, null-violation, type-mismatch)
- `test_sessions.py`: 10 valid rows, 23 negative cases (enum-violation, format-violation, missing-required, null-violation, type-mismatch)
- `test_events.py`: 10 valid rows, 24 negative cases (enum-violation, format-violation, missing-required, null-violation, type-mismatch)

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 Product telemetry 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 Product telemetry API fixture that covers 14 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 Product telemetry API the decisive one is platform IN ('web','ios','android') on sessions.platform, 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 Product telemetry API fixture, yes: the reference engine accepted the 3-table DDL and every row satisfied its 14 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