linux

Linux环境下Swagger API文档格式规范

小樊
34
2025-12-27 17:44:49
栏目: 智能运维

Linux环境下Swagger API文档格式规范

一 规范总览与版本选择

二 文件结构与必填字段规范

openapi: 3.0.0
info:
  title: 示例 API
  version: 1.0.0
  description: API 文档规范示例
servers:
  - url: http://localhost:3000/api/v1
    description: 本地开发环境
paths:
  /users:
    get:
      summary: 获取用户列表
      description: 返回用户基本信息
      operationId: getUsers
      tags:
        - 用户
      parameters:
        - name: page
          in: query
          schema:
            type: integer
            minimum: 1
          description: 页码
          required: false
      responses:
        '200':
          description: 成功返回用户列表
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/User'
        '400':
          $ref: '#/components/responses/BadRequest'
components:
  schemas:
    User:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
          example: 1
        name:
          type: string
          example: 张三
        email:
          type: string
          format: email
          example: user@example.com
  responses:
    BadRequest:
      description: 请求参数错误
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          example: 400
        message:
          type: string
          example: 参数校验失败

三 命名与语义规范

四 验证与本地预览

五 与常见框架的集成与输出规范

0
看了该问题的人还看了