{"id":50536754,"url":"https://github.com/chihebnabil/openapi-graft","last_synced_at":"2026-06-03T17:01:08.290Z","repository":{"id":359007018,"uuid":"1244098128","full_name":"chihebnabil/openapi-graft","owner":"chihebnabil","description":null,"archived":false,"fork":false,"pushed_at":"2026-05-20T00:56:26.000Z","size":202,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-05-20T03:52:00.226Z","etag":null,"topics":["fern","openapi","sdk","stainless"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chihebnabil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-20T00:54:05.000Z","updated_at":"2026-05-20T00:57:47.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/chihebnabil/openapi-graft","commit_stats":null,"previous_names":["chihebnabil/openapi-graft"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/chihebnabil/openapi-graft","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chihebnabil%2Fopenapi-graft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chihebnabil%2Fopenapi-graft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chihebnabil%2Fopenapi-graft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chihebnabil%2Fopenapi-graft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chihebnabil","download_url":"https://codeload.github.com/chihebnabil/openapi-graft/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chihebnabil%2Fopenapi-graft/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33874679,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-03T02:00:06.370Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fern","openapi","sdk","stainless"],"created_at":"2026-06-03T17:01:07.066Z","updated_at":"2026-06-03T17:01:08.284Z","avatar_url":"https://github.com/chihebnabil.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# openapi-graft\n\nOpenAPI SDK generator with AST-level 3-way merge for preserved custom code, plus MCP server scaffolding.\n\n## Features\n\n- **Multi-language SDK generation**: TypeScript, Python, Go, Java, Rust\n- **AST-level 3-way merge**: Preserves custom code across regenerations using `@graft` annotations\n- **MCP server scaffolding**: Generate Model Context Protocol servers from the same OpenAPI spec\n- **CI-native**: Runs as a CLI tool, no cloud dependency\n- **Validation**: Compiles merged output before writing to disk, fails CI if custom code breaks\n\n## Quick Start\n\n```bash\n# Install globally\nnpm install -g openapi-graft\n\n# Or use with npx\nnpx openapi-graft init\nnpx openapi-graft generate\n```\n\n## How It Works\n\nGraft uses annotated regions for code preservation across regenerations:\n\n| Layer | Function |\n|-------|----------|\n| Parser | Tree-sitter based - TypeScript, Python, Go, Java, Rust |\n| Base | Previous clean generation (stored in `.graft/base/`) |\n| Ours | Current working SDK with custom code |\n| Theirs | New generation from updated OpenAPI spec |\n| Merge Engine | Identifies `@graft(preserve)` annotated blocks, merges them into new generated classes |\n| Validator | Compiles the merged output before writing - fails CI if custom code broke the new interface |\n\n## Configuration\n\nCreate a `graft.yml` in your project root:\n\n```yaml\nspec: ./openapi.json\nsdks:\n  - language: typescript\n    output: ./sdks/ts\n    package: \"@yourcompany/sdk\"\n    preserve:\n      - ./sdks/ts/src/custom/**/*.ts  # auto-annotated on first run\n  - language: python\n    output: ./sdks/python\n    package: \"yourcompany-sdk\"\n  - language: go\n    output: ./sdks/go\n    package: \"github.com/yourcompany/sdk\"\nmcp:\n  enabled: true\n  output: ./mcp-server\n```\n\n## Preserving Custom Code\n\nUse `@graft` annotations to mark code that should survive regeneration:\n\n### TypeScript\n```typescript\n// @graft(preserve) id=\"custom-validation\"\nasync validateCustom(request: Request): Promise\u003cResponse\u003e {\n  // Your custom implementation\n  // This survives SDK regeneration\n}\n```\n\n### Python\n```python\n# @graft(preserve) id=\"custom-validation\"\nasync def validate_custom(self, request):\n    # Your custom implementation\n    # This survives SDK regeneration\n    pass\n```\n\n### Go\n```go\n// @graft(preserve) id=\"custom-handler\"\nfunc (api *API) CustomHandler(ctx context.Context, req Request) (*Response, error) {\n    // Custom implementation survives regeneration\n}\n```\n\n### Java\n```java\n// @graft(preserve) id=\"custom-handler\"\npublic Object customHandler(String param) throws SDKException {\n    // Custom implementation survives regeneration\n}\n```\n\n### Rust\n```rust\n/// @graft(preserve) id=\"custom-handler\"\npub async fn custom_handler(\u0026self, param: String) -\u003e GraftResult\u003cValue\u003e {\n    // Custom implementation survives regeneration\n    Ok(Value::Null)\n}\n```\n\n## CLI Commands\n\n```bash\n# Initialize a new graft.yml\ngraft init\n\n# Generate all SDKs\ngraft generate\n\n# Generate MCP server\ngraft mcp\n\n# Perform manual 3-way merge\ngraft merge --base ./base --ours ./ours --theirs ./theirs --language typescript --output ./merged\n\n# Show status\ngraft status\n```\n\n## Why Graft?\n\n| Feature | OpenAPI Generator | Fern | Graft |\n|---------|------------------|------|-------|\n| Custom code survives regen | ❌ Overwritten | ⚠️ .fernignore (manual) | ✅ AST merge with annotations |\n| MCP server from same spec | ❌ No | ❌ No | ✅ Built-in |\n| Self-hosted / air-gapped | ✅ Yes | ⚠️ Docker only | ✅ CLI-native, no cloud |\n| Idiomatic output quality | ❌ Generic | ✅ High | ✅ Template-based |\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchihebnabil%2Fopenapi-graft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchihebnabil%2Fopenapi-graft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchihebnabil%2Fopenapi-graft/lists"}