Skip to content

Commit

Permalink
Merge pull request #2797 from TheSalarKhan/master
Browse files Browse the repository at this point in the history
fix: support type `UUID` from node's `crypto` package
  • Loading branch information
kamilmysliwiec authored Feb 7, 2024
2 parents b1fb761 + bdc130a commit 1d86dfd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/plugin/utils/plugin-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ export function getTypeReferenceAsString(
if (type.aliasSymbol) {
return { typeName: 'Object', arrayDepth };
}
if (typeChecker.getApparentType(type).getSymbol().getEscapedName() === 'String') {
return { typeName: String.name, arrayDepth };
}
return { typeName: undefined };
} catch {
return { typeName: undefined };
Expand Down
9 changes: 7 additions & 2 deletions test/plugin/fixtures/create-cat.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const createCatDtoText = `
import { UUID } from 'crypto';
import { IsInt, IsString, IsPositive, IsNegative, Length, Matches, IsIn } from 'class-validator';
enum Status {
Expand Down Expand Up @@ -50,14 +51,18 @@ export class CreateCatDto {
nodes: Node[];
optionalBoolean?: boolean;
date: Date;
twoDimensionPrimitives: string[][];
twoDimensionNodes: OtherNode[][];
@ApiHideProperty()
hidden: number;
static staticProperty: string;
cryptoUUIDProperty: UUID;
arrayOfUUIDs: UUID[];
}
`;

Expand Down Expand Up @@ -85,7 +90,7 @@ export class CreateCatDto {
this.status = Status.ENABLED;
}
static _OPENAPI_METADATA_FACTORY() {
return { isIn: { required: true, type: () => String, enum: ['a', 'b'] }, pattern: { required: true, type: () => String, pattern: "/^[+]?abc$/" }, name: { required: true, type: () => String }, age: { required: true, type: () => Number, default: 3, minimum: 0, maximum: 10 }, positive: { required: true, type: () => Number, default: 5, minimum: 1 }, negative: { required: true, type: () => Number, default: -1, maximum: -1 }, lengthMin: { required: true, type: () => String, minLength: 2 }, lengthMinMax: { required: true, type: () => String, minLength: 3, maxLength: 5 }, tags: { required: true, type: () => [String] }, status: { required: true, default: Status.ENABLED, enum: Status }, status2: { required: false, enum: Status }, statusArr: { required: false, enum: Status, isArray: true }, oneValueEnum: { required: false, enum: OneValueEnum }, oneValueEnumArr: { required: false, enum: OneValueEnum }, breed: { required: false, type: () => String, title: "this is breed im comment" }, nodes: { required: true, type: () => [Object] }, optionalBoolean: { required: false, type: () => Boolean }, date: { required: true, type: () => Date }, twoDimensionPrimitives: { required: true, type: () => [[String]] }, twoDimensionNodes: { required: true, type: () => [[OtherNode]] } };
return { isIn: { required: true, type: () => String, enum: ['a', 'b'] }, pattern: { required: true, type: () => String, pattern: "/^[+]?abc$/" }, name: { required: true, type: () => String }, age: { required: true, type: () => Number, default: 3, minimum: 0, maximum: 10 }, positive: { required: true, type: () => Number, default: 5, minimum: 1 }, negative: { required: true, type: () => Number, default: -1, maximum: -1 }, lengthMin: { required: true, type: () => String, minLength: 2 }, lengthMinMax: { required: true, type: () => String, minLength: 3, maxLength: 5 }, tags: { required: true, type: () => [String] }, status: { required: true, default: Status.ENABLED, enum: Status }, status2: { required: false, enum: Status }, statusArr: { required: false, enum: Status, isArray: true }, oneValueEnum: { required: false, enum: OneValueEnum }, oneValueEnumArr: { required: false, enum: OneValueEnum }, breed: { required: false, type: () => String, title: "this is breed im comment" }, nodes: { required: true, type: () => [Object] }, optionalBoolean: { required: false, type: () => Boolean }, date: { required: true, type: () => Date }, twoDimensionPrimitives: { required: true, type: () => [[String]] }, twoDimensionNodes: { required: true, type: () => [[OtherNode]] }, cryptoUUIDProperty: { required: true, type: () => String }, arrayOfUUIDs: { required: true, type: () => [String] } };
}
}
__decorate([
Expand Down

0 comments on commit 1d86dfd

Please sign in to comment.