---
title: "Comment by Raymond Kelly on \"How to Automatically Generate Request Models from TypeScript Interfaces\" | Hashnode"
description: "Have you considered instead of generating the OpenAPI documentation and JSONSchema from code that you instead start with the OpenAPI documentation and use that"
url: "https://hashnode.com/posts/how-to-automatically-generate-request-models-from-typescript-interfaces/5f9c625a65cd015fab581392/comment/63d1b73b2086bff3543caee5"
---

[Discussion](https://hashnode.com/posts/how-to-automatically-generate-request-models-from-typescript-interfaces/5f9c625a65cd015fab581392)

Comment [How to Automatically Generate Request Models from TypeScript Interfaces](https://hashnode.com/posts/how-to-automatically-generate-request-models-from-typescript-interfaces/5f9c625a65cd015fab581392)

[Raymond Kelly](https://hashnode.com/@rahmonk)

[Jan 25, 2023](https://hashnode.com/posts/how-to-automatically-generate-request-models-from-typescript-interfaces/5f9c625a65cd015fab581392/comment/63d1b73b2086bff3543caee5)

Have you considered instead of generating the OpenAPI documentation and JSONSchema from code that you instead start with the OpenAPI documentation and use that as the single source of truth. That way you could define an OpenAPI document that is used to generate types for both the client and server as well as can be easily converted to JSONSchema for API validation.

I found the following library that does somewhat of what I mentioned above [npmjs.com/package/@alma-cdk/openapix](https://www.npmjs.com/package/@alma-cdk/openapix) but they use SpecRestAPI construct under the hood. I'm going to try in my own project use the RestAPI construct and build the Models from the JSONSchema generated from the OpenAPI documentation.

Btw great articles I'm really liking them.

[Matt Martz](https://hashnode.com/@martzmakes)

[Feb 1, 2023](https://hashnode.com/posts/how-to-automatically-generate-request-models-from-typescript-interfaces/5f9c625a65cd015fab581392/comment/63d1b73b2086bff3543caee5#reply-63dafa71f5b65869f5efdecc)

Thanks! I prefer the code-first approach. I hate writing specs and would much rather the code generate them. I talk about this a little bit in the next article: [matt.martz.codes/openapi-specs-from-cdk-stack-wit…](https://matt.martz.codes/openapi-specs-from-cdk-stack-without-deploying-first)

But I have since moved more towards Event Driven Documentation: [matt.martz.codes/automate-documenting-api-gateway…](https://matt.martz.codes/automate-documenting-api-gateways-in-eventcatalog)

Both still rely on converting typescript interfaces to json schemas... but in the more recent post I shift to downloading the spec from the deployed version of the API Gateway. Thanks for the feedback though, that's totally a valid approach... just not my preferred one.
