Cannot read properties of undefined (reading 'ref')
hosein74 opened this issue · comments
when I want use tag-file in --group-strategy or 'method-file' in command like this :
command : yarn openapi-zod-client "api.json" -o "src/api" --group-strategy "tag-file" -a
this error occure:
$ C:\Users\me\myproject\node_modules.bin\openapi-zod-client api.json -o src/api --group-strategy tag-file -a
Retrieving OpenAPI document from api.json
C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:2266
(_depsGraphs$deepDepen5 = depsGraphs.deepDependencyGraph[result.resolver.resolveSchemaName(schemaName).ref]) === null || _depsGraphs$deepDepen5 === void 0 ? void 0 : _depsGraphs$deepDepen5.forEach(function (transitiveRef) {
^
TypeError: Cannot read properties of undefined (reading 'ref')
at C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:2266:113
at Array.forEach ()
at C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:2260:42 at Array.forEach ()
at getZodClientTemplateContext (C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:2214:20)
at _callee$ (C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:2345:20)
at tryCatch (C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev. at Generator. (C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:158:22)
at Generator.next (C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:102:21)
at asyncGeneratorStep (C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:345:24)
Node.js v18.16.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
PS C:\Usersme\myproject> yarn openapi-zod-client "api.json" -o "src/api" --group-strategy "tag-file" -a
yarn run v1.22.19
$ C:\Users\me\myproject\node_modules.bin\openapi-zod-client api.json -o src/api --group-strategy tag-file -a
Retrieving OpenAPI document from api.json
C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:2266
(_depsGraphs$deepDepen5 = depsGraphs.deepDependencyGraph[result.resolver.resolveSchemaName(schemaName).ref]) === null || _depsGraphs$deepDepen5 === void 0 ? void 0 : _depsGraphs$deepDepen5.forEach(function (transitiveRef) {
^
TypeError: Cannot read properties of undefined (reading 'ref')
at C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:2266:113
at Array.forEach ()
at C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:2260:42 at Array.forEach ()
at getZodClientTemplateContext (C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:2214:20)
at _callee$ (C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:2345:20)
at tryCatch (C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:77:17)
at Generator. (C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:158:22)
at Generator.next (C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:102:21)
at asyncGeneratorStep (C:\Users\me\myproject\node_modules\openapi-zod-client\dist\generateZodClientFromOpenAPI-0daa4355.cjs.dev.js:345:24)
Node.js v18.16.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
can you provide a minimal reproduction here ? https://openapi-zod-client.vercel.app/
you can hit ctrl+s to save & share the link
or just paste your relevant json/yaml part here
could you paste the openapi JSON ?
and if that error doesnt happen on the playground, maybe you need to upgrade the library version ?
I have same error on my schema, it's complex and private company source. It happens only for file strategies. Other works well.
@astahmer Here is a minimal swagger.json
I was able to reproduce the problem with:
{
"openapi" : "3.0.1",
"info" : {
"title" : "SberCity CRM API",
"version" : "v1"
},
"servers" : [ {
"url" : "http://localhost:37629",
"description" : "Generated server url"
} ],
"paths" : {
"/api/v1/settlement" : {
"post" : {
"tags" : [ "settlement-controller" ],
"operationId" : "create_7",
"parameters" : [ {
"name" : "createDto",
"in" : "query",
"required" : true,
"schema" : {
"$ref" : "#/components/schemas/SettlementCreateRequest"
}
} ],
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/SettlementResponse"
}
}
}
}
},
"security" : [ {
"bearerAuth" : [ ]
} ]
}
}
},
"components" : {
"schemas" : {
"SettlementResponse" : {
"required": [ "id", "name" ],
"type": "object",
"properties": {
"id": {
"type": "integer",
"description": "Идентификатор",
"format": "int32"
},
"name": {
"type": "string",
"description": "Название заселения"
}
}
},
"SettlementCreateRequest" : {
"required" : [ "dealId", "responsibleUserId" ],
"type" : "object",
"properties" : {
"dealId" : {
"type" : "integer",
"format" : "int32"
},
"responsibleUserId" : {
"type" : "integer",
"format" : "int32"
}
}
}
},
"securitySchemes" : {
"bearerAuth" : {
"type" : "http",
"scheme" : "bearer",
"bearerFormat" : "JWT"
}
}
}
}
I also tried to dereference JSON schema but result is still the same (schema is valid but I get the error in the topic):
const openApiSchemaPath = path.resolve(rootPath, 'swagger-test.json');
const prettierConfig = await resolveConfig(rootPath);
const schema = await SwaggerParser.bundle(openApiSchemaPath);
const dereferencedSchema = await SwaggerParser.dereference(schema);
try {
await SwaggerParser.validate(dereferencedSchema);
console.log('Schema is valid');
} catch (e) {
console.error(e);
}
await generateZodClientFromOpenAPI({
openApiDoc: dereferencedSchema as OpenAPIObject,
distPath: outputFilePath,
prettierConfig,
options: {
groupStrategy: 'method-file',
withAlias: true
}
});
got it, thanks for the investigation !
feel free to send a PR as I probably won't be able to contribute, being busy maintaining Panda CSS