Skip to content
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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

pond918
Copy link

@pond918 pond918 commented May 14, 2023

please check changelog:

  • @DtoCreateHidden, @DtoUpdateHidden, @DtoCreateApiResponse,@DtoUpdateApiResponse, @DtoPlainApiResponse, @CustomValidator
  • enhanced @matches to allow brackets in regex;
  • output NestJs pluralized model folders

@Brakebein
Copy link
Owner

Thanks for this extensive merge request! I may need some time to look through and test it.

Copy link
Owner

@Brakebein Brakebein left a 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.

Comment on lines +64 to +65
const transformFileNameCases = (str: string) =>
pluralize(transformFileNameCase(str));
Copy link
Owner

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')}
Copy link
Owner

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?

Copy link
Author

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",
Copy link
Owner

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:
Copy link
Owner

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.

Comment on lines +102 to +103
- `@DtoCreateApiResponse` - generate `@ApiResponseProperty()` and ignore all other annotations in `CreateDTO`
- same for `DtoUpdateApiResponse` and `DtoPlainApiResponse`
Copy link
Owner

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?

Copy link
Author

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.

Comment on lines +35 to +41
export function isApiResp(field: ParsedField, dtoType?: string) {
if (dtoType) {
type ObjectKey = keyof typeof field;
const apiResp = (dtoType + 'ApiResp') as ObjectKey;
return field[apiResp];
}
}
Copy link
Owner

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.

@coryoso
Copy link

coryoso commented Oct 9, 2023

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants