-
Notifications
You must be signed in to change notification settings - Fork 28
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
added some annotations and enhancements. #19
base: main
Are you sure you want to change the base?
Conversation
Thanks for this extensive merge request! I may need some time to look through and test it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for all those update. Though, I have some change requests. And I question the need of @ApiResponseProperty()
. Maybe you can express your thoughts about it.
const transformFileNameCases = (str: string) => | ||
pluralize(transformFileNameCase(str)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be optional (default: false), otherwise it would be a breaking change. Could be an option like pluralizeModelFolders
.
@@ -14,6 +16,8 @@ export const generateCreateDto = ({ | |||
exportRelationModifierClasses, | |||
templateHelpers: t, | |||
}: GenerateCreateDtoParam) => ` | |||
// @@generated by ${name}@${version}. ${new Date().toLocaleDateString('sv-SE')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't include the date. In some projects, the generated dtos are included in the Git. So, if you run generate and a new date is printed, you'll need to commit all files again, even those where actually nothing has changed.
And why the @@
prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll drop the date. in my case, the generated files are git ignored.
@@ -1,7 +1,7 @@ | |||
{ | |||
"name": "@brakebein/prisma-generator-nestjs-dto", | |||
"name": "@pond918/prisma-generator-nestjs-dto", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If merged, it should be changed back to the @brakebin/prisma-generator-nestjs-dto
.
@@ -16,7 +16,7 @@ Generates `ConnectDTO`, `CreateDTO`, `UpdateDTO`, `DTO`, and `Entity` classes fo | |||
|
|||
These 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). | |||
|
|||
This is a fork of [@vegardit/prisma-generator-nestjs-dto](https://github.com/vegardit/prisma-generator-nestjs-dto) and adds multiple features: | |||
This is a fork of [@brakebein/prisma-generator-nestjs-dto](https://github.com/Brakebein/prisma-generator-nestjs-dto) and adds multiple features: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be changed back to the original package name.
- `@DtoCreateApiResponse` - generate `@ApiResponseProperty()` and ignore all other annotations in `CreateDTO` | ||
- same for `DtoUpdateApiResponse` and `DtoPlainApiResponse` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get the point of @ApiResponseProperty()
. Why should it be used over @ApiProperty()
? ApiResponseProperty is the same just with fewer properties and readOnly: true
(api-property.decorator.ts#L75-L85). For me, it does not make sense to use it in the CreateDto and UpdateDto (which are basically for request bodies) if the field is read-only. And in the plain Dto (the response body), there is no need to mark it as read-only. If you want to omit the field in Create or Update, there is the @DtoReadOnly
annotation (or your new @DtoCreateHidden
and @DtoCreateHidden
for more fine control).
Or did I misunderstand something completely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this annotation do 2 things: makes prop readonly; remove all validation annotations(usecase: nestjs ValidationPipe.whitelist)
since I won't edit the generated files, it's convenient to reuse the dtos as response. it's ok to remove this annotation.
export function isApiResp(field: ParsedField, dtoType?: string) { | ||
if (dtoType) { | ||
type ObjectKey = keyof typeof field; | ||
const apiResp = (dtoType + 'ApiResp') as ObjectKey; | ||
return field[apiResp]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be defined in types.ts
, but in helpers.ts
or api-decorator.ts
.
Is there an update on this? The changes are very nice and would help us. Can also help improving some of the asked-for changes :) |
please check changelog: