---
title: "Discussion on \"How to Automatically Generate Request Models from TypeScript Interfaces\" | Hashnode"
description: "Discussion on \"How to Automatically Generate Request Models from TypeScript Interfaces\". I ♥️ AWS CDK (big CDK fan-boi) and have several projects at work that make use of CDK with AWS's APIGateway.  But there isn't an easy way to do API Request Validation without manually defining everything... until now?\n\nBut... Why do request validatio..."
url: "https://hashnode.com/posts/how-to-automatically-generate-request-models-from-typescript-interfaces/5f9c625a65cd015fab581392"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to Automatically Generate Request Models from TypeScript Interfaces](https://martzmakes.com/how-to-automatically-generate-request-models-from-typescript-interfaces?utm_source=hashnode&utm_medium=feed)

I ♥️ AWS CDK (big CDK fan-boi) and have several projects at work that make use of CDK with AWS's APIGateway. But there isn't an easy way to do API Request Validation without manually defining everything... until now? But... Why do request validatio...

Oct 30, 2020 · 7 min read · martzmakes.com  
Read the article

-   [#aws](https://hashnode.com/tag/aws)
-   [#aws-cdk](https://hashnode.com/tag/aws-cdk)
-   [#typescript](https://hashnode.com/tag/typescript)
-   [#2articles1week](https://hashnode.com/tag/2articles1week)

## Written by

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

@martzmakes · Burke, VA

  
[View profile](https://hashnode.com/@martzmakes)

AWS Community Builder

I'm an AWS Community Builder and a Principal Software Architect I love all things CDK, Event Driven Architecture and Serverless

## Responses 3

Markdown supported · ⌘↵ to post

[Bar Miliavsky](https://hashnode.com/@barmil)

[Mar 21, 2023](https://hashnode.com/posts/how-to-automatically-generate-request-models-from-typescript-interfaces/5f9c625a65cd015fab581392/comment/641a0090e592dd06478de2ca)

I know it's been years but I just stumbled upon this article. I was looking into doing something like that for my project and this post and comments are a great resource for me! thank you!

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

[Mar 21, 2023](https://hashnode.com/posts/how-to-automatically-generate-request-models-from-typescript-interfaces/5f9c625a65cd015fab581392/comment/641a0090e592dd06478de2ca#reply-641a15097b483d01e1b3f3f7)

Thanks!

[Oleg Barenboim](https://hashnode.com/@chessbyte)

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

What an amazing article! I integrated the ideas here into our project and stopped the divergence between Typescript interfaces and a home-grown api-models.json file that contained the model definitions!

[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.
