eslint-plugin-zod-to-openapi
Advanced tools
Comparing version 0.0.23 to 0.0.24
@@ -32,3 +32,5 @@ "use strict"; | ||
const deprecatedValue = deprecated ? `${DEPRECATED_TAG} ` : ''; | ||
const exampleValue = example ? `\n${EXAMPLE_TAG} ${example}` : ''; | ||
const exampleValue = example | ||
? `\n${EXAMPLE_TAG} ${JSON.stringify(example)}` | ||
: ''; | ||
return `${deprecatedValue}${contents}${exampleValue}`; | ||
@@ -75,3 +77,3 @@ }; | ||
}; | ||
const getExampleValue = (properties, context) => { | ||
const getExampleValue = (properties) => { | ||
const examples = getPropertyNode(properties, 'examples'); | ||
@@ -84,10 +86,14 @@ const example = getPropertyNode(properties, 'example'); | ||
} | ||
const element = examples.value.elements?.[0]; | ||
if (!element || element.type !== 'Literal') { | ||
return; | ||
} | ||
// Because grabbing a value is difficult if it is not a literal | ||
const arrayText = context.getSourceCode().getText(examples.value); | ||
// Remove square brackets | ||
return arrayText.slice(1, -1); | ||
return element.value; | ||
} | ||
if (example) { | ||
const text = context.getSourceCode().getText(example.value); | ||
return text; | ||
if (example.value.type !== 'Literal') { | ||
return; | ||
} | ||
return example.value.value; | ||
} | ||
@@ -134,3 +140,3 @@ return undefined; | ||
const deprecatedValue = Boolean(getLiteralValue(deprecatedNode)); | ||
const exampleValue = getExampleValue(argument.properties, context); | ||
const exampleValue = getExampleValue(argument.properties); | ||
return createCommentValue(descriptionValue, deprecatedValue, exampleValue); | ||
@@ -198,3 +204,3 @@ }; | ||
} | ||
const commentValue = commentRegex.exec(comment.value)?.[1]; | ||
const commentValue = getCommentValue(comment.value); | ||
if (!commentValue || expectedCommentValue !== commentValue) { | ||
@@ -201,0 +207,0 @@ return context.report({ |
{ | ||
"name": "eslint-plugin-zod-to-openapi", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Eslint rules for zod-to-openapi", |
Sorry, the diff of this file is not supported yet
69275
843