Skip to content

Commit 150d587

Browse files
authored
Migrate to v4 (#247)
1 parent 6ff6b60 commit 150d587

File tree

113 files changed

+513
-598
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+513
-598
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Add the following configuration to your `.eslintrc` file
3030
```js
3131
{
3232
"rules": {
33-
"zod-openapi/require-openapi": "error"
33+
"zod-openapi/require-meta": "error"
3434
"zod-openapi/require-comment": "error",
3535
"zod-openapi/prefer-zod-default": "warn",
3636
}
@@ -44,7 +44,7 @@ You may wish to use overrides as this plugin by default will assume that all Zod
4444
{
4545
"files": ["src/api-types/*.ts"],
4646
"rules": {
47-
"zod-openapi/require-openapi": "error"
47+
"zod-openapi/require-meta": "error"
4848
}
4949
}
5050
]
@@ -54,13 +54,13 @@ You may wish to use overrides as this plugin by default will assume that all Zod
5454

5555
🔧 This rule is automatically fixable by the [--fix CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
5656

57-
| Name | Description | 🔧 |
58-
| ---------------------------------------------------------- | ----------------------------------------------------------------------------- | :-: |
59-
| [require-openapi](./docs/rules/require-openapi.md) | Requires that all ZodTypes have an `.openapi()` method. | |
60-
| [require-comment](./docs/rules/require-comment.md) | Requires that all ZodTypes have a `description` and matching JSDoc comment. ||
61-
| [require-example](./docs/rules/require-example.md) | Requires that all ZodTypes have an `example` or `examples` field. | |
62-
| [prefer-openapi-last](./docs/rules/prefer-openapi-last.md) | Prefers that the `.openapi()` method be the last method in the ZodType chain. | |
63-
| [prefer-zod-default](./docs/rules/prefer-zod-default.md) | Provides an error when `default` in `.openapi()` is used | |
57+
| Name | Description | 🔧 |
58+
| -------------------------------------------------------- | --------------------------------------------------------------------------- | :-: |
59+
| [require-meta](./docs/rules/require-meta.md) | Requires that all ZodTypes have an `.meta()` method. | |
60+
| [require-comment](./docs/rules/require-comment.md) | Requires that all ZodTypes have a `description` and matching JSDoc comment. ||
61+
| [require-example](./docs/rules/require-example.md) | Requires that all ZodTypes have an `example` or `examples` field. | |
62+
| [prefer-meta-last](./docs/rules/prefer-meta-last.md) | Prefers that the `.meta()` method be the last method in the ZodType chain. | |
63+
| [prefer-zod-default](./docs/rules/prefer-zod-default.md) | Provides an error when `default` in `.meta()` is used | |
6464

6565
## Development
6666

docs/rules/prefer-meta-last.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Prefers that the `.meta()` method be the last method (`prefer-meta-last`)
2+
3+
Prefers that the `.meta()` method be the last method in a Zod Schema chain. This is done mainly out of consistency but also because there are some methods that can override the `.meta()` method. eg. pick, omit
4+
5+
A simple example
6+
7+
```ts
8+
const NameSchema = z.string().meta({ example: 'Fred' }).length(5); // ❌ error
9+
10+
const NameSchema = z.string().length(5).meta({ example: 'Fred' }); // ✅ correct
11+
```

docs/rules/prefer-openapi-last.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

docs/rules/prefer-zod-default.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Prefer `.default()` over `default` in `.openapi()` (`prefer-zod-default`)
1+
# Prefer `.default()` over `default` in `.meta()` (`prefer-zod-default`)
22

3-
Provides an error when `default` is used in `.openapi()` option. ZodDefault `.default()` should be used instead.
3+
Provides an error when `default` is used in `.meta()` option. ZodDefault `.default()` should be used instead.
44

55
A simple example
66

77
```ts
8-
const NameSchema = z.string().openapi({ example: 'Fred', default: 'Fred' }); // ❌ error
9-
const NameSchema = z.string().default('Fred').openapi({ example: 'Fred' }); // ✅ correct
8+
const NameSchema = z.string().meta({ example: 'Fred', default: 'Fred' }); // ❌ error
9+
const NameSchema = z.string().default('Fred').meta({ example: 'Fred' }); // ✅ correct
1010
```

docs/rules/require-comment.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ In order for your IDE to display descriptions in inferred types, it requires JSD
99
A simple example
1010

1111
```ts
12-
const NameSchema = z.string().openapi({ example: 'Fred' }); // ❌ error (no description or comment)
12+
const NameSchema = z.string().meta({ example: 'Fred' }); // ❌ error (no description or comment)
1313

1414
/**
1515
* A user's name
1616
**/
1717
const NameSchema = z
1818
.string()
19-
.openapi({ description: "A user's name", example: 'Fred' }); // ✅ correct
19+
.meta({ description: "A user's name", example: 'Fred' }); // ✅ correct
2020
```
2121

2222
This rule is also able to infer JSDoc comments from other variables and automatically copies the comments across where otherwise you would gain no type comments.
@@ -29,7 +29,7 @@ A more complex example:
2929
**/
3030
const NameSchema = z
3131
.string()
32-
.openapi({ description: "A user's name", example: 'Fred', deprecated: true }); // ✅ correct
32+
.meta({ description: "A user's name", example: 'Fred', deprecated: true }); // ✅ correct
3333

3434
/**
3535
* Person
@@ -47,9 +47,9 @@ const PersonSchema = z
4747
.number()
4848
.positive()
4949
.int()
50-
.openapi({ description: "A user's age", example: 12 }),
50+
.meta({ description: "A user's age", example: 12 }),
5151
})
52-
.openapi({ description: 'Person' });
52+
.meta({ description: 'Person' });
5353

5454
/**
5555
* Person

docs/rules/require-example.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Requires an `example` on Zod Types (`require-example`)
22

3-
Requires that the `.openapi()` method contains an `example`, `examples` key for Zod primatives. This makes our generated documentation much nicer. This includes:
3+
Requires that the `.meta()` method contains an `example`, `examples` key for Zod primatives. This makes our generated documentation much nicer. This includes:
44

55
- ZodBoolean
66
- ZodNumber
@@ -13,7 +13,7 @@ const UserIdSchema = z.string().uuid(); // ❌ error (no example)
1313
const UserIdSchema = z
1414
.string()
1515
.uuid()
16-
.openapi({ example: '48948579-f117-47e4-bc05-12f28e7fdccd' }); // ✅ correct
16+
.meta({ example: '48948579-f117-47e4-bc05-12f28e7fdccd' }); // ✅ correct
1717
```
1818

1919
## Options

docs/rules/require-openapi.md renamed to docs/rules/require-meta.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
# Require `.openapi()` on ZodTypes (`require-openapi`)
1+
# Require `.meta()` on ZodTypes (`require-meta`)
22

3-
Requires that all Zod schemas have an `.openapi()` method. In order for your generated documentation to appear nice, you need to provide metadata for your types.
3+
Requires that all Zod schemas have an `.meta()` method. In order for your generated documentation to appear nice, you need to provide metadata for your types.
44

55
A simple example
66

77
```ts
88
const NameSchema = z.string(); // ❌ error
9-
const NameSchema = z.string().openapi({ description: "A user's name" }); // ✅ correct
9+
const NameSchema = z.string().meta({ description: "A user's name" }); // ✅ correct
1010
```
1111

12-
This rule is best used in conjunction with the require-comment rule. To avoid costly traversal we use the Typescript compiler to check the type and also consider any referenced variable which has a JSDoc comment as having an `.openapi()` field.
12+
This rule is best used in conjunction with the require-comment rule. To avoid costly traversal we use the Typescript compiler to check the type and also consider any referenced variable which has a JSDoc comment as having an `.meta()` field.
1313

1414
A complex example
1515

1616
```ts
1717
/**
1818
* A user's name
1919
**/
20-
const NameSchema = z.string().openapi({ description: "A user's name" });
20+
const NameSchema = z.string().meta({ description: "A user's name" });
2121

2222
const IdSchema = z.string().uuid();
2323

@@ -29,9 +29,9 @@ const OtherSchema = z
2929
/**
3030
* A user's age
3131
**/
32-
age: z.number().openapi({ description: "A user's age" }),
32+
age: z.number().meta({ description: "A user's age" }),
3333
})
34-
.openapi({ description: 'Other Schema' });
34+
.meta({ description: 'Other Schema' });
3535

3636
const PersonSchema = z
3737
.object({
@@ -45,5 +45,5 @@ const PersonSchema = z
4545
**/
4646
age: OtherSchema.shape.age, // ✅ correct
4747
})
48-
.openapi({ description: 'Person' });
48+
.meta({ description: 'Person' });
4949
```

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"@typescript-eslint/rule-tester": "^8.7.0",
3939
"skuba": "9.1.0",
4040
"typescript": "5.7.2",
41-
"zod": "3.24.1",
42-
"zod-openapi": "4.2.2"
41+
"zod": "3.25.67",
42+
"zod-openapi": "5.0.0-beta.3"
4343
},
4444
"packageManager": "pnpm@8.15.1",
4545
"engines": {

pnpm-lock.yaml

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rules/prefer-openapi-last/rule.test.ts renamed to src/rules/prefer-meta-last/rule.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { RuleTester } from '@typescript-eslint/rule-tester';
22

33
import { setupHelpers } from '../../tests/helper';
44

5-
const ruleName = 'prefer-openapi-last';
5+
const ruleName = 'prefer-meta-last';
66

77
const { test } = setupHelpers(ruleName);
88

0 commit comments

Comments
 (0)