Strapi integration with other typescript aplications in a monorepo

If you simply want to generate types for your API definitions for consumption in external projects, you can utilise the OpenAPI spec to do so. There’s many OpenAPI code generators available but I personally use the “typescript-fetch” template to generate both a HTTP REST client and the model definitions in TypeScript.

You can see in the screenshot below I’m consuming an endpoint for a single type called “Document”. You can see the auto-generate client and the model (Document):

This works great, but there’s a caveat. The documentation plugin doesn’t generate an OpenAPI spec that matches the API response types! (See Why is the documentation extension (OpenAPI) generating the wrong data type?) Luckily Strapi is very configurable and you can override API definitions to match the response types.

1 Like