Skip to content

Commit

Permalink
fix(plugin): unwrap string literals when used as default vals #2498
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jun 28, 2023
1 parent 81bed53 commit d97d01b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/plugin/visitors/model-class.visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,8 @@ export class ModelClassVisitor extends AbstractFileVisitor {
if (!primitiveTypeName) {
return undefined;
}
return createPrimitiveLiteral(factory, node.getText(), primitiveTypeName);
const text = (node as any).text ?? node.getText();
return createPrimitiveLiteral(factory, text, primitiveTypeName);
}

private getInitializerPrimitiveTypeName(node: ts.Node) {
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/fixtures/project/cats/dto/create-cat.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class CreateCatDto {
age: number = 14;

@ApiProperty({ name: '_breed', type: String })
breed: string;
breed: string = 'Persian';

@ApiProperty({
format: 'uri',
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/fixtures/serialized-meta.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default async () => {
default: 14,
minimum: 1
},
breed: { required: true, type: () => String },
breed: { required: true, type: () => String, default: 'Persian' },
tags: { required: false, type: () => [String] },
createdAt: { required: true, type: () => Date },
urls: { required: false, type: () => [String] },
Expand Down

0 comments on commit d97d01b

Please sign in to comment.