Library Overview
react-openapi is a compiler that runs in the browser: it reads an
OpenAPI document, validates it, transforms it into an internal resource
model, and renders UI from that model. It never edits your spec, and it never
falls back silently when a required extension is missing.
🏗️ Architecture
| Layer | Module | Responsibility |
|---|---|---|
| Load | spec-loader.ts |
fetch JSON/YAML, resolve $ref |
| Validate | spec-validator.ts |
error / warning / info rules |
| Transform | transformers/* |
schema → ResourceConfig, properties → FieldConfig |
| State | context/AppProvider.tsx, AppContext |
shared resources, schemas, auth, axios client |
| HTTP | hooks/useApi.ts |
initApi, getApi with bearer injection |
| Present | components/* |
Admin, ResourceList/Detail/Form, renderers |
📦 Quick start
Admin renders SideMenu plus nested routes per resource:
/<basePath>/<resource> (list), /<resource>/new,
/<resource>/:id (detail), /<resource>/:id/edit. Streaming (x-sse)
resources render only the list.
🔄 How one resource reaches the screen
- The spec is fetched at mount;
specValidatorruns over it. - Every schema carrying
x-resourcebecomes aResourceConfig(name,schemaName,displayName,path,streaming, pagination). - Each property becomes a
FieldConfig—x-order,x-label,x-hidden,x-filterable,x-sortable,x-edit-as,x-ui-type. useResource(name)adds CRUD helpers (list,get,create,update,remove,stream?) for one resource.ListCellRenderer/DetailFieldRenderer/FormFieldRendererdispatch to the concrete control for thatFieldConfig.
⚠️ Design decisions
- Spec loaded at runtime, not compiled into the bundle.
- Schema-to-path mapping is explicit —
x-resourcemust equal the path segment. No pluralisation guessing. - No fallbacks for required extensions — missing
x-primary-key,x-display-format,x-list-columns,x-labelorx-orderfails at transform time rather than defaulting silently. - Strict response parsing — paginated lists are
{ total?, items[] }, non-paginated lists are a plain array. No fallback chains. - FK options use
?limit=0on paginated targets: a server convention meaning "return all", not documented in the spec.