Scenario · target: mock data generator for microservices testing

Seed Internal platform services API from OpenAPI: mock data generator Guide

Team tests several services that share contracts and needs each one to see consistent data.

Direct answer

SchemaSeed (a Node.js CLI) turns an OpenAPI 3.x document into a PostgreSQL seed script for Internal platform services 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: 4 Stack Overflow questions, @pact-foundation/pact at 3,925,794 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 — Internal platform

Running the generator over the Internal platform services 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 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 Internal platform services 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 service_dependencies 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 Internal platform services API, the range probe on deploys.ok uses the value 2, which the constraint "ok" IN (0,1) rejects. The engine produced "CHECK constraint failed: deploys_ok_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 Internal platform services 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 services, deploys, service_dependencies, and each of those tables appears exactly once per seed file.

When a different tool fits better

If the Internal platform services 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 Internal platform services 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 fieldservices.slug23502not_null_violationNOT NULL constraint failed: services.slug
Out-of-contract valuedeploys.ok23514check_violationCHECK constraint failed: deploys_ok_check
Dangling foreign keyservice_dependencies.service_id23503foreign_key_violationFOREIGN KEY constraint failed
Insert order for Internal platform services API, derived from its foreign keysThe generator sorts the tables by this order before writing a single row.
TableReferenced byWritten
servicesservice_dependencies, service_dependencies, deploysafter service_dependencies, service_dependencies, deploys
deploys—first, no dependencies
service_dependencies—first, no dependencies
deploys.json

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

Download platform.openapi.yaml

[
  {
    "id": "964d57ff-60cb-4fb1-b157-a2af24f66e15",
    "service_id": {
      "id": "dceaf740-029f-481c-beb9-e96590b78a20",
      "slug": "summit grove",
      "owner_team": "kelp juniper",
      "tier": "tier1"
    },
    "version": "Bogota, Riverside Lane 118",
    "deployed_at": "2020-06-11T10:45:05.000Z",
    "ok": 0
  },
  {
    "id": "848ad6ea-cc67-4946-8704-c5eca6ba4710",
    "service_id": {
      "id": "2803863f-51bb-420b-95b8-2166af7ee093",
      "slug": "fable onyx",
      "owner_team": "bao.duarte@example.net",
      "tier": "tier1"
    },
    "version": "alpha delta",
    "deployed_at": "2020-09-19T16:35:25.000Z",
    "ok": 0
  },
  {
    "id": "6ae00124-89a8-4351-bdfc-0c617dd33da9",
    "service_id": {
      "id": "4b148739-62e6-4421-afbb-0c568f9e613b",
      "slug": "milo.fontaine@mail.example",
      "owner_team": "summit ember",
      "tier": "tier3"
    },
    "version": "lumen-nimbus-300",
    "deployed_at": "2020-03-26T04:21:53.000Z",
    "ok": 0
  },
  {
    "id": "d02b57cd-b2ea-40fd-b2f1-a12a65edc5a2",
    "service_id": {
      "id": "cd644cf2-3d5d-4593-b224-37566a164530",
      "slug": "grove lumen",
      "owner_team": "Berlin, Maple Street 48",
      "tier": "tier3"
    },
    "version": "onyx meadow",
    "deployed_at": "2025-10-19T22:19:05.000Z",
    "ok": 0
  },
  {
    "id": "52ad0aa2-d583-4edf-97ff-22f91cf30470",
    "service_id": {
      "id": "d24dde9a-e35d-4441-91fc-97ada023da30",
      "slug": "milo.lund@example.net",
      "owner_team": "Osaka, Riverside Lane 189",
      "tier": "tier3"
    },
    "version": "zephyr-pebble-867",
    "deployed_at": "2023-02-03T18:55:00.000Z",
    "ok": 0
  },
  {
    "id": "d8ab23e0-60ec-40f6-a519-51ca8272ebf7",
    "service_id": {
      "id": "fc1a53c5-8dd9-41da-ad63-c9288e1f3b2c",
      "slug": "dara.moreau@example.com",
      "owner_team": "tundra kelp",
      "tier": "tier2"
    },
    "version": "Rosa Okafor",
    "deployed_at": "2026-06-15T09:14:48.000Z",
    "ok": 0
  },
  {
    "id": "28b77bed-53df-481d-9b60-34e721dc88a1",
    "service_id": {
      "id": "0d7048d2-34b4-4180-a2ee-d25652ac9195",
      "slug": "quartz tundra",
      "owner_team": "Iris Moreau",
      "tier": "tier3"
    },
    "version": "nimbus quartz",
    "deployed_at": "2026-11-21T11:14:46.000Z",
    "ok": 0
  },
  {
    "id": "3242fcb6-f709-41cd-b0bf-f589b639debb",
    "service_id": {
      "id": "78a32013-36d0-4652-8bf2-986b110de0b5",
      "slug": "bravo pebble",
      "owner_team": "zephyr vertex",
      "tier": "tier2"
    },
    "version": "juniper harbor",
    "deployed_at": "2021-03-14T18:28:29.000Z",
    "ok": 0
  },
  {
    "id": "347a80e4-99aa-48d7-ba29-4bad06dbdd90",
    "service_id": {
      "id": "50ca962a-a1f0-48a3-891c-b61abc0f82ff",
      "slug": "nia.kaur@mail.example",
      "owner_team": "harbor vertex",
      "tier": "tier3"
    },
    "version": "zephyr indigo",
    "deployed_at": "2020-04-19T02:07:21.000Z",
    "ok": 0
  },
  {
    "id": "20ec7861-0cf9-4b26-bf5e-bab92025b8d0",
    "service_id": {
      "id": "0319d40c-d4b6-4877-acb2-1fcaf20ac4fd",
      "slug": "harbor pebble",
      "owner_team": "Bogota, Maple Street 137",
      "tier": "tier2"
    },
    "version": "nimbus juniper",
    "deployed_at": "2026-05-13T17:56:33.000Z",
    "ok": 0
  }
]

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 Internal platform services 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 Internal platform services 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 Internal platform services API the decisive one is "ok" IN (0,1) on deploys.ok, 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 Internal platform services 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