Swagger 参数和复杂类型 [英] Swagger Parameters and Complex Types
本文介绍了Swagger 参数和复杂类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在以下 Swagger 定义中,我需要参数 labelValue
的类型为 LabelValueObject
,以便对其进行验证并正确反序列化.但是,我无法弄清楚语法!怎么做?
In the following Swagger definition, I need the parameter labelValue
to be of type LabelValueObject
, so that it will be validated and correctly deserialized. However, I can't figure out the syntax! How can that be done?
swagger: "2.0"
paths:
/competition:
post:
parameters:
- name: labelValue
in: formData
type: array
items:
type: string ### this has to be a LabelValueObject ###
responses:
default:
description: Error
schema:
$ref: "#/definitions/AnyResponse"
definitions:
AnyResponse:
properties:
any:
type: string
LabelValueObject:
properties:
label:
type: string
value:
type: string
required:
- label
- value
推荐答案
将对象作为参数传递的唯一方法是将其放入正文 (in: body
) 然后定义这个schema
中的对象(使用 $ref
内联定义或引用预定义的对象).这是一个完整的示例:
The only way to pass an object as a parameter is to put it in the body (in: body
) and then define this object in schema
(inline definition or reference to an predefined object with $ref
). Here's a full example:
swagger: "2.0"
info:
title: A dummy title
version: 1.0.0
paths:
/competition:
post:
parameters:
- name: labelValue
in: body
schema:
$ref: '#/definitions/LabelValueObject'
responses:
default:
description: Error
schema:
$ref: "#/definitions/AnyResponse"
definitions:
AnyResponse:
properties:
any:
type: string
LabelValueObject:
properties:
label:
type: string
value:
type: string
required:
- label
- value
这篇关于Swagger 参数和复杂类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文