Swagger-editor使用openapi3.0编写的demo

来源:互联网 发布:情侣礼物知乎 编辑:程序博客网 时间:2024/05/18 20:12
openapi: 3.0.0
info:
  description: <p>Springboot 整合swagger demo,使用swagger2构建restful api . <p> Created by 赵建强
  version: 1.0.1
  title: 'Swagger editor demo '
  contact:
    name: 联系开发人员
    email: zhaojianqiang@viewhigh.com
servers:
  - url: 'http://{domain}:{port}/{basePath}'
    description: http请求
    variables:
      domain:
        default: api1.viewhigh.com
        description: HTTP API请求域名
      port:
        enum:
          - '9080'
          - '9081'
        default: '9080'
      basePath:
        default: v1.0
  - url: 'https://{domain}:{port}/{basePath}'
    description: https请求
    variables:
      domain:
        default: api1.viewhigh.com
        description: HTTPs API请求域名
      port:
        enum:
          - '9080'
          - '9081'
        default: '9080'
      basePath:
        default: v1.0
tags:
  - name: user
    description: 用户相关操作
components:
  schemas:
    ErrorCode:
      type: integer
      format: int64
      enum:
        - 0
        - 10001
        - 10002
      description: |
        用户请求返回的信息码
          * 0:请求成功 
          * 10001:用户名不存在
          * 10002:用户密码错误
    ResultMessage:
      type: object
      properties:
        code:
          $ref: '#/components/schemas/ErrorCode'
        message:
          description: 错误信息描述
          type: string
        ret:
          type: object
          description: 请求返回的内容(JSON类型)
    User:
      type: object
      properties:
        id:
          description: 主键ID
          type: string
          format: uuid
        username:
          description: 用户登录名
          type: string
        password:
          description: 密码
          type: string
        email:
          description: 用户邮箱
          type: string
        phone:
          description: 联系电话
          type: string
        rowState:
          type: integer
          enum:
            - 0
            - 1
            - 2
          description: |
            用户状态 
            <table>
              <tr>
              <td>枚举字段</td><td>枚举字段说明</td>
              </tr>
              <tr><td>0 </td><td>未启用 </td></tr>
              <tr><td>1 </td><td>启用 </td></tr>
              <tr><td>2 </td><td>删除 </td></tr>
            </table>
paths:
  /user:
    post:
      tags:
        - user
      summary: add user
      description: 新增用户信息
      operationId: addUser
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/User'
      responses:
        default:
          description: 请求成功后返回的内容
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    $ref: '#/components/schemas/ErrorCode'
                  message:
                    description: 错误信息描述
                    type: string
                  ret:
                    type: object
                    description: 请求返回的内容(JSON类型)
                example:
                  code: 0
                  message: 请求成功
                  ret:
                    id: 创建的用户的主键ID
    get:
      tags:
        - user
      summary: 批量获取用户信息
      deprecated: true
      responses:
        default:
          description: 请求成功后返回的内容
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/User'
  '/user/{userId}':
    get:
      tags:
        - user
      summary: find user by id
      description: 根据ID获取用户信息
      operationId: findUserById
      parameters:
        - name: userId
          in: path
          description: 用ID
          required: true
          schema:
            type: string
      responses:
        '400':
          description: 请求失败
        default:
          description: 请求成功后返回的内容
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    $ref: '#/components/schemas/ErrorCode'
                  message:
                    description: 错误信息描述
                    type: string
                  ret:
                    type: object
                    description: 请求返回的内容(JSON类型)
                example:
                  code: 0
                  message: 操作成功
                  ret:
                    user:
                      id: uuid
                      username: 用户登录名
                      password: 用户密码
                      email: 用户邮箱
                      phone: 用户手机号码
                      rowstate: 0
    put:
      tags:
        - user
      summary: update user
      description: 修改用户信息
      operationId: updateUser
      parameters:
        - name: userId
          in: path
          description: 用ID
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/User'
      responses:
        default:
          description: 操作请求成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    $ref: '#/components/schemas/ErrorCode'
                  message:
                    description: 错误信息描述
                    type: string
                  ret:
                    type: object
                    description: 请求返回的内容(JSON类型)
                example:
                  code: 0
                  message: 操作成功
                  ret:
                    user:
                      id: uuid
                      username: 用户登录名
                      password: 用户密码
                      email: 用户邮箱
                      phone: 用户手机号码
                      rowstate: 0
    delete:
      tags:
        - user
      summary: delete user
      description: 删除用户信息
      operationId: deleteUser
      parameters:
        - name: userId
          in: path
          description: 用ID
          required: true
          schema:
            type: string
      responses:
        default:
          description: 操作请求成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    $ref: '#/components/schemas/ErrorCode'
                  message:
                    description: 错误信息描述
                    type: string
                  ret:
                    type: object
                    description: 请求返回的内容(JSON类型)
                example:
                  code: 0
                  message: 请求成功
                  ret:
                    id: 删除的ID
externalDocs:
  url: 'http://www.viewhigh.com'
  description: '@东软望海'
原创粉丝点击