Repository navigation
fix: update ci for typescript openapi.json drift - #1464
Conversation
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
sdks/typescript/scripts/fetch-openapi.mjs (1)
10-15: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse script-relative paths instead of
process.cwd()for better robustness.Relying on
process.cwd()assumes this script is always executed from thesdks/typescriptdirectory. While this holds true when run vianpm run, using URL-based path resolution (import.meta.url) makes the script resilient and safely executable from any working directory.🛠️ Proposed refactor for script-relative paths
import { spawnSync } from "node:child_process"; import { writeFileSync } from "node:fs"; -import { resolve } from "node:path"; +import { dirname, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; -const repoRoot = resolve(process.cwd(), "..", ".."); -const out = resolve(process.cwd(), "openapi.json"); +const __dirname = dirname(fileURLToPath(import.meta.url)); +const repoRoot = resolve(__dirname, "..", "..", ".."); +const out = resolve(__dirname, "..", "openapi.json");🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@sdks/typescript/scripts/fetch-openapi.mjs` around lines 10 - 15, Update the path setup around repoRoot and out to resolve locations from the script’s own URL via import.meta.url instead of process.cwd(). Ensure repoRoot still points to the repository root and out still targets the TypeScript SDK’s openapi.json, regardless of the caller’s working directory.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/generate_openapi.py`:
- Around line 12-19: Remove the VERSION_FILE write and fallback-file mutation
from the OpenAPI generation setup. After importing the FastAPI app via
memanto.app.main.app, temporarily set its version attribute to FALLBACK_VERSION
before schema generation, preserving the real source-controlled _version.py and
avoiding changes to the local source tree.
---
Nitpick comments:
In `@sdks/typescript/scripts/fetch-openapi.mjs`:
- Around line 10-15: Update the path setup around repoRoot and out to resolve
locations from the script’s own URL via import.meta.url instead of
process.cwd(). Ensure repoRoot still points to the repository root and out still
targets the TypeScript SDK’s openapi.json, regardless of the caller’s working
directory.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: be29d580-624e-4998-af68-3960a910c268
📒 Files selected for processing (4)
.github/workflows/sdk-typescript.ymlscripts/generate_openapi.pysdks/typescript/openapi.jsonsdks/typescript/scripts/fetch-openapi.mjs
| from pathlib import Path | ||
|
|
||
| FALLBACK_VERSION = "0.0.0.dev0" | ||
| VERSION_FILE = Path(__file__).resolve().parent.parent / "memanto" / "app" / "_version.py" | ||
|
|
||
| VERSION_FILE.write_text(f'__version__ = "{FALLBACK_VERSION}"\n') | ||
|
|
||
| from memanto.app.main import app # noqa: E402 |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Avoid mutating source files to override the OpenAPI version.
Overwriting _version.py permanently modifies the local source tree, which can cause the local application to report the fallback version instead of the real hatch-vcs version until the environment is rebuilt.
You can achieve the same drift-free OpenAPI generation by dynamically overriding the version attribute on the FastAPI app instance before generating the schema.
♻️ Proposed fix to dynamically override the version
-from pathlib import Path
-
-FALLBACK_VERSION = "0.0.0.dev0"
-VERSION_FILE = Path(__file__).resolve().parent.parent / "memanto" / "app" / "_version.py"
-
-VERSION_FILE.write_text(f'__version__ = "{FALLBACK_VERSION}"\n')
-
-from memanto.app.main import app # noqa: E402
+from memanto.app.main import app
+app.version = "0.0.0.dev0"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| from pathlib import Path | |
| FALLBACK_VERSION = "0.0.0.dev0" | |
| VERSION_FILE = Path(__file__).resolve().parent.parent / "memanto" / "app" / "_version.py" | |
| VERSION_FILE.write_text(f'__version__ = "{FALLBACK_VERSION}"\n') | |
| from memanto.app.main import app # noqa: E402 | |
| from memanto.app.main import app | |
| app.version = "0.0.0.dev0" |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@scripts/generate_openapi.py` around lines 12 - 19, Remove the VERSION_FILE
write and fallback-file mutation from the OpenAPI generation setup. After
importing the FastAPI app via memanto.app.main.app, temporarily set its version
attribute to FALLBACK_VERSION before schema generation, preserving the real
source-controlled _version.py and avoiding changes to the local source tree.
Summary by CodeRabbit
Documentation
Chores