简体   繁体   English

带有两个参数fromuri和frombody的Swagger-WebAPi

[英]Swagger-WebAPi with two params fromuri and frombody

I have an API with two params, the first is from URI the second from the Body, the generated doc with swagger take all params from URI, it doesn't put the body params in the body. 我有一个带有两个参数的API,第一个是来自URI的,第二个是来自Body的,生成的带有swagger的文档从URI中获取所有参数,它没有将body的参数放入体内。 Is it a limit for swagger or should I add some configuration? 这是招摇的极限还是我应该添加一些配置?

public IHttpActionResult Put([FromUri] string id, [FromBody] string name, [FromBody] bool activate = false)
{
    return Ok();
}

Thanks. 谢谢。

You cannot have more than one [FromBody] used in your method signature. 方法签名中不能使用多个[FromBody]。 If you have multiple values, you should just encapsulate into an object to your liking :) 如果您有多个值,则应根据自己的喜好将其封装到一个对象中:)

https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api https://docs.microsoft.com/zh-cn/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM