Odata 无法使用多个HttpPut命令生成swagger
当我有多个HttpPut命令时,我无法让Swashback生成swagger.json。我正在使用OData4和ASP.NET Core 2.2。如果我对两个HttpPut方法中的一个进行注释,它将生成很好的结果。我尝试添加[SwaggerOperation(OperationId='')]属性,但没有成功。我尝试添加[ODataRoute(nameof())]属性,但没有成功。我尝试过编辑[HttpPut(nameof())]属性,但没有成功。我绞尽脑汁,试图找出让这项工作发挥作用的关键组合。欢迎提出任何建议Odata 无法使用多个HttpPut命令生成swagger,odata,asp.net-core-webapi,swagger-ui,swashbuckle,Odata,Asp.net Core Webapi,Swagger Ui,Swashbuckle,当我有多个HttpPut命令时,我无法让Swashback生成swagger.json。我正在使用OData4和ASP.NET Core 2.2。如果我对两个HttpPut方法中的一个进行注释,它将生成很好的结果。我尝试添加[SwaggerOperation(OperationId='')]属性,但没有成功。我尝试添加[ODataRoute(nameof())]属性,但没有成功。我尝试过编辑[HttpPut(nameof())]属性,但没有成功。我绞尽脑汁,试图找出让这项工作发挥作用的关键组合。
[ApiVersion("1.0")]
[ODataRoutePrefix("Items")]
public class ItemsController : ODataController {
[HttpGet]
[Produces("application/json")]
[ProducesResponseType(typeof(IQueryable<Item>), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[EnableQuery(AllowedQueryOptions = Select | OrderBy | Top | Skip | Count,
AllowedFunctions = AllowedFunctions.None,
AllowedArithmeticOperators = AllowedArithmeticOperators.None,
AllowedLogicalOperators = AllowedLogicalOperators.None,
AllowedOrderByProperties = "name,location",
MaxOrderByNodeCount = 2,
MaxTop = 100)]
public async Task<IActionResult> Get() {
...
}
[HttpGet]
[ODataRoute("({key})")]
[ProducesResponseType(typeof(Item), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> GetById(string key) {
...
}
[HttpPost]
[ODataRoute]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
public async Task<IActionResult> Post([FromBody] AddItemCommand command) {
...
}
[HttpPut]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
public async Task<IActionResult> StopMonitoring([FromBody] StopMonitoringCommand command) {
...
}
[HttpPut]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
public async Task<IActionResult> ChangeMonitoring([FromBody] ChangeMonitoringCommand command) {
...
}
}
[ApiVersion(“1.0”)]
[ODataRoutePrefix(“项目”)]
公共类项控制器:ODataController{
[HttpGet]
[产生(“应用程序/json”)]
[ProductsResponseType(typeof(IQueryable),(int)HttpStatusCode.OK)]
[产品响应类型((int)HttpStatusCode.BadRequest)]
[启用查询(AllowedQueryOptions=Select | OrderBy | Top | Skip | Count,
AllowedFunctions=AllowedFunctions.None,
AllowedArtimeticOperators=AllowedArtimeticOperators.None,
AllowedLogicalOperators=AllowedLogicalOperators.None,
AllowedOrderByProperties=“名称,位置”,
MaxOrderByNodeCount=2,
MaxTop=100)]
公共异步任务Get(){
...
}
[HttpGet]
[ODataRoute(“{key})”)]
[产品响应类型(项目类型),(int)HttpStatusCode.OK)]
[产品响应类型((int)HttpStatusCode.NotFound)]
公共异步任务GetById(字符串键){
...
}
[HttpPost]
[ODataRoute]
[产品响应类型((int)HttpStatusCode.OK)]
[产品响应类型((int)HttpStatusCode.BadRequest)]
公共异步任务发布([FromBody]AddItemCommand){
...
}
[HttpPut]
[产品响应类型((int)HttpStatusCode.OK)]
[产品响应类型((int)HttpStatusCode.BadRequest)]
公共异步任务StopMonitoring([FromBody]StopMonitoringCommand){
...
}
[HttpPut]
[产品响应类型((int)HttpStatusCode.OK)]
[产品响应类型((int)HttpStatusCode.BadRequest)]
公共异步任务ChangeMonitoring([FromBody]ChangeMonitoringCommand){
...
}
}
由于有两个HttpPut方法,它会失败,并显示“Fetch error undefined/swagger/v1/swagger.json”错误消息。@HelderSepulveda和提供了解决此问题的线索
无论它们是控制器上的HttpPut
还是HttpPost
,都可以通过将它们添加到控制器和OData模型配置中来添加操作
e、 g
@HelderSepulveda和其他人给了我解决这个问题的线索
无论它们是控制器上的HttpPut
还是HttpPost
,都可以通过将它们添加到控制器和OData模型配置中来添加操作
e、 g
打开
/swagger/v1/swagger.json
,它会给你更多的细节。。。但我建议不要在一个控制器上安装多个HttpPut,只需将第二个控制器移动到另一个控制器或其他控制器即可action@HelderSepulveda这可能是我的想法错误的地方。如果您有多个操作,它们是否只是具有不同路由的HttpPost方法,而不是HttpPut?我似乎找不到示例。打开/swagger/v1/swagger.json
它会给您提供更多详细信息。。。但我建议不要在一个控制器上安装多个HttpPut,只需将第二个控制器移动到另一个控制器或其他控制器即可action@HelderSepulveda这可能是我的想法错误的地方。如果您有多个操作,它们是否只是具有不同路由的HttpPost方法,而不是HttpPut?我似乎找不到例子。
public class ODataModelConfiguration : IModelConfiguration {
public void Apply(ODataModelBuilder builder, ApiVersion apiVersion) {
builder.EntitySet<Item>("Items");
builder.EntityType<Item>()
.Action("StopMonitoring")
.Parameter<StopMonitoringCommand>("command");
builder.EntityType<Item>()
.Action("ChangeMonitoring")
.Parameter<ChangeMonitoringCommand>("command");
}
}
[HttpPut]
[ODataRoute("StopMonitoring")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
public async Task<IActionResult> StopMonitoring([FromBody] StopMonitoringCommand command) {
...
}
[HttpPut]
[ODataRoute("ChangeMonitoring")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
public async Task<IActionResult> ChangeMonitoring([FromBody] ChangeMonitoringCommand command) {
...
}
GET /api/Items
POST /api/Items
GET /api/items({key})
PUT /api/items/StopMonitoring
PUT /api/items/ChangeMonitoring