Skip to content

Commit

Permalink
doc: Add NestJS Example (#554)
Browse files Browse the repository at this point in the history
* fix: Typos and Formatting in README of Example 8

* doc: Add NestJS Example
  • Loading branch information
ahilke committed Mar 7, 2021
1 parent af84b47 commit 61ddf2b
Show file tree
Hide file tree
Showing 14 changed files with 7,849 additions and 5 deletions.
11 changes: 6 additions & 5 deletions examples/8-top-level-discriminator/README.md
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
@@ -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
@@ -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
@@ -0,0 +1,7 @@
{
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": false,
"tsConfigPath": "tsconfig.json"
}
}

0 comments on commit 61ddf2b

Please sign in to comment.