{"meta":{"title":"创建问题","intro":"副驾驶聊天 可以帮助你快速创建问题，而不需要你手动填写每一字段。","product":"GitHub Copilot","breadcrumbs":[{"href":"/zh/copilot","title":"GitHub Copilot"},{"href":"/zh/copilot/tutorials","title":"教程"},{"href":"/zh/copilot/tutorials/copilot-chat-cookbook","title":"GitHub Copilot Chat 指南"},{"href":"/zh/copilot/tutorials/copilot-chat-cookbook/document-code","title":"文档编码"},{"href":"/zh/copilot/tutorials/copilot-chat-cookbook/document-code/creating-issues","title":"创建问题"}],"documentType":"article"},"body":"# 创建问题\n\n副驾驶聊天 可以帮助你快速创建问题，而不需要你手动填写每一字段。\n\n手动创建问题可能非常耗时。 利用 副驾驶聊天，可以采用自然语言创建问题，并根据提示自动填写标题、正文、标签及其他元数据。\n\n## 示例方案\n\n你正在开发一个 API 服务，需要在`createUser`接口上添加服务器端验证。 与其手动起草问题，不如使用 副驾驶聊天 生成详细的问题说明，其中包括验证中间件的示例实现。\n\n以下代码片段展示了在添加验证之前，`createUser` 路由的当前实现：\n\n```javascript\n// Route\napp.post('/users', validateCreateUser, (req, res) => {\n  const { username, email } = req.body;\n  // Simulate user creation\n  res.status(201).json({ message: 'User created', user: { username, email } });\n});\n```\n\n## 示例提示\n\n`In octo-org/octo-repo, create an issue to add server-side validation for the createUser API endpoint. Include an example of how to validate the request body using an existing middleware pattern. Label it with \"backend\" and \"enhancement\".`\n\n## 示例响应\n\n> [!NOTE] 以下响应是示例。 副驾驶聊天 的回答是不确定的，因此你可能会得到与这里所显示的不同的回答。\n\n提交提示后，副驾驶聊天 会根据描述生成问题草稿，并包括代码片段。 可以在创建问题之前查看和编辑草稿。\n\n```markdown\n## Problem\nThe `createUser` API endpoint currently lacks robust server-side validation for incoming requests. To ensure data integrity and security, we should validate the request body before proceeding with user creation.\n\n**Current API endpoint:**\n// Route\napp.post('/users', validateCreateUser, (req, res) => {\n  const { username, email } = req.body;\n  // Simulate user creation\n  res.status(201).json({ message: 'User created', user: { username, email } });\n});\n\n## Proposal\n- Add server-side validation for the request body using the existing middleware pattern.\n- Ensure required fields (`username`, `email`) are present and valid.\n- Return a 400 Bad Request response if validation fails.\n\n**Example (middleware pattern):**\nfunction validateCreateUser(req, res, next) {\n  const { username, email } = req.body;\n  if (!username || !email) {\n    return res.status(400).json({ error: 'Username and email are required.' });\n  }\n  // Additional validation logic here\n  next();\n}\n\napp.post('/users', validateCreateUser, (req, res) => {\n  // ...\n});\n\n## Acceptance Criteria\n- Server-side validation middleware is added to the `createUser` endpoint.\n- Request body is properly validated.\n- Appropriate error responses are returned for invalid requests.\n```"}