{"id":20851935,"url":"https://github.com/stackclash/prisma-generator-nestjs-dto","last_synced_at":"2025-10-26T10:40:58.284Z","repository":{"id":282032418,"uuid":"888644342","full_name":"Stackclash/prisma-generator-nestjs-dto","owner":"Stackclash","description":"Generates NestJS DTO classes from Prisma Schema","archived":false,"fork":true,"pushed_at":"2024-10-30T11:24:35.000Z","size":1061,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-12T12:43:06.243Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Brakebein/prisma-generator-nestjs-dto","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Stackclash.png","metadata":{},"created_at":"2024-11-14T18:52:25.000Z","updated_at":"2024-11-14T18:52:25.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/Stackclash/prisma-generator-nestjs-dto","commit_stats":null,"previous_names":["stackclash/prisma-generator-nestjs-dto"],"tags_count":null,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stackclash%2Fprisma-generator-nestjs-dto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stackclash%2Fprisma-generator-nestjs-dto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stackclash%2Fprisma-generator-nestjs-dto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stackclash%2Fprisma-generator-nestjs-dto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Stackclash","download_url":"https://codeload.github.com/Stackclash/prisma-generator-nestjs-dto/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243222184,"owners_count":20256220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T03:15:36.733Z","updated_at":"2025-10-26T10:40:53.263Z","avatar_url":"https://github.com/Stackclash.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Prisma Generator NestJS DTO\n\n[![Release](https://badge.fury.io/js/%40brakebein%2Fprisma-generator-nestjs-dto.svg)](https://www.npmjs.com/package/@brakebein/prisma-generator-nestjs-dto)\n[![License](https://img.shields.io/github/license/Brakebein/prisma-generator-nestjs-dto.svg?label=license)](#license)\n\n1. [What is it?](#what-is-it)\n1. [Usage](#usage)\n1. [Annotations](#annotations)\n1. [Example](#example)\n1. [Principles](#principles)\n1. [License](#license)\n\n## What is it?\n\nGenerates `ConnectDTO`, `CreateDTO`, `UpdateDTO`, `DTO`, and `Entity` classes for models in your Prisma Schema. This is useful if you want to leverage [OpenAPI](https://docs.nestjs.com/openapi/introduction) in your [NestJS](https://nestjs.com/) application - but also helps with GraphQL resources as well). NestJS Swagger requires input parameters in [controllers to be described through classes](https://docs.nestjs.com/openapi/types-and-parameters) because it leverages TypeScript's emitted metadata and `Reflection` to generate models/components for the OpenAPI spec. It does the same for response models/components on your controller methods.\n\nThese classes can also be used with the built-in [ValidationPipe](https://docs.nestjs.com/techniques/validation#using-the-built-in-validationpipe) and [Serialization](https://docs.nestjs.com/techniques/serialization).\n\nThis is a fork of [@vegardit/prisma-generator-nestjs-dto](https://github.com/vegardit/prisma-generator-nestjs-dto) and adds multiple features:\n\n* enhance fields with additional schema information, e.g., description, to generate a `@ApiProperty()` decorator (see [Schema Object annotations](#schema-object-annotations))\n* optionally add [validation decorators](#validation-decorators)\n* support for composite types\n* control output format with additional flags `flatResourceStructure`, `noDependencies`, and `outputType`\n* optionally auto-format output with prettier\n\nSee [CHANGELOG](CHANGELOG.md) for all improvements and changes.\n\n### ToDo\n\n- [ ] fix `enum` handling\n\n## Usage?\n\n```sh\nnpm install --save-dev @brakebein/prisma-generator-nestjs-dto\n```\n\n```prisma\ngenerator nestjsDto {\n  provider                        = \"prisma-generator-nestjs-dto\"\n  output                          = \"../src/generated/nestjs-dto\"\n  outputToNestJsResourceStructure = \"false\"\n  flatResourceStructure           = \"false\"\n  exportRelationModifierClasses   = \"true\"\n  reExport                        = \"false\"\n  generateFileTypes               = \"all\"\n  createDtoPrefix                 = \"Create\"\n  updateDtoPrefix                 = \"Update\"\n  dtoSuffix                       = \"Dto\"\n  entityPrefix                    = \"\"\n  entitySuffix                    = \"\"\n  classValidation                 = \"false\"\n  fileNamingStyle                 = \"camel\"\n  noDependencies                  = \"false\"\n  outputType                      = \"class\"\n  definiteAssignmentAssertion     = \"false\"\n  requiredResponseApiProperty     = \"true\"\n  prettier                        = \"false\"\n  outputApiPropertyType           = \"true\"\n}\n```\n\n### Parameters\n\nAll parameters are optional.\n\n| Parameter = default                                              | Description                                                                                                                                                                                                          |\n|------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `output = \"../src/generated/nestjs-dto\"`                         | output path relative to your `schema.prisma` file                                                                                                                                                                    |\n| \u003ccode\u003eoutputToNestJsResourceStructure\u0026nbsp;=\u0026nbsp;\"false\"\u003c/code\u003e | writes `dto`s and `entities` to subfolders aligned with [NestJS CRUD generator](https://docs.nestjs.com/recipes/crud-generator). Resource module name is derived from lower-cased model name in `schema.prisma`      |\n| `flatResourceStructure = \"false\"`                                | If `outputToNestJsResourceStructure` is `true`, subfolders `dto`s and `entities` are created within the resource folder. Setting this to `true` will flatten the hierarchy.                                          |\n| `exportRelationModifierClasses = \"true\"`                         | Should extra classes generated for relationship field operations on DTOs be exported?                                                                                                                                |\n| `reExport = \"false\"`                                             | Should an index.ts be created for every folder?                                                                                                                                                                      |\n| `generateFileTypes = \"all\"`                                      | `all`: generate both DTO and Entity files, `dto`: generate only DTO files, `entity`: generate only Entity files (not possible in combination with complex types)                                                     |\n| `createDtoPrefix = \"Create\"`                                     | phrase to prefix every `CreateDTO` class with                                                                                                                                                                        |\n| `updateDtoPrefix = \"Update\"`                                     | phrase to prefix every `UpdateDTO` class with                                                                                                                                                                        |\n| `dtoSuffix = \"Dto\"`                                              | phrase to suffix every `CreateDTO` and `UpdateDTO` class with                                                                                                                                                        |\n| `entityPrefix = \"\"`                                              | phrase to prefix every `Entity` class with                                                                                                                                                                           |\n| `entitySuffix = \"\"`                                              | phrase to suffix every `Entity` class with                                                                                                                                                                           |\n| `fileNamingStyle = \"camel\"`                                      | How to name generated files. Valid choices are `\"camel\"`, `\"pascal\"`, `\"kebab\"` and `\"snake\"`.                                                                                                                       |\n| `classValidation = \"false\"`                                      | Add validation decorators from `class-validator`. Not compatible with `noDependencies = \"true\"` and `outputType = \"interface\"`.                                                                                      |\n| `noDependencies = \"false\"`                                       | Any imports and decorators that are specific to NestJS and Prisma are omitted, such that there are no references to external dependencies. This is useful if you want to generate appropriate DTOs for the frontend. |\n| `outputType = \"class\"`                                           | Output the DTOs as `class` or as `interface`. `interface` should only be used to generate DTOs for the frontend.                                                                                                     |\n| `definiteAssignmentAssertion = \"false\"`                          | Add a definite assignment assertion operator `!` to required fields, which is required if `strict` and/or `strictPropertyInitialization` is set `true` in your tsconfig.json's `compilerOptions`.                    |\n| `requiredResponseApiProperty = \"true\"`                           | If `false`, add `@ApiRequired({ required: false })` to response DTO properties. Otherwise, use `required` defaults always to `true` unless field is optional.                                                        |\n| `prettier = \"false\"`                                             | Stylize output files with prettier.                                                                                                                                                                                  |\n| `outputApiPropertyType = \"true\"`                                 | If `false`, omit `type` property inside `@ApiProperty()` (see [#39](https://github.com/Brakebein/prisma-generator-nestjs-dto/issues/39#issuecomment-2168651849))                                                     |\n\n## Annotations\n\nAnnotations provide additional information to help this generator understand your intentions. They are applied as [tripple slash comments](https://www.prisma.io/docs/concepts/components/prisma-schema#comments) to a field node in your Prisma Schema. You can apply multiple annotations to the same field.\n\n```prisma\nmodel Post {\n  /// @DtoCreateOptional\n  /// @DtoUpdateHidden\n  createdAt   DateTime @default(now())\n  /// @DtoCastType(DurationLike, luxon)\n  timeUntilExpires Json?\n}\n```\n\n| Annotation                          | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |\n|-------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `@DtoReadOnly`                      | omits field in `CreateDTO` and `UpdateDTO`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |\n| `@DtoCreateHidden`                  | omits field in `CreateDTO`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |\n| `@DtoUpdateHidden`                  | omits field in `UpdateDTO`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |\n| `@DtoEntityHidden`                  | omits field in `Entity`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |\n| `@DtoConnectHidden`                 | omits field in `ConnectDto` (applies to `@id` and `@unique` fields)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |\n| `@DtoApiHidden`                     | adds `@ApiHideProperty` decorator to hide field in documentation, class validation remains untouched                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |\n| `@DtoCreateOptional`                | adds field **optionally** to `CreateDTO` - useful for fields that would otherwise be omitted (e.g. `@id`, `@updatedAt`)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |\n| `@DtoUpdateOptional`                | adds field **optionally** to `UpdateDTO` - useful for fields that would otherwise be omitted (e.g. `@id`, `@updatedAt`)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |\n| `@DtoUpdateRequired`                | marks field **required** in `UpdateDTO` that is otherwise optional                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |\n| `@DtoRelationRequired`              | marks relation **required** in `Entity` although it's optional in PrismaSchema - useful when you don't want (SQL) `ON DELETE CASCADE` behavior - but your logical data schema sees this relation as required  (**Note**: becomes obsolete once [referentialActions](https://github.com/prisma/prisma/issues/7816) are released and stable)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |\n| `@DtoRelationCanCreateOnCreate`     | adds [create](https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#create-a-related-record) option on a relation field in the generated `CreateDTO` - useful when you want to allow to create related model instances                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |\n| `@DtoRelationCanConnectOnCreate`    | adds [connect](https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#connect-multiple-records) option on a relation field in the generated `CreateDTO` - useful when you want/need to connect to an existing related instance                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |\n| `@DtoRelationCanCreateOnUpdate`     | adds [create](https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#create-a-related-record) option on a relation field in the generated `UpdateDTO` - useful when you want to allow to create related model instances                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |\n| `@DtoRelationCanConnectOnUpdate`    | adds [connect](https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#connect-multiple-records) option on a relation field in the generated `UpdateDTO` - useful when you want/need to connect to an existing related instance                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |\n| `@DtoRelationCanDisconnectOnUpdate` | adds [disconnect](https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#disconnect-a-related-record) option on a relation field in the generated `UpdateDTO` - useful when you want/need to disconnect to an existing related instance                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |\n| `@DtoRelationIncludeId`             | include ID of a relation field that is otherwise omitted (use instead of `CanCreate`/`CanConnect` annotations, if you just want to pass the IDs)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |\n| `@DtoTypeFullUpdate`                | in the generated `UpdateDTO`, use the `CreateDTO` of the composite type to enforce a complete replacement the old values (see [#2](https://github.com/Brakebein/prisma-generator-nestjs-dto/issues/2#issuecomment-1238855460))                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |\n| `@DtoCastType(...)`                 | in all the generated entities, forces a provided type for this field. Especially useful if you need to cast Json fields at read/write. Note, you must provide at least one and may provide up to 3 arguments in the `(...)` with this annotation - the first is the name of the type to force for this field, the second and third can be used to add an `import` for that type at the top of the entity file. For example: \u003cul\u003e\u003cli\u003e`@DtoCastType(MyType)` will cast the field as `MyType` but add no import\u003c/li\u003e\u003cli\u003e`@DtoCastType(MyType, some-package)` will cast the field as `MyType` and add `import {MyType} from \"some-package\"`\u003c/li\u003e\u003cli\u003e`@DtoCastType(MyType, ../types, default)` will cast and add `import MyType from \"../types\"`\u003c/li\u003e\u003cli\u003e`@DtoCastType(MyTypeInterface, ../types, MyType)` will cast as `MyTypeInterface` and add `import {MyType as MyTypeInterface} from \"../types\"`\u003c/li\u003e\u003c/ul\u003e |\n| `@DtoCreateValidateIf(...)`         | adds @ValidateIf(...) decorator for field in `CreateDTO` (for [conditional validation](https://github.com/typestack/class-validator#conditional-validation) by class-validator)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |                                                                                                                                                     |\n| `@DtoUpdateValidateIf(...)`         | adds @ValidateIf(...) decorator for field in `UpdateDTO` (for [conditional validation](https://github.com/typestack/class-validator#conditional-validation) by class-validator)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |\n### Schema Object annotations\n\nWith `@nestjs/swagger`, you can generate an API specification from code.\nRoutes, request bodies, query parameters, etc., are annotated with special decorators.\nProperties can be annotated with the `@ApiProperty()` decorator to add schema object information.\nThey are partially added at runtime, which will then include `type`, `nullable`, etc.\nBut additional information, such as description, need to be added manually.\n\nIf using a generator like this, any custom `@ApiProperty()` annotation would be overridden when updating the DTOs.\nTo enhance a field with additional schema information, add the schema property prefixed with `@` to the comment section above the field.\n\nCurrently, following schema properties are supported:\n\n* `description`\n* `minimum`\n* `maximum`\n* `exclusiveMinimum`\n* `exclusiveMaximum`\n* `minLength`\n* `maxLength`\n* `minItems`\n* `maxItems`\n* `example`\n\nAdditionally, special data types are inferred and annotated as well:\n\n* `Int: { type: 'integer', format: 'int32' }`\n* `BigInt: { type: 'integer', format: 'int64' }`\n* `Float: { type: 'number', format: 'float' }`\n* `Decimal: { type: 'number', format: 'double' }`\n* `DateTime: { type: 'string', format: 'date-time' }`\n\n#### Example\n\nThis example using `@description` and `@minimum` tags\n\n```prisma\n/// @description Number of reviews\n/// @minimum 9\nreviewCount Int     @default(0)\n```\n\nwill generate `@ApiProperty()` decorator with `description` and `minimum` as properties as well as `type` and `format` to specify the data type.\n\n```typescript\n@ApiProperty({\n  description: 'Number of reviews',\n  minimum: 9,\n  type: 'integer',\n  format: 'int32',\n})\nreviewCount: number;\n```\n\nDefault values are added in `CreateDTO` and `UpdateDTO`.\nHowever, a field with a `@default()` attribute is hidden by default in `CreateDTO` and `UpdateDTO`,\nhence requires `@DtoCreateOptional` and/or `@DtoUpdateOptional` to be present.\n\n### Validation decorators\n\nIf `classValidation = \"true\"`, the generator will add validation decorators from [class-validator](https://github.com/typestack/class-validator) to each field of `CreateDTO` and `UpdateDTO` that can then be used in combination with the NestJS `ValidationPipe` (see [NestJS Auto-validation](https://docs.nestjs.com/techniques/validation#auto-validation)).\n\nSome decorators will be inferred from the field's attributes.\nIf the field is optional, it will add `@IsOptional()`, otherwise `@IsNotEmpty()`.\nIf the field is a list, it will add `@IsArray()`.\nType validators are inferred from the field's type:\n\n* `String` \u0026rarr; `@IsString()`\n* `Boolean` \u0026rarr; `@IsBoolean()`\n* `Int` \u0026rarr; `@IsInt()`\n* `BigInt` \u0026rarr; `@IsInt()`\n* `Float:` \u0026rarr; `@IsNumber()`\n* `Decimal:` \u0026rarr; `@IsDecimal()`\n* `DateTime` \u0026rarr; `@IsDateString()`\n\nAll remaining [validation decorators](https://github.com/typestack/class-validator#validation-decorators) can be added in the comment/documentation section above the field.\nThe parentheses can be omitted if not passing a value.\n\n#### Example\n\nPrisma Schema\n\n```prisma\n/// @Contains('Product')\nname        String   @db.VarChar(255)\nreviewCount Int      @default(0)\n/// @ArrayNotEmpty\ntags        String[]\nscore       Float?\n```\n\nGenerated output\n\n```typescript\n@IsNotEmpty()\n@IsString()\n@Contains('Product')\nname: string;\n@IsOptional()\n@IsInt()\nreviewCount?: number;\n@IsNotEmpty()\n@IsArray()\n@ArrayNotEmpty()\ntags: string[];\n@IsOptional()\n@IsNumber()\nscore?: number;\n```\n\n## Example\n\n\u003cdetails\u003e\n  \u003csummary\u003ePrisma Schema\u003c/summary\u003e\n  \n```prisma\ngenerator nestjsDto {\n  provider = \"prisma-generator-nestjs-dto\"\n  output = \"../src\"\n  outputToNestJsResourceStructure = \"true\"\n}\n\nmodel Question {\n  id          String @id @default(dbgenerated(\"gen_random_uuid()\")) @db.Uuid\n  /// @DtoReadOnly\n  createdAt   DateTime @default(now())\n  /// @DtoRelationRequired\n  createdBy   User? @relation(\"CreatedQuestions\", fields: [createdById], references: [id])\n  createdById String? @db.Uuid\n  updatedAt   DateTime @updatedAt\n  /// @DtoRelationRequired\n  updatedBy   User? @relation(\"UpdatedQuestions\", fields: [updatedById], references: [id])\n  updatedById String? @db.Uuid\n\n  /// @DtoRelationRequired\n  /// @DtoRelationCanConnectOnCreate\n  category   Category? @relation(fields: [categoryId], references: [id])\n  categoryId String?   @db.Uuid\n\n  /// @DtoCreateOptional\n  /// @DtoRelationCanCreateOnCreate\n  /// @DtoRelationCanConnectOnCreate\n  /// @DtoRelationCanCreateOnUpdate\n  /// @DtoRelationCanConnectOnUpdate\n  tags Tag[]\n\n  title     String\n  content   String\n  responses Response[]\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eGenerated results\u003c/summary\u003e\n\n```ts\n// src/question/dto/connect-question.dto.ts\nexport class ConnectQuestionDto {\n  id: string;\n}\n```\n\n```ts\n// src/question/dto/create-question.dto.ts\nimport { ApiExtraModels } from '@nestjs/swagger';\nimport { ConnectCategoryDto } from '../../category/dto/connect-category.dto';\nimport { CreateTagDto } from '../../tag/dto/create-tag.dto';\nimport { ConnectTagDto } from '../../tag/dto/connect-tag.dto';\n\nexport class CreateQuestionCategoryRelationInputDto {\n  connect: ConnectCategoryDto;\n}\nexport class CreateQuestionTagsRelationInputDto {\n  create?: CreateTagDto[];\n  connect?: ConnectTagDto[];\n}\n\n@ApiExtraModels(\n  ConnectCategoryDto,\n  CreateQuestionCategoryRelationInputDto,\n  CreateTagDto,\n  ConnectTagDto,\n  CreateQuestionTagsRelationInputDto,\n)\nexport class CreateQuestionDto {\n  category: CreateQuestionCategoryRelationInputDto;\n  tags?: CreateQuestionTagsRelationInputDto;\n  title: string;\n  content: string;\n}\n```\n\n```ts\n// src/question/dto/update-question.dto.ts\nimport { ApiExtraModels } from '@nestjs/swagger';\nimport { CreateTagDto } from '../../tag/dto/create-tag.dto';\nimport { ConnectTagDto } from '../../tag/dto/connect-tag.dto';\n\nexport class UpdateQuestionTagsRelationInputDto {\n  create?: CreateTagDto[];\n  connect?: ConnectTagDto[];\n}\n\n@ApiExtraModels(CreateTagDto, ConnectTagDto, UpdateQuestionTagsRelationInputDto)\nexport class UpdateQuestionDto {\n  tags?: UpdateQuestionTagsRelationInputDto;\n  title?: string;\n  content?: string;\n}\n```\n\n```ts\n// src/question/entities/question.entity.ts\nimport { User } from '../../user/entities/user.entity';\nimport { Category } from '../../category/entities/category.entity';\nimport { Tag } from '../../tag/entities/tag.entity';\nimport { Response } from '../../response/entities/response.entity';\n\nexport class Question {\n  id: string;\n  createdAt: Date;\n  createdBy?: User;\n  createdById: string;\n  updatedAt: Date;\n  updatedBy?: User;\n  updatedById: string;\n  category?: Category;\n  categoryId: string;\n  tags?: Tag[];\n  title: string;\n  content: string;\n  responses?: Response[];\n}\n```\n\n\u003c/details\u003e\n\n## Principles\n\nGenerally we read field properties from the `DMMF.Field` information provided by `@prisma/generator-helper`. Since a few scenarios don't become quite clear from that, we also check for additional [annotations](#annotations) (or `decorators`) in a field's `documentation` (that is anything provided as a [tripple slash comments](https://www.prisma.io/docs/concepts/components/prisma-schema#comments) for that field in your `prisma.schema`).\n\nInitially, we wanted `DTO` classes to `implement Prisma.\u003cModelName\u003e\u003c(Create|Update)\u003eInput` but that turned out to conflict with **required** relation fields.\n\n### ConnectDTO\n\nThis kind of DTO represents the structure of input-data to expect from 'outside' (e.g. REST API consumer) when attempting to `connect` to a model through a relation field.\n\nA `Model`s `ConnectDTO` class is composed from a unique'd list of `isId` and `isUnique` scalar fields. If the `ConnectDTO` class has exactly one property, the property is marked as required. If there are more than one properties, all properties are optional (since setting a single one of them is already sufficient for a unique query) - you must however specify at least one property.\n\n`ConnectDTO`s are used for relation fields in `CreateDTO`s and `UpdateDTO`s.\n\n### CreateDTO\n\nThis kind of DTO represents the structure of input-data to expect from 'outside' (e.g. REST API consumer) when attempting to `create` a new instance of a `Model`.\nTypically the requirements for database schema differ from what we want to allow users to do.\nAs an example (and this is the opinion represented in this generator), we don't think that relation scalar fields should be exposed to users for `create`, `update`, or `delete` activities (btw. TypeScript types generated in PrismaClient exclude these fields as well). If however, your schema defines a required relation, creating an entity of that Model would become quite difficult without the relation data.\nIn some cases you can derive information regarding related instances from context (e.g. HTTP path on the rest endpoint `/api/post/:postid/comment` to create a `Comment` with relation to a `Post`). For all other cases, we have the\n\n- `@DtoRelationCanCreateOnCreate`\n- `@DtoRelationCanConnectOnCreate`\n- `@DtoRelationCanCreateOnUpdate`\n- `@DtoRelationCanConnectOnUpdate`\n\n[annotations](#annotations) that generate corresponding input properties on `CreateDTO` and `UpdateDTO` (optional or required - depending on the nature of the relation).\n\nWhen generating a `Model`s `CreateDTO` class, field that meet any of the following conditions are omitted (**order matters**):\n\n- `isReadOnly` OR is annotated with `@DtoReadOnly` (_Note:_ this apparently includes relation scalar fields)\n- field represents a relation (`field.kind === 'object'`) and is not annotated with `@DtoRelationCanCreateOnCreate` or `@DtoRelationCanConnectOnCreate`\n- field is a [relation scalar](https://www.prisma.io/docs/concepts/components/prisma-schema/relations/#annotated-relation-fields-and-relation-scalar-fields)\n- field is not annotated with `@DtoCreateOptional` AND\n  - `isId \u0026\u0026 hasDefaultValue` (id fields are not supposed to be provided by the user)\n  - `isUpdatedAt` ([Prisma](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#updatedat) will inject value)\n  - `isRequired \u0026\u0026 hasDefaultValue` (for schema-required fields that fallback to a default value when empty. Think: `createdAt` timestamps with `@default(now())` (see [now()](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#now)))\n\n### UpdateDTO\n\nWhen generating a `Model`s `UpdateDTO` class, field that meet any of the following conditions are omitted (**order matters**):\n\n- field is annotated with `@DtoUpdateOptional`\n- `isReadOnly` OR is annotated with `@DtoReadOnly` (_Note:_ this apparently includes relation scalar fields)\n- `isId` (id fields are not supposed to be updated by the user)\n- field represents a relation (`field.kind === 'object'`) and is not annotated with `@DtoRelationCanCreateOnUpdate` or `@DtoRelationCanConnectOnUpdate`\n- field is a [relation scalar](https://www.prisma.io/docs/concepts/components/prisma-schema/relations/#annotated-relation-fields-and-relation-scalar-fields)\n- field is not annotated with `@DtoUpdateOptional` AND\n  - `isId` (id fields are not supposed to be updated by the user)\n  - `isUpdatedAt` ([Prisma](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#updatedat) will inject value)\n  - `isRequired \u0026\u0026 hasDefaultValue` (for schema-required fields that fallback to a default value when empty. Think: `createdAt` timestamps with `@default(now())` (see [now()](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#now)))\n\n### Entity\n\nWhen generating a `Model`s `Entity` class, only fields annotated with `@DtoEntityHidden` are omitted.\nAll other fields are only manipulated regarding their `isRequired` and `isNullable` flags.\n\nBy default, every scalar field in an entity is `required` meaning it doesn't get the TypeScript \"optional member flag\" `?` next to it's name. Fields that are marked as optional in PrismaSchema are treated as `nullable` - meaning their TypeScript type is a union of `field.type` and `null` (e.g. `string | null`).\n\nRelation and [relation scalar](https://www.prisma.io/docs/concepts/components/prisma-schema/relations/#annotated-relation-fields-and-relation-scalar-fields) fields are treated differently. If you don't specifically `include` a relation in your query, those fields will not exist in the response.\n\n- every relation field is always optional (`isRequired = false`)\n- relations are nullable except when\n  - the relation field is a one-to-many or many-to-many (i.e. list) type (would return empty array if no related records found)\n  - the relation was originally flagged as required (`isRequired = true`)\n  - the relation field is annotated with `@DtoRelationRequired` (do this when you mark a relation as optional in PrismaSchema because you don't want (SQL) `ON DELETE CASCADE` behavior - but your logical data schema sees this relation as required)\n- default values are \u003cins\u003enot\u003c/ins\u003e added to the `@ApiProperty()` decorator\n\n### DTO\n\nThe plain `DTO` class is almost the same as `Entity` with the difference that all relation fields are omitted.\nThis is useful if your response is the plain entity without any (optional) relations.\n\n## License\n\nAll files are released under the [Apache License 2.0](https://github.com/Brakebein/prisma-generator-nestjs-dto/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackclash%2Fprisma-generator-nestjs-dto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackclash%2Fprisma-generator-nestjs-dto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackclash%2Fprisma-generator-nestjs-dto/lists"}