improve-sdk-naming
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseimprove-sdk-naming
优化SDK命名
Improve SDK method naming using AI-powered suggestions or manual overrides. Covers both automatic commands and manual naming with and extensions.
speakeasy suggestx-speakeasy-groupx-speakeasy-name-override借助AI驱动的建议或手动覆盖来改进SDK方法命名。涵盖自动命令以及使用和扩展的手动命名方式。
speakeasy suggestx-speakeasy-groupx-speakeasy-name-overrideWhen to Use
适用场景
Use this skill when you want AI-powered suggestions from Speakeasy:
- SDK methods have ugly auto-generated names like
GetApiV1Users - You want Speakeasy AI to suggest better operation IDs
- You want AI-generated suggestions for error types
- Looking to improve spec quality automatically using
speakeasy suggest - User says: "suggest improvements", "speakeasy suggest", "AI suggestions", "suggest operation-ids", "suggest error-types", "get AI recommendations"
NOT for: Manually creating overlays (see instead)
manage-openapi-overlays当你希望从Speakeasy获取AI驱动的建议时,可以使用此技能:
- SDK方法存在这类不够友好的自动生成名称
GetApiV1Users - 希望Speakeasy AI推荐更优的operation ID
- 希望获取AI生成的错误类型建议
- 希望通过自动提升规范质量
speakeasy suggest - 用户提及:"建议改进"、"speakeasy suggest"、"AI建议"、"建议operation-ids"、"建议错误类型"、"自动优化命名"、"获取AI推荐"
不适用场景:手动创建覆盖层(请改用技能)
manage-openapi-overlaysInputs
输入参数
| Input | Required | Description |
|---|---|---|
| OpenAPI spec | Yes | Path to the spec file ( |
| Authentication | Yes | Via |
| Output file | No | Path for overlay output ( |
| 输入项 | 是否必填 | 描述 |
|---|---|---|
| OpenAPI 规范 | 是 | 规范文件路径( |
| 身份验证 | 是 | 通过 |
| 输出文件 | 否 | 覆盖层输出路径( |
Outputs
输出结果
| Output | Description |
|---|---|
| Suggestions | Better operation names or error types printed to console |
| Overlay file | Optional: saves suggestions as an overlay YAML file ( |
| 输出项 | 描述 |
|---|---|
| 建议内容 | 更优的操作名称或错误类型,将打印至控制台 |
| 覆盖层文件 | 可选:将建议保存为YAML格式的覆盖层文件(通过 |
Prerequisites
前置条件
For non-interactive environments (CI/CD, AI agents), set the API key as an environment variable:
bash
export SPEAKEASY_API_KEY="<your-api-key>"For interactive use, authenticate directly:
bash
speakeasy auth login对于非交互式环境(CI/CD、AI Agent),需将API密钥设置为环境变量:
bash
export SPEAKEASY_API_KEY="<your-api-key>"对于交互式使用场景,直接执行身份验证:
bash
speakeasy auth loginCommand
命令示例
AI-Powered Suggestions
AI驱动的建议
bash
undefinedbash
undefinedSuggest better operation IDs (SDK method names)
推荐更优的operation ID(即SDK方法名称)
speakeasy suggest operation-ids -s <spec-path>
speakeasy suggest operation-ids -s <spec-path>
Suggest error type definitions
推荐错误类型定义
speakeasy suggest error-types -s <spec-path>
speakeasy suggest error-types -s <spec-path>
Output suggestions as an overlay file
将建议输出为覆盖层文件
speakeasy suggest operation-ids -s <spec-path> -o suggested-overlay.yaml
undefinedspeakeasy suggest operation-ids -s <spec-path> -o suggested-overlay.yaml
undefinedCheck Current Operation IDs
查看当前的operation ID
Run the suggest command without to preview what would change:
-obash
speakeasy suggest operation-ids -s openapi.yaml执行不带参数的suggest命令,即可预览将会做出的更改:
-obash
speakeasy suggest operation-ids -s openapi.yamlSDK Method Naming Convention
SDK方法命名规范
Speakeasy generates grouped SDK methods from operation IDs. The naming convention uses for the namespace and for the method name.
x-speakeasy-groupx-speakeasy-name-override| HTTP Method | SDK Usage | Operation ID |
|---|---|---|
| GET (list) | | |
| GET (single) | | |
| POST | | |
| PUT | | |
| DELETE | | |
The operation ID format is . Speakeasy splits on the underscore to create the namespace and method name in the generated SDK.
{group}_{method}Speakeasy会根据operation ID生成分组的SDK方法。命名规范使用指定命名空间,指定方法名称。
x-speakeasy-groupx-speakeasy-name-override| HTTP方法 | SDK使用方式 | Operation ID |
|---|---|---|
| GET(列表) | | |
| GET(单个资源) | | |
| POST | | |
| PUT | | |
| DELETE | | |
Operation ID的格式为。Speakeasy会通过下划线分割,在生成的SDK中创建对应的命名空间和方法名称。
{group}_{method}Example
示例步骤
Step 1: Get AI Suggestions
步骤1:获取AI建议
bash
speakeasy suggest operation-ids -s openapi.yaml -o operation-ids-overlay.yamlThis analyzes your spec and generates an overlay that transforms names like:
- ->
get_api_v1_users_listlistUsers - ->
post_api_v1_users_createcreateUser
bash
speakeasy suggest operation-ids -s openapi.yaml -o operation-ids-overlay.yaml此命令会分析你的规范并生成覆盖层,将如下名称进行转换:
- ->
get_api_v1_users_listlistUsers - ->
post_api_v1_users_createcreateUser
Step 2: Review and Apply the Overlay
步骤2:审核并应用覆盖层
The AI-generated overlay (from ) creates naming improvements using and .
-ox-speakeasy-groupx-speakeasy-name-overrideNote: For manual overlay creation, use the skill instead of this skill.
manage-openapi-overlaysAI生成的覆盖层(通过参数生成)会使用和实现命名优化。
-ox-speakeasy-groupx-speakeasy-name-override注意:如需手动创建覆盖层,请使用技能,而非本技能。
manage-openapi-overlaysStep 3: Add the Overlay to workflow.yaml
步骤3:将覆盖层添加至workflow.yaml
yaml
sources:
my-api:
inputs:
- location: ./openapi.yaml
overlays:
- location: ./operation-ids-overlay.yamlyaml
sources:
my-api:
inputs:
- location: ./openapi.yaml
overlays:
- location: ./operation-ids-overlay.yamlStep 4: Regenerate the SDK
步骤4:重新生成SDK
bash
speakeasy run --output consolebash
speakeasy run --output consoleError Type Suggestions
错误类型建议
The command analyzes your API and suggests structured error responses:
suggest error-typesbash
speakeasy suggest error-types -s openapi.yamlThis suggests:
- Common HTTP error codes (400, 401, 404, 500)
- Custom error schemas appropriate for your API
Output as an overlay:
bash
speakeasy suggest error-types -s openapi.yaml -o error-types-overlay.yamlsuggest error-typesbash
speakeasy suggest error-types -s openapi.yaml此命令会推荐:
- 常见HTTP错误码(400、401、404、500)
- 适合你的API的自定义错误 schema
将建议输出为覆盖层:
bash
speakeasy suggest error-types -s openapi.yaml -o error-types-overlay.yamlWhat NOT to Do
注意事项
- Do NOT modify operationIds directly in the source spec if it is externally managed. Use overlays instead.
- Do NOT use generic names like or
getwithout a group. Always pairpostwithx-speakeasy-name-override.x-speakeasy-group - Do NOT forget to add the generated overlay to after creating it. Without this step, the names will not change in the generated SDK.
workflow.yaml - Do NOT create duplicate operation names across different groups. Each combination must be unique.
{group}_{method}
- 请勿直接修改外部管理的源规范中的operationId,应改用覆盖层。
- 请勿使用或
get这类通用名称而不指定分组。务必将post与x-speakeasy-name-override配合使用。x-speakeasy-group - 请勿在创建覆盖层后忘记将其添加至。若不执行此步骤,生成的SDK中的名称不会发生变化。
workflow.yaml - 请勿在不同分组中创建重复的方法名称。每个组合必须唯一。
{group}_{method}
Troubleshooting
故障排除
| Error | Cause | Solution |
|---|---|---|
| "unauthorized" | Missing or invalid API key | Set |
| Names unchanged after regeneration | Overlay not added to workflow | Add the overlay to the |
| No suggestions returned | Spec already has good naming | No action needed; names are already well-structured |
| Duplicate method names | Similar endpoints share names | Use unique |
| Timeout during suggest | Very large spec | Try running on a smaller subset or increase timeout |
| 错误信息 | 原因 | 解决方案 |
|---|---|---|
| "unauthorized" | API密钥缺失或无效 | 设置 |
| 重新生成后名称未改变 | 覆盖层未添加至工作流 | 将覆盖层添加至 |
| 未返回任何建议 | 规范的命名已较为合理 | 无需操作;当前名称结构已符合要求 |
| 方法名称重复 | 相似端点使用了相同名称 | 为每个端点使用唯一的 |
| suggest命令超时 | 规范文件过大 | 尝试在较小的子集上运行,或增加超时时间 |