Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Add NestJS Example #554

Merged
merged 2 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions examples/8-top-level-discriminator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ npm start

## Try

### Discriminator with explict mapping
### Discriminator with explicit mapping

#### `"pet_type": "cat"
#### `"pet_type": "cat"`

```shell
curl -X POST 'http://localhost:3000/v1/pets/mapping' \
Expand All @@ -32,7 +32,8 @@ npm start
"pet_type": "cat"
}
```
#### `"pet_type": "dog"

#### `"pet_type": "dog"`

```shell
curl -X POST 'http://localhost:3000/v1/pets/mapping' \
Expand All @@ -45,9 +46,9 @@ curl -X POST 'http://localhost:3000/v1/pets/mapping' \
}
```

### Discriminator with implict mapping
### Discriminator with implicit mapping

#### `"pet_type": "DogObject"
#### `"pet_type": "DogObject"`

```shell
curl -X POST 'http://localhost:3000/v1/pets/nomapping' \
Expand Down
53 changes: 53 additions & 0 deletions examples/9-nestjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# NestJS Example

This example demonstrates how to use `express-openapi-validator` with [NestJS](https://nestjs.com/).

## Install

From this `9-nestjs` directory, run:

```shell
npm ci
```

## Run

### Start Server

#### Watch Mode

```shell
npm run start
```

or

```shell
npm run start:dev
```

#### Production Mode

```shell
npm run build
npm run start:prod
```

### Requests

```shell
curl --request GET --url http://localhost:3000/ping/foo
```

```shell
curl --request POST \
--url http://localhost:3000/ping \
--header 'Content-Type: application/json' \
--data '{"ping": "GNU Terry Pratchett"}'
```

## Tests

```shell
npm run test
```
12 changes: 12 additions & 0 deletions examples/9-nestjs/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
moduleFileExtensions: ['ts', 'js'],
testMatch: ['**/*.spec.ts'],
transform: {
'\\.ts': 'ts-jest',
},

testEnvironment: 'node',
};
export default config;
7 changes: 7 additions & 0 deletions examples/9-nestjs/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": false,
"tsConfigPath": "tsconfig.json"
}
}