I'm using swagger-typescript-api to generate interfaces from swagger schema
npx swagger-typescript-api generate -p PATH_TO_YOUR_SCHEMA -o ./
Answer from Sergey Volkov on Stack Overflow
» npm install swagger-typescript-api
Videos
I'm using swagger-typescript-api to generate interfaces from swagger schema
npx swagger-typescript-api generate -p PATH_TO_YOUR_SCHEMA -o ./
Not sure if that's a sane way to do this, it's the first time I'm playing around with Swagger.
I bumped into the following link and pasted the schema from the project I integrate with. From the top 'Generate Client' menu I chose one of the TypeScript presets and it generated a minimal project where I could extract the bits I needed, interface and classes, etc.
http://editor.swagger.io/#/
I tried running your schema. Here's a small excerpt of the generated code:
export interface Bar {
"a"?: string;
"b": number;
"c": Date;
"baz"?: Baz;
}
export interface Baz {
"d": number;
"color": Color;
}
/**
*
*/
export type Color = "0" | "1" | "2";
Maybe with a bit more tweaking it can make exactly what you're looking for.
Further reading may be about tools like https://github.com/swagger-api/swagger-codegen but the online web editor is a quick and dirty way to do this.
At work we have a pretty simple set up: Next.js frontend hosted on Vercel and a Java/Dropwizrd backend hosted on AWS. Our backend uses Swagger/Open API, and we generate our types based on the swagger.json.
Frankly, this sucks to manage across deployments and branches. Our backend is in a separate repository, so we frequently block preview deployments because our hosted staging or dev instance is either ahead or behind our frontend.
Our types are generated either via script locally or right before our build on vercel. We do not commit them, and we’d prefer to never commit them
We are considering a monorepo, which for other reasons as well, might be the most sane solution. I have considered hosting our types, creating packages in a private NPM repository, trying some kind of gRPC solution, but none of them really seem that straight forward, nor do they really “fix” our problem.
How have you or how have you seen synchronizing backend and frontend types? Any solution or architecture ideas for this would be very helpful!