Swagger:在哪里提供样本 json 进行调用?
Swagger: where to provide sample json for a call?
我是 swagger 的新手,我正在尝试开始记录 API。我想在我的文档中包含 requests/responses 的示例,而不仅仅是模式定义本身。
响应对象上有一个 "examples" 功能,但是,当我填写它时,它不会显示在生成的文档中的任何地方。这只是swagger暂时缺少的功能,还是我使用不正确?
这是我的规范(我知道我还没有正确实施安全性):
swagger: '2.0'
schemes: ['https']
info:
version: 1.0.0.0
title: 'Test API'
contact:
name: Support
url: 'www.nowhere.com'
email: 'test@example.com'
consumes: ['application/json']
produces: ['application/json']
paths:
/Variables:
get:
summary:
Returns the list of all variables in the system.
description:
Returns the list of all variables in the system.
tags: ['Variables']
consumes: ['application/json']
produces: ['application/json']
parameters:
- name: "Authorization"
in: header
description: "Provide the OAuth access token in the format of: Bearer token_value"
type: string
responses:
'200':
description: Successful response
schema:
$ref: '#/definitions/Variables'
examples:
application/json:
VariableToken: Name
VariableGroupName: Main
DataType: text
VariableDisplayName: Name
definitions:
Variables:
type: array
items:
title: Variable
type: object
properties:
VariableToken:
type: string
format: string
VariableGroupName:
type: string
format: string
DataType:
type: string
format: string
VariableDisplayName:
type: string
format: string
我想通了。我将我的示例放在正确的位置,但是,Swagger Editor 不会在预览中显示它 window。然而,Swagger UI 将使用给定的信息生成 UI。
我是 swagger 的新手,我正在尝试开始记录 API。我想在我的文档中包含 requests/responses 的示例,而不仅仅是模式定义本身。
响应对象上有一个 "examples" 功能,但是,当我填写它时,它不会显示在生成的文档中的任何地方。这只是swagger暂时缺少的功能,还是我使用不正确?
这是我的规范(我知道我还没有正确实施安全性):
swagger: '2.0'
schemes: ['https']
info:
version: 1.0.0.0
title: 'Test API'
contact:
name: Support
url: 'www.nowhere.com'
email: 'test@example.com'
consumes: ['application/json']
produces: ['application/json']
paths:
/Variables:
get:
summary:
Returns the list of all variables in the system.
description:
Returns the list of all variables in the system.
tags: ['Variables']
consumes: ['application/json']
produces: ['application/json']
parameters:
- name: "Authorization"
in: header
description: "Provide the OAuth access token in the format of: Bearer token_value"
type: string
responses:
'200':
description: Successful response
schema:
$ref: '#/definitions/Variables'
examples:
application/json:
VariableToken: Name
VariableGroupName: Main
DataType: text
VariableDisplayName: Name
definitions:
Variables:
type: array
items:
title: Variable
type: object
properties:
VariableToken:
type: string
format: string
VariableGroupName:
type: string
format: string
DataType:
type: string
format: string
VariableDisplayName:
type: string
format: string
我想通了。我将我的示例放在正确的位置,但是,Swagger Editor 不会在预览中显示它 window。然而,Swagger UI 将使用给定的信息生成 UI。