Skip to content

Commit

Permalink
Fix type to be a string value
Browse files Browse the repository at this point in the history
  • Loading branch information
erkstruwe committed Jan 19, 2024
1 parent 19be9b7 commit 5a6611b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/zod-nestjs/src/lib/create-zod-dto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('zod-nesjs create-zod-dto', () => {
const generatedSchema = metadataFactory();

expect(generatedSchema).toBeDefined();
expect(generatedSchema?.name.type).toEqual(['string']);
expect(generatedSchema?.name.type).toEqual('string');
expect(generatedSchema?.name.nullable).toBe(true);
});

Expand Down
12 changes: 5 additions & 7 deletions packages/zod-nestjs/src/lib/create-zod-dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,12 @@ export const createZodDto = <T extends OpenApiZodAny>(

// @nestjs/swagger expects OpenAPI 3.0-style schema objects
// Nullable
if (Array.isArray(convertedSchemaObject.type)) {
const nullTypeIndex = convertedSchemaObject.type.findIndex(
(type) => type === 'null'
if (Array.isArray(schemaObject.type)) {
convertedSchemaObject.type = schemaObject.type.find(
(t) => t !== 'null'
);
if (nullTypeIndex > -1) {
convertedSchemaObject.type.splice(nullTypeIndex, 1);
convertedSchemaObject.nullable = true;
}
convertedSchemaObject.nullable =
schemaObject.type.includes('null') || undefined;
}
// Exclusive minimum and maximum
const { exclusiveMinimum, exclusiveMaximum } = schemaObject;
Expand Down

0 comments on commit 5a6611b

Please sign in to comment.