C# 斯威格认为有效载荷来自;查询「;

C# 斯威格认为有效载荷来自;查询「;,c#,asp.net,asp.net-mvc,swagger,nswag,C#,Asp.net,Asp.net Mvc,Swagger,Nswag,我有一个带有简单RESTAPI的aspnet核心项目 NSwag被用作招摇过市的工具,它的工作原理基于我对模型和控制器方法的修饰: [Route("api/v2/")] public class JobCollectionsControllerV2 : Controller { [HttpPut] [Route("tenants/{tenant}/collections/{collection}")] [SwaggerResponse(typeof(JobCollecti

我有一个带有简单RESTAPI的aspnet核心项目

NSwag被用作招摇过市的工具,它的工作原理基于我对模型和控制器方法的修饰:

[Route("api/v2/")]
public class JobCollectionsControllerV2 : Controller
{
    [HttpPut]
    [Route("tenants/{tenant}/collections/{collection}")]
    [SwaggerResponse(typeof(JobCollectionDtoV2))]
    public async Task<IActionResult> CreateTask(JobCollectionDtoV2 collectionParams)
    {
        // removed
    }
}

public class JobCollectionDtoV2
{
    [Required]
    [FromRoute]
    [RegularExpression("^[a-z][a-z0-9]+$")]
    [StringLength(maximumLength: 24, MinimumLength = 3)]
    public string Collection { get; set; }

    [Required]
    [FromRoute]
    [RegularExpression("^[a-z][a-z0-9]+$")]
    [StringLength(maximumLength: 24, MinimumLength = 3)]
    public string Tenant { get; set; }

    [Required]
    [FromBody]
    public JobCollectionDetails CollectionDetails { get; set; }

    public override string ToString()
    {
        return JsonConvert.SerializeObject(this);
    }
}

public class JobCollectionDetails
{
    [Required]
    public bool Enabled { get; set; }

    [Required]
    [CollectionFrequency]
    public TimeSpan Frequency { get; set; }
}
看起来不错,除了以下部分,该部分指定
collectionDetails
应该来自查询参数,而不是主体

            {
                "type": "object",
                "name": "collectionDetails",
                "in": "query",  <<<<-------------- SHOULD BE 'body' or something like that
                "required": true,
                "x-schema": {
                    "$ref": "#/definitions/JobCollectionDetails"
                },
                "x-nullable": true
            }

我已经将NSwag库更新到最新的v12版本(从v11版本开始),问题得到了解决--
查询
确实被
正文
所取代


没有进行任何其他更改。

我已将NSwag库更新为最新的v12(从v11开始),问题已得到解决--
查询
确实被
正文


未进行任何其他更改。

您能否显示中间件如何在Startup中注册。csI已更新为NSwag v12,问题已得到解决您能否显示中间件如何在Startup中注册。csI已更新为NSwag v12,问题已得到解决
            {
                "type": "object",
                "name": "collectionDetails",
                "in": "query",  <<<<-------------- SHOULD BE 'body' or something like that
                "required": true,
                "x-schema": {
                    "$ref": "#/definitions/JobCollectionDetails"
                },
                "x-nullable": true
            }
    public void ConfigureServices(IServiceCollection services)
    {
        if (_env.IsDevelopment())
        {
            services.AddMvc();
            services.AddSwaggerDocument();
        }
    }


    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            _loggerFactory.AddDebug();
            app.UseDeveloperExceptionPage();

            app.UseSwagger(settings =>
            {
                settings.PostProcess = (document, request) =>
                {
                    document.Info.Version = _context.CodePackageActivationContext.CodePackageVersion;
                    document.Info.TermsOfService = "None";
                    document.Info.Contact = new SwaggerContact
                    {
                    };
                };
            });

            app.UseSwaggerUi3();
        }
    }