Skip to content

Commit 7da8eb4

Browse files
authored
Fix optional (#13)
1 parent 9c7f471 commit 7da8eb4

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/rules/require-openapi/rule.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ruleTester.run(ruleName, rule, {
2424
test('reference'),
2525
test('object-shape-reference'),
2626
test('object-property-reference-optional'),
27+
test('object-property-shape-optional'),
2728
],
2829
invalid: [
2930
{

src/rules/require-openapi/rule.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export const rule: TSESLint.RuleModule<any, any> = createRule({
5555
type.name.startsWith('ZodOptional') &&
5656
node.value.type === 'CallExpression' &&
5757
node.value.callee.type === 'MemberExpression' &&
58-
node.value.callee.object.type === 'Identifier'
58+
(node.value.callee.object.type === 'Identifier' ||
59+
node.value.callee.object.type === 'MemberExpression')
5960
) {
6061
return;
6162
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { z } from 'zod';
2+
import { extendZodWithOpenApi } from 'zod-openapi';
3+
4+
extendZodWithOpenApi(z);
5+
6+
export const a = z
7+
.object({
8+
a: z.string().openapi({ description: 'a prop' }),
9+
})
10+
.openapi({ description: 'object' });
11+
12+
export const ZodObject = z
13+
.object({
14+
prop: a.shape.a.optional(),
15+
})
16+
.openapi({ description: 'object description' });

0 commit comments

Comments
 (0)