Closed robogeek closed 9 months ago
The upstream package says it has been fixed. Does this package need to update its dependencies?
The package has this dependency:
"json-schema-to-zod": "^1.1.1",
The upstream package is at 2.0.13
updated it . I hope it resolves your problem.
Well, I updated to 0.0.6
and now get the following error. I see at the referenced line there is require('./parser/parser')
but there is no such file inside dist
.
> npx openapi-to-zod -x ts -i ${npm_package_config_openadryaml} -o ${npm_package_config_zodoutput}
node:internal/modules/cjs/loader:1147
throw err;
^
Error: Cannot find module './parser/parser'
Require stack:
- /home/david/Projects/openadr/openadr-3-ts-types/builder/node_modules/openapi-to-zod/dist/index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
at Module._load (node:internal/modules/cjs/loader:985:27)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (/home/david/Projects/openadr/openadr-3-ts-types/builder/node_modules/openapi-to-zod/dist/index.js:39:18)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/david/Projects/openadr/openadr-3-ts-types/builder/node_modules/openapi-to-zod/dist/index.js'
]
}
Node.js v20.10.0
odd. for some reason npm decided to ignore subdirectories in dist folder when package.json was like this:
I changed it to 'dist' without the glob pattern and it now includes them.
edit: seems to be an npm bug
Thank you for the quick response. That has the program running correctly. But, there's a new problem:
$ cat zod/zod-dateTime.ts
z.string().datetime().describe("datetime in ISO 8601 format")
That is - the schema is not exported from the module.
A minor nitpick is there is no final newline at the end of the file.
lol. sorry I'm a little sleepy right now. it's midnight here.
I see you updated to 0.0.9
This update is working correctly.
Thank you.
If an object schema has a field with
default: null
andnullable: true
, the Zod schema is generated incorrectly. The.nullable()
appears after.default(null)
, and.default(null)
appears twice.With this schema:
Running the command:
Generates these Zod schemas.
For the first
.default(null)
, withtsconfig.json
containing"strict": true
, an error is thrown by the compiler saying the following:But, moving the
.nullable()
before.default(null)
no such error is thrown. THEORY, having.nullable
first puts the Zod code into a state where.default()
takes eithernull | string
rather than juststring
.The other issue is that
.default(null)
appears twice in the generated code. This does not happen ifnullable
does not appear in the schema.