Skip to content

Commit 03a058f

Browse files
committedApr 11, 2023
fix(zod): avoid deplicated consts declaration
1 parent 673bb55 commit 03a058f

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed
 

‎packages/zod/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
"lint": "eslint src/**/*.ts"
1414
},
1515
"dependencies": {
16-
"@orval/core": "6.13.1"
16+
"@orval/core": "6.13.1",
17+
"lodash.uniq": "^4.5.0"
18+
},
19+
"devDependencies": {
20+
"@types/lodash.uniq": "^4.5.7"
1721
}
1822
}

‎packages/zod/src/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
isObject,
2121
isBoolean,
2222
} from '@orval/core';
23-
import SwaggerParser from '@apidevtools/swagger-parser';
23+
import uniq from 'lodash.uniq';
2424

2525
const ZOD_DEPENDENCIES: GeneratorDependency[] = [
2626
{
@@ -204,7 +204,7 @@ const generateZodValidationSchemaDefinition = (
204204
functions.push(['optional', undefined]);
205205
}
206206

207-
return { functions, consts };
207+
return { functions, consts: uniq(consts) };
208208
};
209209

210210
const parseZodValidationSchemaDefinition = (
@@ -356,7 +356,7 @@ const generateZodRoute = (
356356
!!resolvedResponseJsonSchema?.required?.find(
357357
(requiredKey: string) => requiredKey === key,
358358
),
359-
camel(`${operationName}-${key}`),
359+
camel(`${operationName}-response-${key}`),
360360
),
361361
};
362362
})
@@ -389,7 +389,7 @@ const generateZodRoute = (
389389
!!resolvedRequestBodyJsonSchema?.required?.find(
390390
(requiredKey: string) => requiredKey === key,
391391
),
392-
camel(`${operationName}-${key}`),
392+
camel(`${operationName}-body-${key}`),
393393
),
394394
};
395395
})
@@ -408,7 +408,7 @@ const generateZodRoute = (
408408
const definition = generateZodValidationSchemaDefinition(
409409
schema,
410410
parameter.required,
411-
camel(`${operationName}-${parameter.name}`),
411+
camel(`${operationName}-${parameter.in}-${parameter.name}`),
412412
);
413413

414414
if (parameter.in === 'header') {

‎yarn.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@
10001000

10011001
"@types/lodash.uniq@^4.5.7":
10021002
version "4.5.7"
1003-
resolved "https://registry.npmjs.org/@types/lodash.uniq/-/lodash.uniq-4.5.7.tgz"
1003+
resolved "https://registry.yarnpkg.com/@types/lodash.uniq/-/lodash.uniq-4.5.7.tgz#0773960ec0148b29e6a54821a65b878a0ebb5c1a"
10041004
integrity sha512-qg7DeAbdZMi6DGvCxThlJycykLLhETrJrQZ6F2KaZ+o0sNK1qRHz46lgNA+nHHjwrmA2a91DyiZTp3ey3m1rEw==
10051005
dependencies:
10061006
"@types/lodash" "*"
@@ -4280,7 +4280,7 @@ lodash.topath@^4.5.2:
42804280

42814281
lodash.uniq@^4.5.0:
42824282
version "4.5.0"
4283-
resolved "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz"
4283+
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
42844284
integrity sha512-xfBaXQd9ryd9dlSDvnvI0lvxfLJlYAZzXomUYzLKtUeOQvOP5piqAWuGtrhWeqaXK9hhoM/iyJc5AV+XfsX3HQ==
42854285

42864286
lodash.uniqby@^4.7.0:

0 commit comments

Comments
 (0)
Please sign in to comment.