Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#188 - do not label default schemas as required #192

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading