# prisma-generator-nestjs-swagger

> generates basic dto classes for use with @nestjs/swagger and class-validator

Latest version **2.0.10** (published 2023-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install prisma-generator-nestjs-swagger
pnpm add prisma-generator-nestjs-swagger
yarn add prisma-generator-nestjs-swagger
bun add prisma-generator-nestjs-swagger
```

Provides the command `prisma-generator-nestjs-swagger`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.10 |
| Published | 2023-04-30 |
| First published | 2023-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=14.0 |
| Dependencies | 6 |
| Unpacked size | 127.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | dayne.mentier@gmail.com |
| Maintainers | dayne.mentier |
| Keywords | nestjs, @nestjs/swagger, class-validator, prisma, generator, crud |

## Links

- npm: https://www.npmjs.com/package/prisma-generator-nestjs-swagger
- npm.io page: https://npm.io/package/prisma-generator-nestjs-swagger

## Dependencies (6)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [@swc/cli](https://npm.io/package/@swc/cli.md) ^0.1.62
- [prettier](https://npm.io/package/prettier.md) ^2.8.4
- [@swc/core](https://npm.io/package/@swc/core.md) ^1.3.36
- [@prisma/generator-helper](https://npm.io/package/@prisma/generator-helper.md) ^4.10.1
- [@trivago/prettier-plugin-sort-imports](https://npm.io/package/@trivago/prettier-plugin-sort-imports.md) ^4.0.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 2.0.10 (latest) — 2023-04-30
- 2.0.9 — 2023-04-16
- 2.0.8 — 2023-04-16
- 2.0.7 — 2023-04-15
- 2.0.6 — 2023-04-09
- 2.0.5 — 2023-04-08
- 2.0.4 — 2023-04-08
- 2.0.3 — 2023-04-08
- 2.0.2 — 2023-04-07
- 2.0.1 — 2023-04-07
- 2.0.0 — 2023-04-07
- 1.3.3 — 2023-03-18
- 1.3.2 — 2023-03-18
- 1.3.1 — 2023-03-18
- 1.3.0 — 2023-03-18
- … 13 more at https://npm.io/package/prisma-generator-nestjs-swagger/versions

## README

# prisma-generator-nestjs-swagger

This generator is used to create all the possible dto classes you'll need for
prisma crud operations, while also supporting open-api specs, including:

- Create
- Delete
- Find
- Update

[//]: # (- FindUnique)

It includes an extended ValidationPipe serializer that will transform the DTO to
match the expected prisma query object. It includes support for pagination (skip/take or cursor),
filtering and ordering.

### Getting Started

1. Install the generator

```bash
npm i prisma-generator-nestjs-swagger
```

2. Inside your prisma schema, add the following:

```
generator nestJsSwagger {
  provider = "prisma-generator-nestjs-swagger"
}
```

The output will be generated to:

```
node_modules/@generated/swagger
```

3. Add the `ValidationPipe` as a global pipe:

```typescript
import { ValidationPipe } from '@nestjs/common';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  app.useGlobalPipes(new ValidationPipe({transform: true}));

  await app.listen(3000);
}
```

[//]: # ()
[//]: # (_*_ This is a wrapper around [ValidationPipe]&#40;https://docs.nestjs.com/techniques/validation&#41; that invokes)

[//]: # (a serialized method no the generated DTOs.)

4. Import & use the generated DTOs (based on code generated in example):

```typescript
import { FindManyUserDto } from '@generated/swagger';
import { Controller, Get, Query, Req, Res } from '@nestjs/common';

// assumed import of prisma wrapped service
import { PrismaService } from '../prisma/prisma.service';

@Controller()
export class UserController {
  constructor(private prisma: PrismaService) {
  }

  @Get('/users')
  async getUsers(@Query() query: FindManyUserDto, @Res() res) {
    const value = await this.prisma.user.findMany({
      cursor: query.cursor,
      orderBy: query.orderBy,
      skip: query.skip,
      take: query.take,
      where: query.where
    });

    return res.send(value);
  }
}
```

---

[//]: # ()
[//]: # (### Supported Filters)

[//]: # ()
[//]: # (| suffix       | description              | types supported        | Example                                 |)

[//]: # (|--------------|--------------------------|------------------------|-----------------------------------------|)

[//]: # (| __gt         | greater than             | Number, Date, DateTime | createdAt__gt=2023-03-18T16:51:33.991Z  |)

[//]: # (| __gte        | greater than or equal to | Number, Date, DateTime | createdAt__gte=2023-03-18T16:51:33.991Z |)

[//]: # (| __lt         | less than                | Number, Date, DateTime | createdAt__lt=2023-03-18T16:51:33.991Z  |)

[//]: # (| __lte        | less than or equal to    | Number, Date, DateTime | createdAt__lte=2023-03-18T16:51:33.991Z |)

[//]: # (| __contains   | starts containing        | String                 | email__contains=test                    |)

[//]: # (| __endsWith   | starts ends with         | String                 | email__endsWith=@gmail.com              |)

[//]: # (| __startsWith | starts starts with       | String                 | email__startsWith=test@                 |)

[//]: # ()
[//]: # (---)

### Example

See our this [doc](https://github.com/mainfraame/prisma-generator-nestjs-swagger/blob/main/docs/Example.md) for an example output

---
_Source: https://npm.io/package/prisma-generator-nestjs-swagger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
