Skip to content

A UI from an OpenAPI document

Status: 🧪 Experimental (Java generator: Maven goal and command line; the YAML it writes runs on every backend and renderer)

You have an API with an OpenAPI document and want screens over it. mateu-openapi reads the document and writes the screens as ordinary Mateu YAML under specs/ui — the same files you would write by hand or with the visual editor. Nothing new runs at runtime: the result is a YAML mount with its REST sources, served by any Mateu backend or shipped as a static bundle.

Terminal window
mvn io.mateu:mateu-bundle-maven-plugin:ui-from-openapi \
-Dopenapi.spec=https://swapi.mateu.io/v3/api-docs \
-Dopenapi.overrides=src/main/openapi/overrides.yaml

writes, for the Star Wars API:

specs/ui/
swapi.ui.yaml the mount (type: UI)
app.yaml the app shell: one menu entry per collection
routes.yaml every route below
sources.yaml one named source per operation (provenance: existing)
people.yaml the listing /people
people-record.yaml the record page /people/:id
people-edit.yaml the edit form /people/:id/edit
people-new.yaml the create form /people/new
films.yaml … the same for every collection

The reference app is demo/demo-openapi (port 8606): its YAML is generated from the live Star Wars API and committed; the only Java is the Spring Boot main.

Front doorCommand
Maven goalmvn io.mateu:mateu-bundle-maven-plugin:ui-from-openapi -Dopenapi.spec=<url or file> — or bind it to generate-resources in a profile (the demo’s -Pregenerate)
Command linejava -cp "mateu-openapi.jar:<jackson-databind + jackson-dataformat-yaml>" io.mateu.openapi.OpenApiUiCli <url or file> [--overrides overrides.yaml] [--out src/main/resources/specs/ui] [--force] [--dry-run] (Jackson is its only dependency)
PropertyDefault
openapi.spec—The document: an http(s) url or a file, JSON or YAML, OpenAPI 3.x.
openapi.overridesnoneThe overrides file.
openapi.outsrc/main/resources/specs/uiWhere the files go.
openapi.dryRunfalseReport what would be written, write nothing.
openapi.forcefalseAlso overwrite files that were not generated.

Regenerating is safe. Every generated file starts with the line # Generated by mateu-openapi from an OpenAPI document. Edit the overrides, not this file. A file without it — one you wrote, or a generated one you took over by removing the line — is never overwritten unless you pass force. The output is deterministic: the same document and overrides give byte-identical files, so a regeneration shows up in git diff only when something changed. Files that are no longer generated are not deleted.

Collections. Paths are grouped by collection: GET /people (a list) with GET /people/{id} (one) is a collection; POST /people, PUT|PATCH /people/{id} and DELETE /people/{id} add the create form, the edit form and delete. A path under an item (/owners/{ownerId}/pets) is a sub-collection: its own listing, linked from the owner’s record page. Any other operation under an item (POST /owners/{ownerId}/archive) is an action: a button on the record page, with a form when it takes a body. The common literal prefix (/api) is dropped from the routes.

OpenAPIMateu
GET /peopleListing at /people, rows from swapi-people-list
GET /people/{id}Read-only record page at /people/:id (rows open it)
POST /peopleNew person → form at /people/new
PUT / PATCH /people/{id}Edit → form at /people/:id/edit
DELETE /people/{id}Delete on the record; selection + Delete selected on the listing
/owners/{ownerId}/petsListing at /owners/:ownerId/pets, a button on the owner
POST /owners/{ownerId}/archiveArchive on the owner’s record page
GET /health (no collection)nothing (reported)

Fields. The schema’s properties become fields ($ref and allOf resolved, a nullable oneOf unwrapped): string → text (format: date / date-time / time / email / password → that field kind, enum → radio buttons up to four values, else a select), integer, number, boolean, a nested object → its fields flattened (address.street), a list of numbers → a JSON list. required, readOnly (shown on the record, never in a form), writeOnly (in the forms, never shown — a password), description (the field’s help) and the operation’s summary (the listing’s subtitle) are honoured.

The listing’s query. From the list operation’s query parameters:

ParameterRead as
page / size (pageNumber, per_page…)Mateu’s page (one-based when the parameter’s minimum or default is 1)
offset / limit (skip, take…)offset=${(state.page ?? 0) * (state.size ?? 20)}
search, q, query…the listing’s search box
sort, orderBy…sortable columns — name,desc (Spring), name:desc, -name or a separate direction parameter
any other scalara filter
cursor, after, pageToken…not supported: a warning, the listing shows the first page

The answer’s envelope is read from the list’s response schema: the rows at content, items, data, results… and the total at totalElements, total, count… — a bare array is all the rows.

By default every source is proxy: true: the browser asks the Mateu server, the server calls the API. That is what keeps the API’s credentials out of the browser and makes CORS a non-issue.

Credentials come from the document’s securitySchemes (an apiKey header, bearer, basic) or from the auth override, and are always a server secret: ${secret.SWAPI_WRITE_KEY} is read from a SecretsProvider bean or the environment variable MATEU_SECRET_SWAPI_WRITE_KEY — never sent to the browser. auth.methods limits it to some methods (the Star Wars API is open for reading and wants its key on the writes).

proxy: false in the overrides lets the browser call the API directly — but a call carrying a secret, or under step-up, stays on the server whatever the override says.

A refused write is shown the way the API meant it. A problem+json (or any JSON error) that names fields marks those fields on the form, with the API’s message under each, as if the form had checked them itself:

{ "title": "Bad Request", "status": 400,
"errors": [ { "field": "name", "message": "must not be blank" } ] }

The fields are read from errors, invalid-params (RFC 7807), invalidParams, fieldErrors, violations or a detail list (FastAPI), each entry naming its field as field, name, property, propertyPath, param, pointer (#/address/street → address.street), path or loc. Any other failure shows the API’s own message (detail, message, title…) as a toast, and an unreadable one a generic text. This is not specific to generated UIs: every REST source behaves this way, direct or proxied, on every renderer — the rule is pinned by the corpus conformance/client/service-errors.json.

What the document cannot say, or should say otherwise. Every key is optional; the file has a JSON Schema (META-INF/mateu/openapi-overrides-schema.json in the mateu-openapi jar, also on GitHub) for completion in your editor:

# yaml-language-server: $schema=https://raw.githubusercontent.com/miguelperezcolom/mateu/master/backend/shared/openapi/src/main/resources/META-INF/mateu/openapi-overrides-schema.json
api: swapi # file and source names
title: Star Wars (from OpenAPI) # the app shell's
auth:
type: apiKey
header: X-Api-Key
secret: SWAPI_WRITE_KEY # MATEU_SECRET_SWAPI_WRITE_KEY
methods: [POST, PUT, PATCH, DELETE]
menu: [people, films, planets] # first = home page; the rest follow in document order
stepUp:
swapi-people-delete: true # by source name or operationId
resources: # by route, API path or last segment
people:
subtitle: Everybody in the saga
icon: vaadin:users
columns: [name, height, mass]
readOnly: [homeworldName, url, image]
hidden: [created]
filters: [name]
paging: { pageSize: 50, itemsPath: content, totalPath: totalElements }
Key
api, title, subtitle, basePath, baseUrlthe mount’s name, the shell’s texts, where it is served, the API’s base url
proxyfalse = the browser calls the API (except secret / step-up calls)
authtype none | apiKey | bearer | basic, header, secret, methods
paging, sortthe parameters and the answer’s paths when they are not recognisable (paging.style: none = never page); the sort style comma | colon | minus | field
menuthe menu’s order
stepUpstep-up per operation (true or a policy)
resources.<r>exclude, label, singular, subtitle, icon, idField, titleField, columns, hidden, readOnly, filters, paging, sort
  • OpenAPI 3.x only (convert a Swagger 2.0 document first); references to another document are not followed.
  • Cursor paging is not supported; lists of texts in a body are left out (reported), as are bodies that are not JSON (file uploads, forms).
  • The generator writes; it does not merge. To change a generated screen beyond what the overrides offer, take the file over (remove its first line) — it is yours from then on.