eslint-plugin-zod-to-openapi
Advanced tools
Comparing version 0.0.25 to 0.0.26
@@ -7,7 +7,8 @@ "use strict"; | ||
const type_1 = require("../../util/type"); | ||
const getExample = (properties) => { | ||
const getExample = (properties, key) => { | ||
for (const property of properties) { | ||
if (property.type === 'Property' && | ||
property.key.type === 'Identifier' && | ||
property.key.name === 'example') { | ||
((key === 'examples' && property.key.name === 'examples') || | ||
((!key || key === 'example') && property.key.name === 'example'))) { | ||
return property; | ||
@@ -23,6 +24,8 @@ } | ||
} | ||
const example = getExample(argument.properties); | ||
const example = getExample(argument.properties, context.options[0]); | ||
if (!example) { | ||
return context.report({ | ||
messageId: 'required', | ||
messageId: context.options[0] === 'examples' | ||
? 'require-examples' | ||
: 'require-example', | ||
node: openApiCallExpression, | ||
@@ -76,5 +79,10 @@ }); | ||
messages: { | ||
required: '.openapi() example is required for Zod primatives', | ||
'require-example': '.openapi() example is required for Zod primatives', | ||
'require-examples': '.openapi() examples is required for Zod primatives', | ||
}, | ||
schema: [], | ||
schema: [ | ||
{ | ||
enum: ['example', 'examples'], | ||
}, | ||
], | ||
docs: { | ||
@@ -85,4 +93,4 @@ description: 'Requires that all zod primatives have an example', | ||
}, | ||
defaultOptions: [], | ||
defaultOptions: ['example'], | ||
}); | ||
//# sourceMappingURL=rule.js.map |
@@ -1,5 +0,5 @@ | ||
import { TSESLint, TSESTree } from '@typescript-eslint/utils'; | ||
export declare const rule: TSESLint.RuleModule<"required", never[], { | ||
VariableDeclaration(node: TSESTree.VariableDeclaration): void; | ||
Property(node: TSESTree.Property): void; | ||
}>; | ||
import { TSESLint } from '@typescript-eslint/utils'; | ||
declare type Key = 'example' | 'examples'; | ||
declare type MessageIds = 'require-example' | 'require-examples'; | ||
export declare const rule: TSESLint.RuleModule<MessageIds, [Key], TSESLint.RuleListener>; | ||
export {}; |
{ | ||
"name": "eslint-plugin-zod-to-openapi", | ||
"version": "0.0.25", | ||
"version": "0.0.26", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Eslint rules for zod-to-openapi", |
@@ -139,3 +139,3 @@ # eslint-plugin-zod-to-openapi | ||
In order for your IDE to display descriptions in inferred types, it requires JsDoc comments. This rule autogenerates comments based on your `description` and `deprecated` fields and adds it to your ZodSchema. These appear in both the inferred and actual ZodSchema. This rule is autofixable. | ||
In order for your IDE to display descriptions in inferred types, it requires JsDoc comments. This rule autogenerates comments based on your `description` `example` or `examples` and `deprecated` fields and adds it to your ZodSchema. These appear in both the inferred and actual ZodSchema. This rule is autofixable. | ||
@@ -195,3 +195,3 @@ A simple example | ||
Requires that the `.openapi()` method contains an `example` key for Zod primatives. This makes our generated documentation much nicer. This includes: | ||
Requires that the `.openapi()` method contains an `example`, `examples` key for Zod primatives. This makes our generated documentation much nicer. This includes: | ||
@@ -202,2 +202,3 @@ - ZodBoolean | ||
- ZodRecord | ||
- ZodEnum | ||
@@ -212,2 +213,6 @@ ```ts | ||
By default this rule looks for the `example` key. If you wish to use the `examples` key which is required in Open API 3.1 pass the key `examples` in the options argument of your rule configuration. | ||
eg. `'zod-to-openapi/require-example': ['error', 'examples']` | ||
### prefer-openapi-last | ||
@@ -214,0 +219,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
70440
849
319