Fredx87 / openapi-io-ts

OpenAPI code generation tool with validation powered by io-ts
MIT License
36 stars 9 forks source link

openapi-io-ts generator script thrown an error #19

Open paololim opened 2 years ago

paololim commented 2 years ago

We are running into an issue generating for our project. The instructions in the readme were followed, and summarized below as follows.

Added to package.json as a devDependency using:

npm i -D @openapi-io-ts/cli

Added a command in our package.json using:

scripts: {
  ...
  "openapi-io-ts:generate": "openapi-io-ts -i apps/dashboard-api/src/docs/openapi.yaml -o apps/dashboard-api/src/codecs/generated",
  ...
}

Note that apps/dashboard-api/src/docs/openapi.yaml is a valid openapi format using:

openapi: 3.0.1

We get the following:

$ npm run openapi-io-ts:generate

> dynamic@0.0.0 openapi-io-ts:generate
> openapi-io-ts -i apps/dashboard-api/src/docs/openapi.yaml -o apps/dashboard-api/src/codecs/generated

/Users/paolo/Dyn/redcoast/node_modules/@openapi-io-ts/cli/dist/bin.js:981
  return (0, import_function16.pipe)(RTE12.Do, RTE12.bind("schema", () => JsonReference.is(s) ? getOpenapiSchemaFromRef(s) : RTE12.right(s)), RTE12.map((obj) => obj.schema.default));
                                                                                                                                                                            ^
TypeError: Cannot read properties of undefined (reading 'default')
    at /Users/paolo/Dyn/redcoast/node_modules/@openapi-io-ts/cli/dist/bin.js:981:173
    at /Users/paolo/Dyn/redcoast/node_modules/fp-ts/lib/Either.js:268:52
    at Object.pipe (/Users/paolo/Dyn/redcoast/node_modules/fp-ts/lib/function.js:286:20)
    at Object._map [as map] (/Users/paolo/Dyn/redcoast/node_modules/fp-ts/lib/Either.js:56:49)
    at /Users/paolo/Dyn/redcoast/node_modules/fp-ts/lib/Functor.js:19:92

My expectation is that the command will generate the the necessary files based on the openapi.yml file passed in as a parameter. Is there something I am missing here? Thanks!