Skip to content

Commit

Permalink
fix(zod): avoid deplicated consts declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
anymaniax committed Apr 11, 2023
1 parent 673bb55 commit 03a058f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion packages/zod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"lint": "eslint src/**/*.ts"
},
"dependencies": {
"@orval/core": "6.13.1"
"@orval/core": "6.13.1",
"lodash.uniq": "^4.5.0"
},
"devDependencies": {
"@types/lodash.uniq": "^4.5.7"
}
}
10 changes: 5 additions & 5 deletions packages/zod/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
isObject,
isBoolean,
} from '@orval/core';
import SwaggerParser from '@apidevtools/swagger-parser';
import uniq from 'lodash.uniq';

const ZOD_DEPENDENCIES: GeneratorDependency[] = [
{
Expand Down Expand Up @@ -204,7 +204,7 @@ const generateZodValidationSchemaDefinition = (
functions.push(['optional', undefined]);
}

return { functions, consts };
return { functions, consts: uniq(consts) };
};

const parseZodValidationSchemaDefinition = (
Expand Down Expand Up @@ -356,7 +356,7 @@ const generateZodRoute = (
!!resolvedResponseJsonSchema?.required?.find(
(requiredKey: string) => requiredKey === key,
),
camel(`${operationName}-${key}`),
camel(`${operationName}-response-${key}`),
),
};
})
Expand Down Expand Up @@ -389,7 +389,7 @@ const generateZodRoute = (
!!resolvedRequestBodyJsonSchema?.required?.find(
(requiredKey: string) => requiredKey === key,
),
camel(`${operationName}-${key}`),
camel(`${operationName}-body-${key}`),
),
};
})
Expand All @@ -408,7 +408,7 @@ const generateZodRoute = (
const definition = generateZodValidationSchemaDefinition(
schema,
parameter.required,
camel(`${operationName}-${parameter.name}`),
camel(`${operationName}-${parameter.in}-${parameter.name}`),
);

if (parameter.in === 'header') {
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@

"@types/lodash.uniq@^4.5.7":
version "4.5.7"
resolved "https://registry.npmjs.org/@types/lodash.uniq/-/lodash.uniq-4.5.7.tgz"
resolved "https://registry.yarnpkg.com/@types/lodash.uniq/-/lodash.uniq-4.5.7.tgz#0773960ec0148b29e6a54821a65b878a0ebb5c1a"
integrity sha512-qg7DeAbdZMi6DGvCxThlJycykLLhETrJrQZ6F2KaZ+o0sNK1qRHz46lgNA+nHHjwrmA2a91DyiZTp3ey3m1rEw==
dependencies:
"@types/lodash" "*"
Expand Down Expand Up @@ -4280,7 +4280,7 @@ lodash.topath@^4.5.2:

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

lodash.uniqby@^4.7.0:
Expand Down

0 comments on commit 03a058f

Please sign in to comment.