Scenario · target: create realistic dummy data for api development
Seed Blog and comments API from OpenAPI: create realistic dummy Guide
Frontend dev needs data that looks real so screens can be built without a backend.
Direct answer
SchemaSeed (a Node.js CLI) turns an OpenAPI 3.x document into a PostgreSQL seed script for Blog and comments 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, @faker-js/faker at 95,721,308 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 — Blog and
Running the generator over the Blog and comments 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 15, which is the number of primary key, foreign key and NOT NULL 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 Blog and comments 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 posts is never written before the row it points at.
Boundary cases that come with the seed
The Blog and comments API fixture has no numeric range declaration, so the boundary cases it produces are enum and nullability cases instead of range probes.
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 Blog and comments 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 authors, posts, comments, and each of those tables appears exactly once per seed file.
When a different tool fits better
If the Blog and comments 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 | authors.handle | 23502 | not_null_violation | NOT NULL constraint failed: authors.handle |
| Dangling foreign key | posts.author_id | 23503 | foreign_key_violation | FOREIGN KEY constraint failed |
| Table | Referenced by | Written |
|---|---|---|
| authors | posts, comments | after posts, comments |
| posts | comments | after comments |
| comments | — | first, no dependencies |
npx --yes @wenlu8848/schemaseed generate --input ./blog.openapi.yaml --out ./seed --formats sql --count 10 --seed 42
-- Generated by schemaseed.
-- seed: 42
-- rows per table: 10
-- Foreign key values are taken from the rows of the referenced table.
BEGIN;
CREATE TABLE IF NOT EXISTS "authors" (
"id" UUID,
"handle" TEXT NOT NULL,
"display_name" TEXT NOT NULL,
CONSTRAINT "authors_pkey" PRIMARY KEY ("id")
);
CREATE TABLE IF NOT EXISTS "posts" (
"id" UUID,
"author_id" UUID NOT NULL,
"slug" TEXT NOT NULL,
"title" TEXT NOT NULL,
"body" TEXT NOT NULL,
"published_at" TIMESTAMPTZ,
CONSTRAINT "posts_pkey" PRIMARY KEY ("id")
);
CREATE TABLE IF NOT EXISTS "comments" (
"id" UUID,
"post_id" UUID NOT NULL,
"author_id" UUID,
"body" TEXT NOT NULL,
"created_at" TIMESTAMPTZ NOT NULL,
CONSTRAINT "comments_pkey" PRIMARY KEY ("id")
);
DO $schema_seed$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'posts_author_id_fkey') THEN
ALTER TABLE "posts" ADD CONSTRAINT "posts_author_id_fkey" FOREIGN KEY ("author_id") REFERENCES "authors" ("id");
END IF;
END
$schema_seed$;
DO $schema_seed$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'comments_post_id_fkey') THEN
ALTER TABLE "comments" ADD CONSTRAINT "comments_post_id_fkey" FOREIGN KEY ("post_id") REFERENCES "posts" ("id");
END IF;
END
$schema_seed$;
DO $schema_seed$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'comments_author_id_fkey') THEN
ALTER TABLE "comments" ADD CONSTRAINT "comments_author_id_fkey" FOREIGN KEY ("author_id") REFERENCES "authors" ("id");
END IF;
END
$schema_seed$;
INSERT INTO "authors" ("id", "handle", "display_name")
VALUES ('a22d5a6f-e223-4454-bd90-ad3a04e8fdc8', 'Pia Petrov', 'quartz bravo')
ON CONFLICT DO NOTHING;
INSERT INTO "authors" ("id", "handle", "display_name")
VALUES ('c38499c5-36d8-4ac9-bb7c-f4a17d924816', 'grove vertex', 'bravo kelp')
ON CONFLICT DO NOTHING;
INSERT INTO "authors" ("id", "handle", "display_name")
VALUES ('257084e8-438d-48cc-b1f3-3ffc16cdd5de', 'Tara Petrov', 'umbra-river-39')
ON CONFLICT DO NOTHING;
INSERT INTO "authors" ("id", "handle", "display_name")
VALUES ('a7c0a435-71c5-4d8a-85d2-fe03e65ca60a', 'jun.engel@example.org', 'quartz-quartz-377')
ON CONFLICT DO NOTHING;
INSERT INTO "authors" ("id", "handle", "display_name")
VALUES ('f88e8610-495e-47ef-87a6-b92a61d3e3db', 'ember-kelp-41', 'Jun Okafor')
ON CONFLICT DO NOTHING;
INSERT INTO "authors" ("id", "handle", "display_name")
VALUES ('83137192-eada-49fa-8f51-5d6ff41ba3e1', 'Toronto, Riverside Lane 101', 'bravo-zephyr-429')
ON CONFLICT DO NOTHING;
INSERT INTO "authors" ("id", "handle", "display_name")
VALUES ('f44d60f9-f520-442b-9d5c-69379aeb1f1c', 'lumen quartz', 'fable-onyx-671')
ON CONFLICT DO NOTHING;
INSERT INTO "authors" ("id", "handle", "display_name")
VALUES ('5c2dc552-6947-476b-9e7a-9d2020c461ab', 'fay.engel@test.dev', 'pebble vertex')
ON CONFLICT DO NOTHING;
INSERT INTO "authors" ("id", "handle", "display_name")
VALUES ('d6ea6085-6cca-462e-acf0-647b6086739d', 'Lisbon, Oak Drive 85', 'Toronto, Riverside Lane 236')
ON CONFLICT DO NOTHING;
INSERT INTO "authors" ("id", "handle", "display_name")
VALUES ('0a8526b7-124c-4847-82b8-37c63ad865b3', 'juniper alpha', 'Toronto, Maple Street 113')
ON CONFLICT DO NOTHING;
INSERT INTO "posts" ("id", "author_id", "slug", "title", "body", "published_at")
VALUES ('c50708db-a253-4207-878b-f1ef7310856f', 'f44d60f9-f520-442b-9d5c-69379aeb1f1c', 'quinn.jansen@example.com', 'umbra-harbor-649', 'umbra nimbus', '2020-09-26T05:58:25.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "posts" ("id", "author_id", "slug", "title", "body", "published_at")
VALUES ('0b32a8f9-cf78-4598-aa41-926ca078a359', '5c2dc552-6947-476b-9e7a-9d2020c461ab', 'nimbus grove', 'Nia Okafor', 'delta-tundra-492', '2024-05-24T19:36:31.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "posts" ("id", "author_id", "slug", "title", "body")
VALUES ('a14ccfa3-a266-4873-82bc-c7953acc234a', 'a22d5a6f-e223-4454-bd90-ad3a04e8fdc8', 'river-vertex-757', 'Lisbon, Harbor Road 250', 'fable-delta-220')
ON CONFLICT DO NOTHING;
INSERT INTO "posts" ("id", "author_id", "slug", "title", "body", "published_at")
VALUES ('e640581f-870c-4a3b-b0a2-639eccd43858', 'f44d60f9-f520-442b-9d5c-69379aeb1f1c', 'delta nimbus', 'Bao Novak', 'nimbus pebble', NULL)
ON CONFLICT DO NOTHING;
INSERT INTO "posts" ("id", "author_id", "slug", "title", "body", "published_at")
VALUES ('3cf67de3-01de-43bb-9ffa-0737f5774846', 'f44d60f9-f520-442b-9d5c-69379aeb1f1c', 'umbra-ember-164', 'Osaka, Oak Drive 37', 'pia.duarte@test.dev', '2025-05-20T02:05:28.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "posts" ("id", "author_id", "slug", "title", "body")
VALUES ('2fba8eb0-fbaa-47d5-940c-8a69909378ee', 'a7c0a435-71c5-4d8a-85d2-fe03e65ca60a', 'Nairobi, Oak Drive 148', 'grove summit', 'pebble nimbus')
ON CONFLICT DO NOTHING;
INSERT INTO "posts" ("id", "author_id", "slug", "title", "body", "published_at")
VALUES ('0392432a-b8eb-4364-9367-b58d1dfa4b79', '83137192-eada-49fa-8f51-5d6ff41ba3e1', 'Jun Fontaine', 'dara.adler@example.org', 'pebble quartz', '2026-04-04T22:13:53.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "posts" ("id", "author_id", "slug", "title", "body", "published_at")
VALUES ('0390c325-52a6-4c9f-8a77-31d1b89f9926', 'c38499c5-36d8-4ac9-bb7c-f4a17d924816', 'Osaka, Elm Avenue 102', 'pebble zephyr', 'vertex-umbra-399', '2020-12-27T17:44:26.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "posts" ("id", "author_id", "slug", "title", "body", "published_at")
VALUES ('9db2df76-b9c0-41e9-8dc2-9a5f26354566', '5c2dc552-6947-476b-9e7a-9d2020c461ab', 'kelp-indigo-400', 'kai.adler@example.org', 'vertex lumen', '2022-03-12T09:05:23.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "posts" ("id", "author_id", "slug", "title", "body", "published_at")
VALUES ('50a9e5cb-a6cf-4611-8b28-9c0bcc1bd4dd', 'f88e8610-495e-47ef-87a6-b92a61d3e3db', 'nimbus ember', 'fable meadow', 'willow quartz', '2022-11-18T07:40:27.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "comments" ("id", "post_id", "author_id", "body", "created_at")
VALUES ('9f7627a8-8e2a-4d9b-8ff3-38430930c2df', '0392432a-b8eb-4364-9367-b58d1dfa4b79', 'f88e8610-495e-47ef-87a6-b92a61d3e3db', 'Tara Novak', '2022-02-19T03:42:27.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "comments" ("id", "post_id", "author_id", "body", "created_at")
VALUES ('3b806e71-acdb-43b1-a923-1a128c54da18', '9db2df76-b9c0-41e9-8dc2-9a5f26354566', 'a7c0a435-71c5-4d8a-85d2-fe03e65ca60a', 'tara.okafor@mail.example', '2021-03-19T23:03:23.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "comments" ("id", "post_id", "author_id", "body", "created_at")
VALUES ('cedee2d6-22d0-4478-b791-d5def1a3a880', '2fba8eb0-fbaa-47d5-940c-8a69909378ee', '5c2dc552-6947-476b-9e7a-9d2020c461ab', 'river willow', '2020-02-27T23:17:27.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "comments" ("id", "post_id", "author_id", "body", "created_at")
VALUES ('6107adfe-02e0-49ae-80d7-4edbe5a62167', 'c50708db-a253-4207-878b-f1ef7310856f', 'f44d60f9-f520-442b-9d5c-69379aeb1f1c', 'indigo-juniper-120', '2024-05-28T21:18:24.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "comments" ("id", "post_id", "author_id", "body", "created_at")
VALUES ('9ef53efd-bc4d-4f17-8286-1c8de12fbfb1', 'c50708db-a253-4207-878b-f1ef7310856f', 'd6ea6085-6cca-462e-acf0-647b6086739d', 'umbra-umbra-609', '2021-12-13T23:16:41.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "comments" ("id", "post_id", "author_id", "body", "created_at")
VALUES ('cb822fcd-3678-467b-8618-16ddfa18a1da', '0390c325-52a6-4c9f-8a77-31d1b89f9926', 'c38499c5-36d8-4ac9-bb7c-f4a17d924816', 'Jun Lund', '2020-11-21T06:49:28.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "comments" ("id", "post_id", "author_id", "body", "created_at")
VALUES ('8abca45e-df74-4dc6-a87a-6d518c2b8f13', '50a9e5cb-a6cf-4611-8b28-9c0bcc1bd4dd', 'f44d60f9-f520-442b-9d5c-69379aeb1f1c', 'Jun Petrov', '2025-01-19T05:28:47.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "comments" ("id", "post_id", "author_id", "body", "created_at")
VALUES ('254b70e4-70d7-4040-a461-05158f055556', 'c50708db-a253-4207-878b-f1ef7310856f', '257084e8-438d-48cc-b1f3-3ffc16cdd5de', 'pebble meadow', '2022-11-23T13:28:31.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "comments" ("id", "post_id", "author_id", "body", "created_at")
VALUES ('b11b5de3-6fb7-4aba-ad35-1f383e80f36a', 'c50708db-a253-4207-878b-f1ef7310856f', '5c2dc552-6947-476b-9e7a-9d2020c461ab', 'Iris Holt', '2024-08-08T01:10:21.000Z')
ON CONFLICT DO NOTHING;
INSERT INTO "comments" ("id", "post_id", "author_id", "body", "created_at")
VALUES ('0c0f9372-2c52-43be-9da2-8a4bf864a1f7', '0392432a-b8eb-4364-9367-b58d1dfa4b79', '5c2dc552-6947-476b-9e7a-9d2020c461ab', 'dara.duarte@mail.example', '2020-03-07T09:35:28.000Z')
ON CONFLICT DO NOTHING;
COMMIT;
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 Blog and comments 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 Blog and comments API fixture that covers 15 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 Blog and comments API the decisive one is the enum membership clause on authors.handle, and the value that breaks it ships as a negative case.
- Is the output valid on a fresh database?
- On the Blog and comments API fixture, yes: the reference engine accepted the 3-table DDL and every row satisfied its 15 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