【发布时间】:2021-10-14 16:36:23
【问题描述】:
我在 OpenAPI 中定义了以下组件:
Template:
type: object
properties:
Callback:
description: 'If set, this url will be called with a POST when a job completes. If the text "{guid}" is in the url, that text will be replaced with the Guid for the callback.'
type: string
OutputFormat:
type: string
description: 'Generate the document in the provided format.'
enum: [pdf, docx, xlsx, pptx, txt, html, prn, csv, rtf, jpg, png, svg, eps, bmp, gif]
Data:
description: 'The source of the template- embedded or external. Embed template as a Base64-encoded string.'
type: string
format: base64
ConnectionString:
description: "Set this to provide the template as a connection string of the template's location."
type: string
Format:
type: string
description: 'Format of the template. Auto-determined if not provided.'
enum: [docx, html, xlsx, pptx]
Properties:
description: "Windward properties for this document. These override any properties set in the configuration file on the server side."
type: array
items:
$ref: '#/components/schemas/Property'
xml:
wrapped: true
Parameters:
description: "A set of input parameters for this document. The parameters are global and shared among all data sources."
type: array
items:
$ref: '#/components/schemas/Parameter'
xml:
wrapped: true
Datasources:
description: "The datasources to apply to the template. The datasources are applied simultaneously."
type: array
items:
$ref: '#/components/schemas/Datasource'
xml:
wrapped: true
Tag:
type: string
description: "Anything you want. This is passed in to the repository & job handlers and is set in the final generated document object. The RESTful engine ignores this setting, it is for the caller's use."
TrackImports:
type: boolean
description: "Return all imports with the generated document."
TrackErrors:
type: integer
minimum: 0
maximum: 3
description: "Enable or disable the error handling and verify functionality."
MainPrinter:
type: string
description: "If you are using printer output use to specify main printer. Printer must be recognized by Network"
FirstPagePrinter:
type: string
description: "Set first page printer if main printer is already set"
PrinterJobName:
type: string
description: "Assign print job name"
PrintCopies:
type: integer
description: "Set number of copies to print"
PrintDuplex:
type: string
description: "Selects the printer duplex mode. Only if supported by the printer."
如果您查看Datasources 条目,它是Datasource 组件的数组:
Datasources:
description: "The datasources to apply to the template. The datasources are applied
simultaneously."
type: array
items:
$ref: '#/components/schemas/Datasource'
我正在尝试为 POST 请求定义一个示例请求正文(您发送的正文是我在上面显示的模板组件)。当我尝试定义示例值时,它看起来是这样的:
这就是它呈现的内容:
问题在于它将其显示为字典字典(带有“{}”括号)。我需要它是一个字典数组(外面有“[]”)。有谁知道怎么做?
我试过这样做:
但 Swagger 编辑器不喜欢这样。有什么想法吗?
为了更清楚,这就是我想要做的:
# I NEED THIS
Datasources: [
Datasource: {
Name: "...",
Type: "..."
}
]
# INSTEAD OF THIS
Datasources: {
Datasource: {
Name: "...",
Type: "..."
}
}
【问题讨论】: