swagger例子

Data Types

Primitive data types in the Swagger Specification are based on the types supported by the JSON-Schema Draft 4. Models are described using the Schema Object which is a subset of JSON Schema Draft 4.

An additional primitive data type "file" is used by the Parameter Object and the Response Object to set the parameter type or the response as being a file.

Primitives have an optional modifier property format. Swagger uses several known formats to more finely define the data type being used. However, the format property is an open string-valued property, and can have any value to support documentation needs. Formats such as "email""uuid", etc., can be used even though they are not defined by this specification. Types that are not accompanied by a format property follow their definition from the JSON Schema (except for file type which is defined above). The formats defined by the Swagger Specification are:

Common Name type format Comments
integer integer int32 signed 32 bits
long integer int64 signed 64 bits
float number float  
double number double  
string string    
byte string byte base64 encoded characters
binary string binary any sequence of octets
boolean boolean    
date string date As defined by full-date - RFC3339
dateTime string date-time As defined by date-time - RFC3339
password string password Used to hint UIs the input needs to be obscured.
  /login:
    post:
      parameters:
        - in: formData
          name: account
          description: phone num
          type: string
          default: "13800138000"
        - in: formData
          name: password
          type: string
          format: password
          required: true
      responses:
        200:
          description: Echo test-path
          schema:
            $ref: "#/definitions/response"
          examples:
            application/json:
              {
                code: 404,
                message: 接口不存在,
                result:
                {
                  request: null,
                  code: 123456
                }
              }
definitions:
  response:
    type: object
    properties:
      code:
        type: integer
        description: 错误码
      message:
        type: string
        description: 错误信息
      result:
        type: object
        properties:
          request:
            type: object

Parameter Types

Swagger distinguishes between the following parameter types based on the parameter location. The location is determined by the parameter’s in key, for example, in: query or in: path.

  • query parameters, such as /users?role=admin            in: query
  • path parameters, such as /users/{id}            in: path
  • header parameters, such as X-MyHeader: Value           in: header
  • body parameters that describe the body of POST, PUT and PATCH requests (see Describing Request Body)      in: body
  • form parameters – a variety of body parameters used to describe the payload of requests with Content-Type of application/x-www-form-urlencoded and multipart/form-data (the latter is typically used for file uploads)           in: formData

Required and Optional Parameters

Default Parameter Values

Enum Parameters

The enum keyword allows you to restrict a parameter value to a fixed set of values. The enum values must be of the same type as the parameter type.

        - in: query
          name: status
          type: string
          enum: [available, pending, sold]

More info: Defining an Enum.

时间: 2024-08-03 09:03:31

swagger例子的相关文章

Swagger入门教程

[译]5.41 Swagger tutorial 单击此处查看原文 更多概念参见:Implementing Swagger with your API docs 关于 Swagger Swagger能成为最受欢迎的REST APIs文档生成工具之一,有以下几个原因: Swagger 可以生成一个具有互动性的API控制台,开发者可以用来快速学习和尝试API. Swagger 可以生成客户端SDK代码用于各种不同的平台上的实现. Swagger 文件可以在许多不同的平台上从代码注释中自动生成. Sw

Spring MVC中使用Swagger生成API文档和完整项目示例Demo,swagger-server-api

本文作者:小雷FansUnion-一个有创业和投资经验的资深程序员-全球最大中文IT社区CSDN知名博主-排名第119 实际项目中非常需要写文档,提高Java服务端和Web前端以及移动端的对接效率. 听说Swagger这个工具,还不错,就网上找了些资料,自己实践了下. 一:Swagger介绍 Swagger是当前最好用的Restful API文档生成的开源项目,通过swagger-spring项目 实现了与SpingMVC框架的无缝集成功能,方便生成spring restful风格的接口文档,

第四章 springboot + swagger(转载)

此篇博客转发自:http://www.cnblogs.com/java-zhao/p/5348113.html swagger用于定义API文档. 好处: 前后端分离开发 API文档非常明确 测试的时候不需要再使用URL输入浏览器的方式来访问Controller 传统的输入URL的测试方式对于post请求的传参比较麻烦(当然,可以使用postman这样的浏览器插件) spring-boot与swagger的集成简单的一逼 1.项目结构 和上一节一样,没有改变. 2.pom.xml 引入了两个ja

利用Swagger Maven Plugin生成Rest API文档

利用Swagger Maven Plugin生成Rest API文档 Swagger Maven Plugin This plugin enables your Swagger-annotated project to generate Swagger specs and customizable, templated static documents during the maven build phase. Unlike swagger-core, swagger-maven-plugin

Swagger - 前后端分离后的契约

http://www.cnblogs.com/whitewolf/p/4686154.html 按照现在的趋势,前后端分离几乎已经是业界对开发和部署方式所达成的一种共识.所谓的前后端分离,并不是传统行业中的按部门划分,一部分人只做前端(HTML/CSS/JavaScript等等),另一部分人只做后端(或者叫服务端),因为这种方式是不工作的:比如很多团队采取了后端的模板技术(JSP, FreeMarker, ERB等等),前端的开发和调试需要一个后台Web容器的支持,从而无法将前后端开发和部署做到

微服务架构实战:Swagger规范RESTful API

转载本文需注明出处:EAII企业架构创新研究院,违者必究.如需加入微信群参与微课堂.架构设计与讨论直播请直接回复公众号:"EAII企业架构创新研究院".(微信号:eaworld)   导读:本文是EAII微服务系列文章之一.随着微服务架构的流行,REST风格也是大势所趋.那么,什么是REST?如何规范我们的RESTFUL API 文档?本文中,作者主要基于以上两个话题进行讨论并探讨在数字化企业云平台实践中如何规范RESTful文档. REST的引入 随着微服务架构的广泛流行,REST风

利用swagger模块开发flask的api接口帮助文档

swagger官网称其为世界最流行的api工具.用过的都说好.我已经深有体会. 附上官网编辑页面.只需要拷贝相应的文件就可以实现效果 swagger在线编辑器 下面主要讲解一下在python的flask框架下,如何使用这款屌炸天的应用. 1.安装flasgger 项目地址https://github.com/rochacbruno/flasgger pip install flasgger 2.写一个简单的web例子. 以下是简写代码 #coding:utf8 import sys reload

(Swagger)一个终端和后台开发对api接口管理工具

Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件的方法,参数和模型紧密集成到服务器端的代码,允许API来始终保持同步.Swagger 让部署管理和使用功能强大的API从未如此简单. 为了方便的管理项目中API接口,在网上找了好多关于API接口管理的资料,感觉目前最流行的莫过于Swagger了,功能强大,UI界面漂亮,并且支持在线测试等等 Swagger – The World

使用 Swagger 自动生成 ASP.NET Core Web API 的文档、在线帮助测试文档(ASP.NET Core Web API 自动生成文档)

对于开发人员来说,构建一个消费应用程序时去了解各种各样的 API 是一个巨大的挑战.在你的 Web API 项目中使用 Swagger 的 .NET Core 封装 Swashbuckle 可以帮助你创建良好的文档和帮助页面. Swashbuckle 可以通过修改 Startup.cs 作为一组 NuGet 包方便的加入项目.Swashbuckle 是一个开源项目,为使用 ASP.NET Core MVC 构建的 Web APIs 生成 Swagger 文档.Swagger 是一个机器可读的 R