Generate TypeScript types from your models
Morphic describes your models in an OpenAPI 3.1 document. You can copy ready-made TypeScript types from the admin app, or give the document to a generator to build a client.
Before you start
- You need at least one model. The types and the document describe the models that exist on your site.
- To run the generator command, you need Node.js and npm on your computer.
Copy or download the TypeScript types
- Select API & integration.
- Select TypeScript.
- Select Copy types, or select Download morphic.d.ts.
Result: The TypeScript tab shows the types generated from your models, in a code block. Paste them into your frontend project.
Generate a client from the OpenAPI document
The OpenAPI document is at /wp-json/morphic/v1/openapi on your site.
- On the TypeScript tab, copy the command in the openapi-typescript code block. The command contains your site's OpenAPI address.
- In your project folder, run the command.
npx openapi-typescript "https://example.com/wp-json/morphic/v1/openapi" -o morphic-api.d.ts
Result: The file morphic-api.d.ts contains types for your models. Any other OpenAPI generator works with the same address.