对于一个较旧的网络框架项目,我使用Swashbuckle 5.6.0. 当我使用一个类作为get参数时,会发生一件奇怪的事情.它将变量名添加到参数中.
这意味着API的消费者必须添加"记录".放在每个论点的前面.真的很不方便.
对这种行为的解释是什么?
这是POCO班级:
public class AssetTransactionAllAssetsSearchRecord2
{
public AssetTransactionAllAssetsSearchRecord2() { }
public long Id { get; set; }
public DateTime FromCreated { get; set; }
public DateTime ToCreated { get; set; }
public long? DocumentId { get; set; }
public long AssetId { get; set; }
public long HostingAssetId { get; set; }
public long SystemAssetId { get; set; }
public long CustomerAssetId { get; set; }
public string AssetCode { get; set; }
public string HostingAssetCode { get; set; }
public string SystemAssetCode { get; set; }
public string CustomerAssetCode { get; set; }
public string AssetName { get; set; }
public string HostingAssetName { get; set; }
public string SystemAssetName { get; set; }
public string CustomerAssetName { get; set; }
}
以下是Swagger配置:
using System.Web.Http;
using WebActivatorEx;
using VI_Web;
using Swashbuckle.Application;
using Swashbuckle.Swagger;
using System.Collections.Generic;
using System.Web.Http.Description;
[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]
namespace VI_Web
{
class AuthTokenOperation : IDocumentFilter
{
public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer)
{
swaggerDoc.paths.Add("/token", new PathItem
{
post = new Operation
{
tags = new List<string> { "UserAuth" },
consumes = new List<string>
{
"application/x-www-form-urlencoded"
},
parameters = new List<Parameter> {
new Parameter
{
type = "string",
name = "grant_type",
required = true,
@in = "formData",
@default = "password"
},
new Parameter
{
type = "string",
name = "client_id",
required = true,
@in = "formData"
},
new Parameter
{
type = "string",
name = "client_secret",
required = true,
@in = "formData"
},
new Parameter
{
type = "string",
name = "database",
required = true,
@in = "formData"
}
}
}
});
}
}
public class SwaggerConfig
{
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "VI_Web");
c.ApiKey("Token")
.Description("Filling bearer token here")
.Name("Authorization")
.In("header");
c.DocumentFilter<AuthTokenOperation>();
})
.EnableSwaggerUi(c =>
{
c.EnableApiKeySupport("Authorization", "header");
});
}
}
}