vegardit / prisma-generator-nestjs-dto

Generates NestJS DTO classes from Prisma Schema

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Requests] - Don't override existing - Generate Only Entity/Dto/Create

ragokan opened this issue · comments

Hello, firstly I would like to say thank you for this amazing package. It saved a lot of time for me. Because I am using it currently, I would like to suggest/request two features.

1: Don't override if file exists

  • When it is generated, sometimes we do changes such as adding validator decorators. Especially when I use outputToNestJsResourceStructure = "true", I do add validators. It would be good if this package does not do anything if there is any file on that location. ( as an option )

2: Select what is going to be generated. For example only generate Entity and Create Dto

another idea could be checking if file exists on that path and has some other annotations then generate classes with those existing annotations.

another idea could be checking if file exists on that path and has some other annotations then generate classes with those existing annotations.

This is actually better but I don't know if it is harder to do.

not overriding existing files could lead to inconsistent behaviour. esp. when we import that existing file in another newly generated file to reuse its generated contents.

What I found to work great for me is to have generators produce code in a separate folder (e.g. src/generated) and import DTOs in my nest modules:

// src/my-module/dto/input/create-foo.input.ts
import { CreateFooInput as GeneratedCreateFooInput } from 'src/generated';

export CreateFooInput extends GeneratedCreateFooInput {
// add custom props here
}

This way you can always generate all the things - and only import what you need - and even make modifications.
Also see MappedTypes if you want to exclude generated props or merge classes