OpenAPI 3.0.0 学习 之 新版本3.0通过SwaggerHub编写接口文档

一:打开swaggerhub官网登陆

  1. 在线编辑器地址:https://swagger.io/tools/swaggerhub/
  2. 操作前先登陆账号,没有账号者先注册相应账号,有github账号者可直接    

登陆

OpenAPI 3.0.0 学习 之 新版本3.0通过SwaggerHub编写接口文档_第1张图片

 

                                                                                     1-2-1 登陆

OpenAPI 3.0.0 学习 之 新版本3.0通过SwaggerHub编写接口文档_第2张图片

 

                                             1-2-2 点击swaggerhub

OpenAPI 3.0.0 学习 之 新版本3.0通过SwaggerHub编写接口文档_第3张图片

 

                                        1-2-3 github登陆

OpenAPI 3.0.0 学习 之 新版本3.0通过SwaggerHub编写接口文档_第4张图片

 

                                                                            1-2-4创建新api

 

 

 

二:编写API

OpenAPI 3.0.0 学习 之 新版本3.0通过SwaggerHub编写接口文档_第5张图片

 

                                     2-1 选择一份模板或者创建空的API

OpenAPI 3.0.0 学习 之 新版本3.0通过SwaggerHub编写接口文档_第6张图片

 

                                                                          2-2 修改后保存

OpenAPI 3.0.0 学习 之 新版本3.0通过SwaggerHub编写接口文档_第7张图片

 

                                               2-3

OpenAPI 3.0.0 学习 之 新版本3.0通过SwaggerHub编写接口文档_第8张图片

 

                                                 2-4 运行

OpenAPI 3.0.0 学习 之 新版本3.0通过SwaggerHub编写接口文档_第9张图片

 

                                                                         2-5 执行结果

 

附代码示例:

openapi: 3.0.0
# Added by API Auto Mocking Plugin
servers:
  - description: SwaggerHub API Auto Mocking
    url: https://virtserver.swaggerhub.com/Aokyz/demo/1.0.0
info:
  description: |
    This is a sample Petstore server.  You can find
    out more about Swagger at
    [http://swagger.io](http://swagger.io) or on
    [irc.freenode.net, #swagger](http://swagger.io/irc/).
  version: "1.0.0"
  title: Swagger Petstore
  termsOfService: 'http://swagger.io/terms/'
  contact:
    email: [email protected]
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
  - name: pet
    description: Everything about your Pets
    externalDocs:
      description: Find out more
      url: 'http://swagger.io'
  - name: store
    description: Access to Petstore orders
  - name: user
    description: Operations about user
    externalDocs:
      description: Find out more about our store
      url: 'http://swagger.io'
paths:
  /pet:
    get:
      tags:
        - pet
      summary: Find pet by ID
      description: Returns a single pet
      operationId: getPetById
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/User'
        '400':
          description: Invalid ID supplied
        '404':
          description: Pet not found
components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: integer
          description: The user ID.
        username:
          type: string
          description: The user name.

 

你可能感兴趣的:(API学习)