# sdkwork-code-generator **Repository Path**: zowalk/sdkwork-code-generator ## Basic Information - **Project Name**: sdkwork-code-generator - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-05 - **Last Updated**: 2025-10-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SDKWork Code Generator 一个基于 OpenAPI 3.x 标准的现代化多语言代码生成器,支持生成多种编程语言的 SDK 和 HTTP 请求代码。 ## ✨ 特性 - **多语言支持**: 支持 12+ 种编程语言的代码生成 - **OpenAPI 3.x 标准**: 完全遵循最新的 OpenAPI 规范 - **HTTP 请求生成**: 自动生成完整的 HTTP 请求代码 - **SDK 生成**: 生成完整的 SDK 项目结构 - **类型安全**: 完整的 TypeScript 类型定义 - **可扩展架构**: 模块化设计,易于扩展新语言支持 ## 🚀 支持的语言 | 语言 | HTTP 库支持 | SDK 生成 | MCP 生成 | 代码生成 | |------|-------------|----------|----------|----------| | JavaScript | ✅ Axios, Fetch, Got, Superagent | ✅ | 🔄 | ✅ | | TypeScript | ✅ Axios, Fetch, Got, Superagent | ✅ | 🔄 | ✅ | | Python | ✅ Requests, aiohttp, httpx | ✅ | 🔄 | ✅ | | Java | ✅ OkHttp, Retrofit, Apache HttpClient, Unirest | ✅ | 🔄 | ✅ | | Go | ✅ net/http, fasthttp, resty | ✅ | 🔄 | ✅ | | C# | ✅ HttpClient, RestSharp, Refit | ✅ | 🔄 | ✅ | | PHP | ✅ Guzzle, cURL | ✅ | 🔄 | ✅ | | Swift | ✅ Alamofire, URLSession | ✅ | 🔄 | ✅ | | Dart | ✅ Dio, http | ✅ | 🔄 | ✅ | | Kotlin | ✅ OkHttp, Retrofit | ✅ | 🔄 | ✅ | | Ruby | ✅ Faraday, HTTParty | ✅ | 🔄 | ✅ | | C++ | ✅ Boost.Beast, cpp-httplib, cpprest | ✅ | 🔄 | ✅ | ## 📦 安装 ```bash # 克隆项目 git clone https://github.com/nodesource/sdkwork-code-generator.git cd sdkwork-code-generator # 安装依赖 npm install # 构建项目 npm run build ``` ## 🎯 快速开始 ### 基本使用 首先安装包: ```bash npm install sdkwork-code-generator ``` 然后在代码中使用: ```typescript import { OpenAPIParser, CodeGeneratorFactory } from 'sdkwork-code-generator'; // 创建解析器实例 const parser = new OpenAPIParser(); // 方式1: 解析本地文件(自动检测格式) const specFromFile = await parser.parseFile('path/to/openapi.yaml'); // 支持 .yaml, .yml, .json // 方式2: 从 URL 解析 const specFromUrl = await parser.parseByUrl('https://api.example.com/openapi.json'); // 方式3: 直接解析字符串内容 const yamlContent = ` openapi: 3.0.0 info: title: Sample API version: 1.0.0 `; const specFromString = parser.parse(yamlContent); // 使用工厂类生成代码 const generator = CodeGeneratorFactory.getGenerator('typescript', 'axios'); const result = generator.generateCode( '/api/users/{userId}', 'GET', 'https://api.example.com', specFromFile.paths['/api/users/{userId}'].get, [], // cookies [], // headers [], // queryParams null, // requestBody { outputDir: './generated', baseUrl: 'https://api.example.com' } ); console.log('Generated code:', result); ``` ### 代码生成支持 本项目提供多种代码生成能力: #### 1. OpenAPI Operation 访问代码生成 ✅ 使用 `RequestCodeGenerator` 接口,支持多种语言实现,生成具体的 HTTP 请求代码。 ```typescript import { RequestCodeGenerator } from 'sdkwork-code-generator'; // 获取特定语言的代码生成器 const codeGenerator = CodeGeneratorFactory.getGenerator('typescript', 'axios'); // 生成单个操作的请求代码 const code = codeGenerator.generateCode( '/api/users/{userId}', 'GET', 'https://api.example.com', operation, [], // cookies [], // headers [], // queryParams null, // requestBody { outputDir: './generated', baseUrl: 'https://api.example.com' } ); ``` #### 2. 多语言 SDK 生成 🔄 正在开发中... 基于 OpenAPI 标准生成完整的 SDK 项目结构。 #### 3. MCP 代码生成 🔄 正在开发中... 通过 OpenAPI 标准生成 Model Context Protocol 相关代码。 #### 4. 提示词驱动代码生成 🔄 正在开发中... 通过输入提示词生成代码,支持 MCP 调用。 #### 5. 提示词驱动工程创建 🔄 正在开发中... 通过输入提示词创建完整的代码工程,支持 MCP 调用。 #### 6. 提示词驱动应用创建 🔄 正在开发中... 通过输入提示词创建完整应用,支持 MCP 调用。 ### 检查支持的语言和库 ```typescript // 获取支持的语言列表 const supportedLanguages = CodeGeneratorFactory.getSupportedLanguages(); console.log('Supported languages:', supportedLanguages); // 检查特定组合是否支持 const isSupported = CodeGeneratorFactory.isSupported('python', 'requests'); console.log('Python requests supported:', isSupported); // 获取所有语言列表 const languages = CodeGeneratorFactory.getLanguages(); console.log('Languages:', languages); // 获取特定语言支持的库 const pythonLibs = CodeGeneratorFactory.getLibraries('python'); console.log('Python libraries:', pythonLibs); // 获取默认库 const defaultPythonLib = CodeGeneratorFactory.getDefaultLibrary('python'); console.log('Default Python library:', defaultPythonLib); ``` ### 命令行使用 ```bash # 生成 TypeScript Axios 代码 npm run generate -- --input openapi.yaml --language typescript --library axios --output ./generated # 生成 Python Requests 代码 npm run generate -- --input openapi.yaml --language python --library requests --output ./generated ``` ## 📁 项目结构 ``` sdkwork-code-generator/ ├── src/ # 源代码 │ ├── openapi/ # OpenAPI 功能模块 │ │ ├── parser/ # 解析器 │ │ └── generator/ # 代码生成器 │ │ └── languages/ # 多语言实现 │ ├── mcp/ # MCP 协议支持 │ ├── sdk/ # SDK 生成 │ ├── types/ # 类型定义 │ └── utils/ # 工具函数 ├── templates/ # 代码模板 ├── dist/ # 构建输出 └── test/ # 测试文件 ``` ## 🔧 开发 ### 开发环境设置 ```bash # 安装依赖 npm install # 开发模式(监听文件变化) npm run dev # 运行测试 npm test # 构建项目 npm run build # 代码检查 npm run lint # 代码格式化 npm run format ``` ### 添加新的语言支持 1. 在 `src/openapi/generator/languages/` 创建语言目录 2. 实现 `BaseRequestCodeGenerator` 抽象类 3. 在语言注册表中注册新语言 4. 添加相应的测试用例 ## 🧪 测试 项目包含完整的单元测试和集成测试: ```bash # 运行所有测试 npm test # 运行测试并生成覆盖率报告 npm run test:coverage # 运行特定测试 npm test -- --grep "javascript" ``` ## 📊 代码质量 - **TypeScript**: 严格的类型检查 - **ESLint**: 代码规范检查 - **Prettier**: 代码自动格式化 - **Jest**: 单元测试框架 - **Husky**: Git 钩子管理 ## 🤝 贡献 欢迎贡献代码!请遵循以下步骤: 1. Fork 项目 2. 创建功能分支 (`git checkout -b feature/amazing-feature`) 3. 提交更改 (`git commit -m 'Add amazing feature'`) 4. 推送到分支 (`git push origin feature/amazing-feature`) 5. 创建 Pull Request ## 📄 许可证 本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。 ## 🔗 相关链接 - [OpenAPI 规范](https://github.com/OAI/OpenAPI-Specification) - [Model Context Protocol](https://github.com/modelcontextprotocol) - [项目 Issues](https://github.com/nodesource/sdkwork-code-generator/issues) ## 📞 支持 如有问题或建议,请通过以下方式联系: - 创建 [Issue](https://github.com/nodesource/sdkwork-code-generator/issues) - 发送邮件至: support@nodesource.com --- ⭐ 如果这个项目对你有帮助,请给个 Star!