Swagger Codegen does not offer Nestjs generator at the moment. Here is a related request but no one seems to have found the time to make the contribution yet: https://github.com/swagger-api/swagger-codegen/issues/9559

UPDATE: there's PR to add a Nestjs generator in OpenAPI Generator (a community fork of Swagger Codegen)

Answer from NickSim on Stack Overflow
🌐
npm
npmjs.com › package › @newko › swagger-nestjs-codegen
@newko/swagger-nestjs-codegen - npm
Swagger Codegen Nest.js Framwork. Latest version: 1.6.8, last published: 2 years ago. Start using @newko/swagger-nestjs-codegen in your project by running `npm i @newko/swagger-nestjs-codegen`. There are no other projects in the npm registry using @newko/swagger-nestjs-codegen.
      » npm install @newko/swagger-nestjs-codegen
    
Published   Sep 16, 2023
Version   1.6.8
Author   Ryan
Discussions

[Nestjs] Typescript Nestjs New Language Generator
Description We use nestjs as our backend and frontend node applications. Currently there is support for angular 2-6 but not nestjs. I proposed adding nestjs. Swagger-codegen version N/A Swagger dec... More on github.com
🌐 github.com
11
July 10, 2019
[NEST JS - TYPESCRIPT] nullable field not generated
Hey Swagger code gen team 🥷 📔 Description I'm currently working on a monorepo nest js / angular app. We use nx lib to create a reusable lib to provide frontend model according to backend type d... More on github.com
🌐 github.com
0
June 5, 2023
NestJS codegen from Swagger API definition - Stack Overflow
Does anybody know of a way to automatically generate NestJS typescript code from Swagger? More on stackoverflow.com
🌐 stackoverflow.com
How to enable Swagger for API interfaces shared between NestJS and Angular within Nx monorepo? - Stack Overflow
This might be a complete workaround (aka not a solution) is if you enable Swagger on the NestJS side then you might want to, instead of sharing the interfaces, use a 3rd party tool to generate the API stubs for the Angular side using tools like: nswag, swagger-codegen, ng-openapi-gen etc... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › nestjs › swagger › issues › 146
Swagger-codegen template · Issue #146 · nestjs/swagger
September 28, 2018 - It would be useful to have a swagger-codegen template for nestjs.
Author   nestjs
🌐
GitHub
github.com › swagger-api › swagger-codegen › issues › 9559
[Nestjs] Typescript Nestjs New Language Generator · Issue #9559 · swagger-api/swagger-codegen
July 10, 2019 - Description We use nestjs as our backend and frontend node applications. Currently there is support for angular 2-6 but not nestjs. I proposed adding nestjs. Swagger-codegen version N/A Swagger declaration file content or url Command lin...
Author   swagger-api
🌐
Socket
socket.dev › npm › package › @newko › swagger-nestjs-codegen
@newko/swagger-nestjs-codegen - npm Package Security Analysi...
March 16, 2023 - # npm $ npm install -g @newko/swagger-nestjs-codegen # yarn $ yarn global add @newko/swagger-nestjs-codegen
🌐
GitHub
github.com › Ryan-Sin › swagger-nestjs-codegen
GitHub - Ryan-Sin/swagger-nestjs-codegen: Swagger Nest.js Code Generator 오픈소스
# npm $ npm install -g @newko/swagger-nestjs-codegen # yarn $ yarn global add @newko/swagger-nestjs-codegen
Starred by 21 users
Forked by 4 users
Languages   JavaScript 82.1% | TypeScript 17.6% | JavaScript 82.1% | TypeScript 17.6%
🌐
GitHub
github.com › swagger-api › swagger-codegen › issues › 12173
[NEST JS - TYPESCRIPT] nullable field not generated · Issue #12173 · swagger-api/swagger-codegen
June 5, 2023 - // swagger code gen brew package version swagger-codegen: stable 3.0.44 (bottled) // swagger nest js package `@nestjs/swagger": "^6.3.0` swagger-codegen generate -i http://localhost:3000/swagger-json -l typescript-angular -o myGeneratedFilesFolder/ Create a typescript class with nullable fields ·
Author   swagger-api
Find elsewhere
🌐
Medium
faraz-faraji.medium.com › generate-sdk-from-endpoints-to-connect-the-frontend-to-the-backend-in-the-standard-way-and-share-922b549cc5bd
Generate SDK from endpoints to connect the Frontend to the Backend in the Standard way and share types and DTOs in Typescript ( NestJS and ReactJS ) | by Faraz Faraji | Medium
November 29, 2022 - swagger-codegen generate -i http://localhost:3000/api-json -l typescript-axios -o client-sdk · -i is a variable given the JSON source? -l is responsible for the export language and its library -o represents the output folder · After generating the SDK, you should able to see the client-SDK folder. 🤓 · Imagine that, our controller should respond the data in a pagination format: import { ApiProperty } from '@nestjs/swagger'; export class PaginationDto<T> { data: T[]; @ApiProperty({ type: String }) token?: string; @ApiProperty({ type: Boolean }) more: boolean; }
🌐
notiz
notiz.dev › blog › angular-nest-openapi-codegen
Codegen REST API types and requests for Angular - notiz.dev
October 17, 2022 - In your case the Swagger JSON is available at localhost:3333/api-json. You should see openapi as first value with version 3.0.0. output is the directory for the generated files. The files are generated inside your Angular app. Change the directory if you choose a different app name (apps/your-name/src/api) or perhaps you want to generate into a shared library (libs/api/src/lib). Last step, add a new script to your package.json let's call it "codegen": "ng-openapi-gen".
🌐
Restack
restack.io › p › swagger-codegen-answer-javascript-example
Swagger Codegen Javascript Example | Restackio
Explore practical examples of using Swagger Codegen for JavaScript to streamline your API development process. | Restackio
🌐
DEV Community
dev.to › samchon › new-nestjs-swagger-generator-evolved-than-ever-1phe
New NestJS Swagger Generator evolved than ever - DEV Community
August 28, 2024 - New NestJS Swagger Generator import { NestiaSwaggerComposer } from... Tagged with typescript, opensource, nestjs, openapi.
🌐
Medium
andrew-larse514.medium.com › full-nestjs-starter-kit-part-5-api-documentation-client-code-generation-576c2c16eed5
Full NestJS Starter Kit — Part 5 API Documentation & Client Code Generation | by Andrew Larsen | Medium
January 25, 2024 - On top of this documentation, we can leverage tools to generate clickable documentation (Swagger UI) and generate actual source code to call our APIs with. We’ll walk through configuring Swagger and generating client code! NestJS offers first class support for swagger which makes the initial setup easy.
🌐
NestJS
docs.nestjs.com › openapi › introduction
OpenAPI (Swagger) | NestJS - A progressive Node.js ...
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
🌐
Medium
medium.com › @exfabrica › nestjs-ultimate-api-documentation-with-swagger-16f628ddf1f2
NestJS: Ultimate API documentation with Swagger | by exFabrica | Medium
June 14, 2022 - On the one hand because it allows to generate API documentation sites at lightning speed and on the other hand for its capacities to generate client proxies from a “swaggerized” API with Swagger CodeGen (an awesome approach, really!) Swagger allows much more than this thin description but our story would be far too long. To integrate Swagger into a NestJS project, let’s run the following command:
🌐
Nestia
nestia.io › docs › swagger
Guide Documents > Swagger Document | Nestia
June 25, 2026 - For CI pipelines, static hosting, or downstream codegen, emit a file instead: ... import { INestiaConfig } from "@nestia/sdk"; import { NestFactory } from "@nestjs/core"; import { AppModule } from "./src/AppModule"; const config: INestiaConfig = { input: () => NestFactory.create(AppModule), output: "src/api", swagger: { openapi: "3.1", // or "3.0" / "2.0" if your tooling needs it output: "dist/swagger.json", info: { title: "My App", version: "1.0.0", }, servers: [ { url: "http://localhost:3000", description: "Local" }, { url: "https://api.example.com", description: "Production" }, ], security: { bearer: { type: "apiKey", name: "Authorization", in: "header" }, }, beautify: true, }, }; export default config;
🌐
jsDelivr
jsdelivr.com › package › npm › @newko › swagger-nestjs-codegen
@newko/swagger-nestjs-codegen CDN by jsDelivr - A CDN for npm and GitHub
September 16, 2023 - A free, fast, and reliable CDN for @newko/swagger-nestjs-codegen. Swagger Codegen Nest.js Framwork
Published   Apr 21, 2022
Top answer
1 of 4
2

I have succeeded of sharing DTO(s) between Angular and Nest.js (Approach #1)

Replacing @angular-devkit/build-angular:browser to @angular-builders/custom-webpack:browser has resolved the errors when building or serving the angular app.

See https://github.com/nestjs/nest/issues/1706#issuecomment-474657479 for more details.

2 of 4
2

Martin's answer is most of the way there, but the situation may sometimes require the presence of these Swagger decorators in your models where certain metadata in the OpenAPI spec might not be expressible via inference using just the cli plugin alone.

You can actually use the @ApiXXX decorators in your models, and still import them into your front-end Angular application directly.

To do this, you will use a shim provided by NestJS in the @nestjs/swagger package, along with a little Webpack-fu.

I am also using Nx (16.0.3), Angular (15.2.8), and NestJS (^9.0.0), so I will demonstrate with my own configurations.

  • First, in your front-end app's project.json be sure you have your build target configured to use the @nx/angular:webpack-browser executor, and your serve target configured to use the @nx/angular:webpack-dev-server executor. For me, the serve target was the sticking point–I thought I was going crazy when my custom Webpack configuration wasn't being picked up, but it is an absolute requirement that you have both the build and serve targets configured using these executors.
  • Be sure your webpack configuration is set up in your front-end's project.json file like so:
{
// ... start of project.json
  "targets": {
    "build": {
      "executor": "@nx/angular:webpack-browser",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/apps/my-angular-app",
        "customWebpackConfig": {
          "path": "apps/my-angular-app/webpack.config.ts"
        }
      }
      // ... remainder of project.json
  • Your front-end app's webpack.config.ts should look something like the following:
import path from 'path';

export default function customConfig(config) {
  return {
    ...config,
    resolve: {
      ...config.resolve,
      alias: {
        ...config.resolve.alias,
        // shims out nestjs swagger module in the frontend for DTO sharing
        '@nestjs/swagger': path.resolve(__dirname, '../../node_modules/@nestjs/swagger/dist/extra/swagger-shim')
      }
    }
  };
}
  • Import your backend DTO into your front-end service, and enjoy not having to write the same model code twice!

Bonus

Additionally, the Swagger CLI Plugin mentioned by Martin can be used at the same time to take advantage of all of the other benefits it offers.

Assuming you're using the @nx/webpack:webpack executor to build your back-end service and the @nx/js:js executor for serve, you may configure the Swagger CLI Plugin like so:

// ... start of project.json
"targets": {
    "build": {
      "executor": "@nx/webpack:webpack",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "production",
      "options": {
        // ... other options
        "webpackConfig": "apps/my-backend-app/webpack.config.ts",
        "transformers": [
          {
            "name": "@nestjs/swagger/plugin",
            "options": {
              "introspectComments": true
              // other plugin options here
            }
          }
        ]
        // ... other options
      }
      // ... remainder of project.json

To any future reader, please keep in mind that these executor names and options may change from one major version of Nx to another, but the core of the solution is to ensure you configure the @nestjs/swagger shims correctly in your front-end bundler, and that if you so desire, you set up the transformers to use the NestJS Swagger CLI Plugin for your back-end similar to the above.

🌐
Reddit
reddit.com › r/nextjs › is there something similar to swagger codegen for nextjs api routes?
r/nextjs on Reddit: Is there something similar to swagger codegen for Nextjs API routes?
September 7, 2024 -

consider this endpoint:
src/app/api/todos/[todoId]/route.ts

export async function GET() {  
const data:TodoDetails = ...  
return data;  
}  

which can generate something like:

function getTodo(params: { todoId: string}){  
return fetch(`api/todos/${todoId}`) as TodoDetails  
}  

is there anything like this, or a tool that can generate swagger schemas?

EDIT:
I've gone with https://elysiajs.com they have a Nextjs integration, if you're not using bun, have a look at Hono