在我希望查询中的参数为long
(C#)列表的情况下,我很难弄清楚什么是正确的Swagger 2.0规范。这是我根据看到的示例进行尝试的示例,其中在查询中传递的参数是简单的数据类型,例如int
或boolean
。但这似乎不起作用。看起来好像没有正确解析。
在我的API级测试中,在 api-version = 2016-09-13&featureIds =
部分之后,它没有解决任何相似的问题 "get": {
"tags": [
"FeatureText"
],
"operationId": "RenderFeatureTexts",
"description": "The operation to get feature texts for specified features",
"parameters": [
{
"name": "featureIds",
"in": "query",
"required": true,
"schema": {
"type": "array",
"collectionFormat": "multi",
"items": {
"type": "integer",
"format": "int64"
}
},
.......
Swagger Codegen生成的C#代码:
public static async System.Threading.Tasks.Task<object> ListFeatureTextsAsync(this IAgentClient operations, object featureIds, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
using (var _result = await operations.ListFeatureTextsWithHttpMessagesAsync(featureIds, null, cancellationToken).ConfigureAwait(false))
{
return _result.Body;
}
}
答案 0 :(得分:1)
如下所示更改参数定义,即将type
,items
和collectionFormat
移出schema
。在OpenAPI 2.0中,schema
仅用于主体参数,其他参数类型直接使用type
等。
"parameters": [
{
"name": "featureIds",
"in": "query",
"required": true,
"type": "array",
"collectionFormat": "multi",
"items": {
"type": "integer",
"format": "int64"
}
通过将规范粘贴到Swagger Editor中,您可以轻松捕获此类语法错误。