redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

2XX status code is always ignored

Open maddrag0n opened this issue 6 months ago • 6 comments

Current Behavior

'2XX' status is always ignored

Expected Behavior

in absence of a more specific 200 range status code, the 2XX code should be used to type the response (see https://swagger.io/specification/v3/#responses-object)

Example

this leads to generated ApiResponse type to be typed to any

"responses": {
  "2XX": {
    "description": "…",
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/MyComponent"
        }
      }
    }
  }
}

maddrag0n avatar May 08 '25 12:05 maddrag0n

closing because unclear whether that was solved with 2.0.0 (which I cannot run because cli is not exported as export in package.json)

maddrag0n avatar May 08 '25 13:05 maddrag0n

@maddrag0n can you clarify the packaging comment?

markerikson avatar May 08 '25 15:05 markerikson

@markerikson we are calling the cli programmatically like this

const cliPath = require.resolve('@rtk-query/codegen-openapi/lib/bin/cli');

const runReduxCodegen = async (specUrl: string | undefined, configPath: string, outputPath: string): Promise<void> => (
  new Promise((resolve, reject) => {
    exec(
      `tsx ${cliPath} ${configPath}`,
      {
        env: {
          ...process.env,
          SPEC_URL: specUrl,
          STORE_ROOT_PATH: outputPath,
        },
      },
      (error, stdout, stderr) => {
        if (error) {
          console.error(`exec error: ${error}`);
          reject(new Error(`Execution failed with error: ${stderr || 'Unknown error'}`));
        } else {
          console.log(stdout);

          if (stderr) {
            reject(new Error(`Execution produced errors: ${stderr}`));
          } else {
            resolve();
          }
        }
      },
    );
  })
);

when upgrading from 1.2.0 to 2.0.0, the error message is that /lib/bin/cli is not in exports of the package

nodeLinker is pnp

maddrag0n avatar May 08 '25 15:05 maddrag0n

Yeah, we don't have that exposed here:

https://github.com/reduxjs/redux-toolkit/blob/cb089e6c834ff72a5457875e0f5be10a742ee239/packages/rtk-query-codegen-openapi/package.json#L10-L22

We didn't anticipate anyone trying to do what you're doing :)

Ought to be doable, though - just need to add it as an entry point in the exports section (ie "./cli").

Opened https://github.com/reduxjs/redux-toolkit/issues/4976 to track that, and I'll keep this issue open as well.

Not immediately sure when we'll have time to work on the codegen specifically, but it ought to be a fairly simple change if you'd like to file a PR!

markerikson avatar May 08 '25 15:05 markerikson

I was able to confirm 2.0.0 does not solve the 2XX incompatibility

maddrag0n avatar May 09 '25 08:05 maddrag0n

Now that we've shipped an updated Codegen CLI version with the CLI package exposed, are there next steps we need to do here?

markerikson avatar Oct 22 '25 01:10 markerikson