-
-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(openapi-typescript): --make-paths-enum renames the paths URL #2152
base: main
Are you sure you want to change the base?
Conversation
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: e60c169 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@insertmike I also opened a PR #2153 a few minutes ago! Thanks for the reminder :) As for the fix, it's up to the maintainers but the |
@Semigradsky You are right, I did not look into the code too much, then the maintainers can feel free to close my PR and merge yours #2153 but please take some action, it's straight-forward change and the community needs it 🙏 I will leave this PR open to bring back awareness to this issue.. |
@semanser @insertmike great minds think alike 😅 |
Hi all. We are happy to take a look at this, but please refrain from directly mentioning maintainers unless it's absolutely critical. Thank you! |
Noted - won't happen again. Thanks for your time :) |
@drwpow it looks like this does fix a reintroduced bug. However, applying it will affect the behavior for anyone who has started using the flag. I know you mentioned the following when this was fixed, so I want to double-check before we change its behavior:
Do you think a patch release is appropriate? |
@htunnicliff Looking back in time, when this feature was first introduced, it was implemented incorrectly (issue) and was patched with this Pull Request. I suspect that when reintroducing the feature, the author of the pull request simply copied the call from the original implementation without realizing that it was initially incorrect and patched in time. We could add it as a flag, but to me, it just seems fundamentally wrong—ApiPaths is not useful if it doesn’t match the original paths of the OpenAPI schema. WDYT? |
Temporary Workaround for the --make-paths-enum BugAssuming you saved the snippet as /**
* Workaround for --make-paths-enum bug:
* https://github.com/openapi-ts/openapi-typescript/pull/2152
*
* Generated ApiPaths enum values use ":id" instead of "{id}".
* This script converts ":param" to "{param}".
*
* Usage: node posprocessOpenApiGeneration.js <generated-file-path>
*/
import fs from "fs";
// Get file path from command-line arguments
const filePath = process.argv[2];
if (!filePath) {
console.error("Usage: node postprocess.js <file-path>");
process.exit(1);
}
let content = fs.readFileSync(filePath, "utf8");
// Regex to capture the ApiPaths enum block
// Group 1: "export enum ApiPaths {"
// Group 2: the enum body (non-greedy)
// Group 3: the closing brace
const enumRegex = /(export\s+enum\s+ApiPaths\s*{)([\s\S]*?)(\n?\s*})/;
// Replace only inside the ApiPaths enum block
content = content.replace(enumRegex, (match, start, enumBody, end) => {
// Replace occurrences of ":param" with "{param}" in the enum body
const modifiedBody = enumBody.replace(/:([a-zA-Z0-9_]+)/g, "{$1}");
return `${start}${modifiedBody}${end}`;
});
fs.writeFileSync(filePath, content, "utf8");
console.log(`File "${filePath}" updated successfully!`); Add a post-generation script to your package.json so that the patch is applied automatically after generating your API client: {
"scripts": {
"script-generating-openapi": "your-openapi-generation-command OUTPUT_PATH",
"postscript-generating-openapi": "node postprocess.js OUTPUT_PATH"
}
} When you run the script-generating-openapi command, the post script will automatically be invoked, updating your ApiPaths enum to use the correct placeholder syntax. |
Changes
Fixes: #2101, when the --make-paths-enum was reintroduced back it was reintroduced with previously fixed bug: #950
How to Review
It's straight-forward change :)
Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)