很多时候,Swagger定义的标准并不能满足我们实际的需求,比如拿分组后的接口来说,有适合我们希望我们的接口能够排序,假如我们当前有一个注册的需求实现,那么他的接口可能是这样的:
1.获取验证码 -> 2.校验用户名是否有效 -> 3.注册验证 -> 4.登录
如果我们没有排序的情况下,上面的接口对于开发人员来说可能是杂乱无章的,对于初级的接口对接人员来说,排序更能让开发者把当前的需求清晰明了的用代码来实现掉,为此,接口文档的作用也能最大化.
那么,在swagger的标准中,那些允许我们自定义扩展,在Springfox中我们又如何来实现我们的自定义扩展呢?
Swagger标准
先来看Swagger定义的几个标准属性,可参考官方文档
swagger | string |
Required. Specifies the Swagger Specification version being used. It can be used by the Swagger UI and other clients to interpret the API listing. The value MUST be "2.0" . |
---|---|---|
info | Info Object | Required. Provides metadata about the API. The metadata can be used by the clients if needed. |
host | string |
The host (name or ip) serving the API. This MUST be the host only and does not include the scheme nor sub-paths. It MAY include a port. If the host is not included, the host serving the documentation is to be used (including the port). The host does not support path templating. |
basePath | string |
The base path on which the API is served, which is relative to the host . If it is not included, the API is served directly under the host . The value MUST start with a leading slash (/ ). The basePath does not support path templating. |
schemes | [string ] |
The transfer protocol of the API. Values MUST be from the list: "http" , "https" , "ws" , "wss" . If the schemes is not included, the default scheme to be used is the one used to access the Swagger definition itself. |
consumes | [string ] |
A list of MIME types the APIs can consume. This is global to all APIs but can be overridden on specific API calls. Value MUST be as described under Mime Types. |
produces | [string ] |
A list of MIME types the APIs can produce. This is global to all APIs but can be overridden on specific API calls. Value MUST be as described under Mime Types. |
paths | Paths Object | Required. The available paths and operations for the API. |
definitions | Definitions Object | An object to hold data types produced and consumed by operations. |
parameters | Parameters Definitions Object | An object to hold parameters that can be used across operations. This property does not define global parameters for all operations. |
responses | Responses Definitions Object | An object to hold responses that can be used across operations. This property does not define global responses for all operations. |
securityDefinitions | Security Definitions Object | Security scheme definitions that can be used across the specification. |
security | [Security Requirement Object] | A declaration of which security schemes are applied for the API as a whole. The list of values describes alternative security schemes that can be used (that is, there is a logical OR between the security requirements). Individual operations can override this definition. |
tags | [Tag Object] | A list of tags used by the specification with additional metadata. The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used by the Operation |