Q42 / openapi-typescript-validator

Generate typescript with ajv validation based on openapi schemas
26 stars 15 forks source link

Error generating schema #16

Open hermanbanken opened 2 years ago

hermanbanken commented 2 years ago

One of the dependencies (json-stringify-safe) throws an error when generating our schema. The error is:

Start generating files for custom schema: /project/json-schemas/schemas/schema.ts
/project/json-schemas/node_modules/json-stringify-safe/stringify.js:5
  return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces)
              ^
RangeError: Invalid string length
    at JSON.stringify (<anonymous>)
    at stringify (/project/json-schemas/node_modules/json-stringify-safe/stringify.js:5:15)
    at /project/json-schemas/node_modules/json-schema-to-typescript/dist/src/optimizer.js:34:204
    at baseUniq (/project/json-schemas/node_modules/lodash/lodash.js:4338:35)
    at Function.uniqBy (/project/json-schemas/node_modules/lodash/lodash.js:8482:40)
    at optimize (/project/json-schemas/node_modules/json-schema-to-typescript/dist/src/optimizer.js:34:35)
    at /project/json-schemas/node_modules/json-schema-to-typescript/dist/src/optimizer.js:18:86
    at Array.map (<anonymous>)
    at Object.optimize (/project/json-schemas/node_modules/json-schema-to-typescript/dist/src/optimizer.js:18:36)
    at Object.<anonymous> (/project/json-schemas/node_modules/json-schema-to-typescript/dist/src/index.js:159:45)

Just reporting this here, before I dive deeper into the issue.

hermanbanken commented 2 years ago

Removing node_modules/json-schema-to-typescript/dist/src/optimizer.js from running (direct return via return ast at the top), both makes the generation nearly instant, as fixes the issue... but no idea what isn't done then...

hermanbanken commented 2 years ago

Updating json-schema-to-typescript to v11 seems to fix the issue, and seems to have no further downsides/impact on our code generation.