前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >如何使用swagger editor 编写api yaml

如何使用swagger editor 编写api yaml

原创
作者头像
CoffeeLand
修改2020-04-03 17:40:17
1.4K0
修改2020-04-03 17:40:17
举报
文章被收录于专栏:CoffeeLand

Table of Contents

  • prerequesities
  • demo

prerequesities

swagger editor 2.0

Demo

代码语言:javascript
复制
swagger: '2.0'
info:
  description: API for user Service
  version: 1.0.0
  title: user Service API
basePath: /user-v1
schemes:
  - https
produces:
  - application/json
paths:
  /user:
    get:
      tags:
        - user
      summary: get all user info.
      description: >-
        get all user info.
      operationId: getUsers
      responses:
        '200':
          description: Successful response returns option key state
          schema:
            type: array
            items:
                $ref: '#/definitions/User'
                
definitions:
  User: 
    description: user object
    type: object
    properties:
      userId: 
        description: user uuid
        type: string
        example: "hjkhfkashfweuiorfjlsamfma"
      userName: 
        description: user name
        type: string
        example: "james"
      userAge:  
        description: user age
        type: integer
        example: 18
      userLoginStatus: 
        description: user login status
        type: string
        $ref: '#/definitions/UserLoginStatus'
  
  UserLoginStatus: 
    description: user login status
    type: string
    enum:
      - LOGINED
      - REGISTERED
  Order:
    description: user order
    type: object
    properties:
      orderId: 
        description: order uuid
        type: string
        example: "JD7832"
      orderName:  
        description: order name
        type: string
        example: basketball
  // create a map structure by using additionalProperties
  // https://support.reprezen.com/support/solutions/articles/6000162892-support-for-additionalproperties-in-swagger-2-0-schemas     
  UserOrderMap: 
    description: the map user to order
    type: object
    properties:
      userOrderMap: 
        type: object
        additionalProperties:
          $ref: '#/definitions/Order'
    
      

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Table of Contents
  • prerequesities
  • Demo
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档