Skip to content

Commit

Permalink
Merge pull request #216 from danielsharvey/bugfix/nestjs-array-handling
Browse files Browse the repository at this point in the history
fix: Improve array handling not fully functional (misses item type) #215
  • Loading branch information
Brian-McBride authored Jan 20, 2025
2 parents 8d4fa35 + deecf7b commit 913d1ae
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/zod-nestjs/src/lib/create-zod-dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type ZodDtoStatic<T extends CompatibleZodType = CompatibleZodType> = {
// Used for transforming the SchemaObject in _OPENAPI_METADATA_FACTORY
type SchemaObjectForMetadataFactory = Omit<SchemaObject30, 'required'> & {
required: boolean | string[];
isArray?: boolean;
};

export const createZodDto = <T extends OpenApiZodAny>(
Expand Down Expand Up @@ -148,6 +149,10 @@ export const createZodDto = <T extends OpenApiZodAny>(
convertedSchemaObject.type = 'string'; // There ist no explicit null value in OpenAPI 3.0
convertedSchemaObject.nullable = true;
}
// Array handling (NestJS references 'isArray' boolean)
if (convertedSchemaObject.type === 'array') {
convertedSchemaObject.isArray = true;
}
// Exclusive minimum and maximum
const { exclusiveMinimum, exclusiveMaximum } = schemaObject;
if (exclusiveMinimum !== undefined) {
Expand Down

0 comments on commit 913d1ae

Please sign in to comment.