reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.7k stars 1.17k forks source link

Codegen OpenAPI: negative numbers cause error #4455

Closed Innders closed 1 month ago

Innders commented 4 months ago

When I try to run npx @rtk-query/codegen-openapi openapi-config.ts I get the error:

Error: Debug Failure. False expression: Negative numbers should be created in combination with createPrefixUnaryExpression
    at Object.createNumericLiteral (/path/to/project/node_modules/typescript/lib/typescript.js:21094:13)
    at createLiteral (/path/to/project/node_modules/oazapfts/src/codegen/tscodegen.ts:42:22)
    at /path/to/project/node_modules/oazapfts/src/codegen/tscodegen.ts:50:39
    at Array.map (<anonymous>)
    at Object.createEnumTypeNode (/path/to/project/node_modules/oazapfts/src/codegen/tscodegen.ts:47:24)
    at ApiGenerator.getBaseTypeFromSchema (/path/to/project/node_modules/oazapfts/src/codegen/generate.ts:689:14)
    at ApiGenerator.getTypeFromSchema (/path/to/project/node_modules/oazapfts/src/codegen/generate.ts:563:23)
    at ApiGenerator.getRefAlias (/path/to/project/node_modules/oazapfts/src/codegen/generate.ts:432:25)
    at ApiGenerator.getBaseTypeFromSchema (/path/to/project/node_modules/oazapfts/src/codegen/generate.ts:580:19)
    at ApiGenerator.getTypeFromSchema (/path/to/project/node_modules/oazapfts/src/codegen/generate.ts:563:23)

openapi-config.ts

const config: ConfigFile = {
  schemaFile: 'https://ayon.dev/openapi.json',
  apiFile: './src/services/ayon.ts',
  apiImport: 'RestAPI',
  outputFile: './src/services/ayonRestTypes.ts',
  exportName: 'ayonRestApi',
}

If I exclude a specific endpoint filterEndpoints: [/^(?!.*sitesync).*$/i] then I don't get this error and everything is great.

The endpoint has a negative enum value (-1) and I believe this is the cause of the error. image

I found a similar issue report for this negative number error here (not sure how related it is): https://github.com/hey-api/openapi-ts/issues/466#issuecomment-2069303641

It doesn't look like openapi-ts is being used but maybe this is still helpful.

yamilelias commented 4 months ago

This is related to an issue from oazapfts dependency.

They already solved it, and it is available on v6.0.6. However, the dependency is on version v4.8.0. So, there's a need to update the dependency.

There's already a PR to update it, but it seems that no one is taking care of it.

Innders commented 4 months ago

Oh sorry I missed the PR, thanks! At least this issue might come up in a google search now for someone like me....

markerikson commented 1 month ago

Should be live in https://github.com/reduxjs/redux-toolkit/releases/tag/%40rtk-query%2Fcodegen-openapi%402.0.0-alpha.0 ! Please try it out and let us know if it works.

Innders commented 1 month ago

Please try it out and let us know if it works.

I can confirm that this fixes the issue! Thanks 💯

image