This repository contains a generator to create an OpenAPI document compliant to the API Design Rules.
URL: https://developer-overheid-nl.github.io/oas-generator/
The generator can also be used from the command line. It reads an input document
(see src/specs/gen/example.json for the syntax),
validates it against the input schema (src/specs/gen/schema.json)
and writes the generated OpenAPI document.
# From a file to a file
pnpm generate input.json -o openapi.json
# From a file to stdout (use -s/--silent to keep pnpm's banner out of the output)
pnpm -s generate input.json
# From stdin to a file
cat input.json | pnpm -s generate > openapi.jsonThe input is read from the given file, or from stdin when no file is provided.
The result is written to stdout, or to the file given with -o/--output.
Use -s/--silent (or the -o option) when redirecting stdout, so the run banner
does not end up in the generated document.
The CLI exits with code 1 when the input is invalid and 2 on usage or I/O errors.
The CLI can be run straight from GitHub, without publishing to npm. npx clones
the repository, builds the CLI bundle (via the prepare script) and runs it:
# From a file to a file
npx github:developer-overheid-nl/oas-generator input.json -o openapi.json
# From stdin to stdout
cat input.json | npx github:developer-overheid-nl/oas-generatorPin a branch or tag with a # suffix (e.g. github:developer-overheid-nl/oas-generator#main).
npx caches the install, so use the #-suffix or clear the cache to pick up changes.
| Field | Required | Description |
|---|---|---|
oasVersion |
no | OpenAPI version to generate for: "3.1" (default) or "3.0". |
title |
yes | Title of the API. |
description |
yes | Description of the API. |
contact |
yes | name, email and url of the contact. |
resources |
yes | Array of resources (at least one). |
The input is validated strictly: unknown keys at the root, in contact or in a
resource are rejected. Only an inline schema may contain any keywords, since it
is a JSON schema itself.
Each resource has a name and plural, an optional readonly boolean, and an
optional schema. A schema is not allowed when oasVersion is "3.0" and
can be either an inline JSON schema (object) or a URL string pointing to an
external JSON schema. An inline schema is added under components/schemas and
referenced locally; an external schema (URL) is referenced directly with a
$ref from the operations (no local component). When omitted, a default schema
with an id property is generated under components/schemas.
A resource can also have optional filters, an array of strings. Each filter
becomes an optional query parameter (type string) on the collection endpoint
(GET /{plural}), named in lowerCamelCase (created_at becomes createdAt),
with a default description. Filters must be unique, but are not checked against
the resource schema.
Collection endpoints (GET /{plural}) return an object with the resources
wrapped in an items array ({ "items": [...] }) instead of a bare array, so
the response can be extended later (for example with paging metadata) without a
breaking change. The wrapper is a named schema, {Name}Collection under
components/schemas.
This project uses pnpm. Prepare your local environment:
- Install project dependencies:
pnpm install - Install VSCode extensions: Prettier, ESLint, Tailwind CSS IntelliSense
- Set VSCode default formatter to
esbenp.prettier-vscode
Start the development server:
pnpm devVersioning, the changelog, and releases are driven by Changesets. The package is not published to npm; a release creates a GitHub release and deploys the web UI to GitHub Pages.
-
Add a changeset with your change. Run
pnpm changeset, pick the bump (major/minor/patch), and write a one-line summary. This creates a.changeset/<name>.mdfile; commit it with your PR. Omit only for changes that don't affect the generator or the web UI (CI, internal docs, tests). -
Merge the version pull request. Every push to
mainruns the Release workflow (.github/workflows/release.yml). While changesets are pending, it opens or updates achore(release): version packagespull request that runspnpm version-packages: it consumes the pending.changeset/*.mdfiles, bumpspackage.json, and prepends the summaries toCHANGELOG.md. Merge it when you want to release. Don't hand-edit theversionfield; Changesets owns it.GitHub doesn't run the Build workflow on pull requests opened by the workflow token, so the version pull request shows no checks. The release job builds, lints, and tests anyway; close and reopen the pull request if you want the checks on it.
-
Release. When the version pull request lands on
main, the workflow finds apackage.jsonversion that has nov<version>tag yet. It builds, lints, and tests, creates thev<version>tag with a GitHub release whose notes are that version'sCHANGELOG.mdsection, and deploys the web UI to GitHub Pages. Starting the workflow by hand (Actions → Release → Run workflow onmain) does the same as a push. To retry a failed release, use Re-run failed jobs.
The build output (docs) is not committed; GitHub Pages must be set to deploy from GitHub Actions.