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

DtoCastType question #62

Open
fmay opened this issue Dec 5, 2024 · 2 comments
Open

DtoCastType question #62

fmay opened this issue Dec 5, 2024 · 2 comments

Comments

@fmay
Copy link

fmay commented Dec 5, 2024

I have the following Prisma model and type generation question :

model Connection {
  uuid        String    @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  name        String
  ///@DtoCastType(ConnectionType, @/connections/dtos/connection-type)
  type        String
  description String
  value       String
  inFlows     Flow[]    @relation("ConnectionFlows")
  createdAt   DateTime  @default(now())
  updatedAt   DateTime? @updatedAt
  isDeleted   Boolean?  @default(false)
}

The ConnectionType looks like this

export enum ConnectionTypeEnum {
  DATABASE = 'DATABASE',
}

export class ConnectionType {
  @ApiProperty({
    description: 'Connection Property',
    enum: ConnectionTypeEnum, // Use `enum` property for enums
    enumName: 'ConnectionTypeEnum',
  })
  @IsEnum(ConnectionTypeEnum)
  type: ConnectionTypeEnum
}

The generated connection.entity.ts looks like this for the type field

@ApiProperty({
  type: 'string',
})
type: ConnectionType ;

whereas I would like the ConnectionType to appear in there, which it currently doesn't.

Thanks!

@Brakebein
Copy link
Owner

Please check out version 1.24.0-beta6. There are 2 new decorators to override the type of the class property (@DtoOverrideType) and the ApiProperty type (@DtoOverrideApiPropertyType) separately. Syntax remains the same. See discussion in isssue #54.

@fmay
Copy link
Author

fmay commented Dec 6, 2024

Thanks for the quick reply! This does indeed add

@ApiProperty({
  type: () => ConnectionTypeEnum,
})
type: ConnectionTypeEnum ;

However, i am now getting circular dependencies from Swagger. I guess this is not related to you and I will have to sort it out later.

Thanks again

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

No branches or pull requests

2 participants