Skip to content

Commit

Permalink
Merge pull request #192 from asteasolutions/fix/#188-default-should-b…
Browse files Browse the repository at this point in the history
…e-optional

#188 - do not label default schemas as required
  • Loading branch information
AGalabov authored Nov 16, 2023
2 parents 81d16d5 + 7b8b2bd commit eb58a06
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
6 changes: 2 additions & 4 deletions spec/modifiers/default.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('default', () => {
});
});

it('supports required defaults', () => {
it('supports required types with defaults', () => {
const schema = z
.object({
test: z.string().default('test'),
Expand All @@ -72,7 +72,6 @@ describe('default', () => {
default: 'test',
},
},
required: ['test'],
},
});
});
Expand Down Expand Up @@ -103,7 +102,7 @@ describe('default', () => {
);
});

it('supports required default schemas with refine', () => {
it('supports required types with default and refine', () => {
expectSchema(
[
z
Expand All @@ -124,7 +123,6 @@ describe('default', () => {
default: 42,
},
},
required: ['test'],
},
}
);
Expand Down
3 changes: 1 addition & 2 deletions spec/modifiers/refine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('refine', () => {
);
});

it('supports required refined schemas with default', () => {
it('supports required type schemas with refine and default', () => {
expectSchema(
[
z
Expand All @@ -128,7 +128,6 @@ describe('refine', () => {
default: 42,
},
},
required: ['test'],
},
}
);
Expand Down
4 changes: 0 additions & 4 deletions src/openapi-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1045,10 +1045,6 @@ export class OpenAPIGenerator {
return this.isOptionalSchema(zodSchema._def.schema);
}

if (isZodType(zodSchema, 'ZodDefault')) {
return this.isOptionalSchema(zodSchema._def.innerType);
}

return zodSchema.isOptional();
}

Expand Down

0 comments on commit eb58a06

Please sign in to comment.