Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions frameworks-nestjs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
56 changes: 56 additions & 0 deletions frameworks-nestjs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# compiled output
/dist
/node_modules
/build

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
4 changes: 4 additions & 0 deletions frameworks-nestjs/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
81 changes: 81 additions & 0 deletions frameworks-nestjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<div align="center">
<a href="https://www.speakeasy.com/" target="_blank">
<img width="1500" height="500" alt="Speakeasy" src="https://github.com/user-attachments/assets/0e56055b-02a3-4476-9130-4be299e5a39c" />
</a>
<br />
<br />
<div>
<a href="https://speakeasy.com/docs/create-client-sdks/" target="_blank"><b>Docs Quickstart</b></a>&nbsp;&nbsp;//&nbsp;&nbsp;<a href="https://go.speakeasy.com/slack" target="_blank"><b>Join us on Slack</b></a>
</div>
<br />
</div>

<h2>Speakeasy NestJS OpenAPI Example — Train Travel API</h2>

This example NestJS app demonstrates Speakeasy-recommended practices for generating clear OpenAPI specifications and SDKs for a Train Travel API with stations, trips, bookings, and payments.

The project uses [NestJS 11](https://nestjs.com/), [@nestjs/swagger 11](https://github.com/nestjs/swagger), and [Scalar API Reference](https://scalar.com/). The generated document is configured as OpenAPI 3.2 through the native NestJS Swagger `DocumentBuilder` API.

## Prerequisites

- Node.js >= 20
- The [NestJS CLI](https://docs.nestjs.com/cli/overview):
```bash
npm install -g @nestjs/cli
```
- The [Speakeasy CLI](https://github.com/speakeasy-api/speakeasy#installation) for SDK generation:
```bash
brew install speakeasy-api/homebrew-tap/speakeasy
```

## Installation

```bash
git clone https://github.com/speakeasy-api/nestjs-openapi-example.git
cd nestjs-openapi-example
npm install
```

## Running the server

```bash
npm run start:dev
```

Open [http://localhost:3000/api](http://localhost:3000/api) to view the Scalar API reference UI.

## Generating the OpenAPI document

Generate `openapi.yaml` without starting the long-running server:

```bash
npm run generate:openapi
```

## API endpoints

| Method | Path | Description |
|--------|------|-------------|
| GET | `/stations` | List train stations |
| GET | `/trips` | List available trips |
| GET | `/bookings` | List bookings |
| POST | `/bookings` | Create a booking |
| GET | `/bookings/:bookingId` | Get a booking |
| DELETE | `/bookings/:bookingId` | Cancel a booking |
| POST | `/bookings/:bookingId/payment` | Pay for a booking |

## Generating an SDK with Speakeasy

```bash
speakeasy quickstart
```

Or generate directly:

```bash
speakeasy generate sdk --schema ./openapi.yaml --lang typescript --out ./sdk-typescript
```

## License

MIT
16 changes: 16 additions & 0 deletions frameworks-nestjs/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"plugins": [
{
"name": "@nestjs/swagger",
"options": {
"introspectComments": true
}
}
]
}
}
Loading