{"meta":{"title":"文档 API","intro":"基于代码生成全面的 API 文档。","product":"GitHub Copilot","breadcrumbs":[{"href":"/zh/copilot","title":"GitHub Copilot"},{"href":"/zh/copilot/tutorials","title":"教程"},{"href":"/zh/copilot/tutorials/customization-library","title":"定制化库"},{"href":"/zh/copilot/tutorials/customization-library/prompt-files","title":"提示文件"},{"href":"/zh/copilot/tutorials/customization-library/prompt-files/document-api","title":"文档 API"}],"documentType":"article"},"body":"# 文档 API\n\n基于代码生成全面的 API 文档。\n\n> \\[!NOTE]\n>\n> * Copilot 提示文件为 公共预览版，可能随时更改。 提示文件仅适用于 VS Code、Visual Studio 和 JetBrains IDE。请查看 [关于自定义GitHub Copilot 响应](/zh/copilot/concepts/prompting/response-customization#about-prompt-files)。\n> * 如需获取社区提供的有关特定语言和场景的提示文件示例，请参阅[出色的 GitHub Copilot 自定义内容](https://github.com/github/awesome-copilot/blob/main/docs/README.prompts.md)仓库。\n\n此提示文件通过分析 API 代码以及创建标准化的计算机可读文档，为 REST API 终结点生成 OpenAPI 3.0 规范。\n\n## OpenAPI 规范提示\n\n```text copy\n---\nagent: 'agent'\ndescription: 'Generate OpenAPI 3.0 specification for API endpoints'\n---\n\n## Task\n\nAnalyze the API endpoint code and generate a valid OpenAPI 3.0 specification in YAML format.\n\n## OpenAPI Structure\n\nGenerate a complete OpenAPI spec including:\n\n1. **OpenAPI Header**\n   - OpenAPI version (3.0.3)\n   - API info (title, description, version)\n   - Server configuration\n\n2. **Path Definitions**\n   - HTTP method and path\n   - Operation summary and description\n   - Tags for organization\n\n3. **Parameters Schema**\n   - Path parameters with type validation\n   - Query parameters with constraints and defaults\n   - Request body schema using proper JSON Schema\n   - Required vs optional parameters\n\n4. **Response Schemas**\n   - Success responses (200, 201, etc.) with schema definitions\n   - Error responses (400, 401, 404, 500) with error schema\n   - Content-Type specifications\n   - Realistic example values\n\n5. **Components Section**\n   - Reusable schemas for request/response models\n   - Security schemes (Bearer token, API key, etc.)\n   - Common parameter definitions\n\n## Requirements\n\n- Generate valid OpenAPI 3.0.3 YAML that passes validation\n- Use proper JSON Schema for all data models\n- Include realistic example values, not placeholders\n- Define reusable components to avoid duplication\n- Add appropriate data validation (required fields, formats, constraints)\n- Include security requirements where applicable\n\nFocus on: ${input:endpoint_focus:Which specific endpoint or endpoints should be documented?}\n\nGenerate production-ready OpenAPI specification that can be used with Swagger UI, Postman, and code generators.\n```\n\n## 如何使用此提示文件\n\n1. 将上述内容另存为 `document-api.prompt.md`，并将其保存在 `.github/prompts` 文件夹中。\n2. 在 Visual Studio Code 中，显示 副驾驶聊天 视图，然后输入 `/document-api`。 （可选）也可以通过键入 `endpoint_focus=GET /activities` 等内容，指明要为其创建文档的具体终结点。\n\n## 其他阅读材料\n\n* Visual Studio Code 文档中的[使用 Visual Studio Code 中的提示文件](https://code.visualstudio.com/docs/copilot/customization/prompt-files) - 有关如何创建和使用提示文件的信息\n* [关于自定义GitHub Copilot 响应](/zh/copilot/concepts/response-customization) - GitHub Copilot 中的响应自定义概述\n* [出色的 GitHub Copilot 自定义内容](https://github.com/github/awesome-copilot/blob/main/docs/README.prompts.md) - 社区提供的自定义提示文件的仓库以及特定语言和场景的其他自定义内容"}