【发布时间】:2022-05-11 23:36:37
【问题描述】:
我必须从使用 NET CORE 制作的 API 到 .NET 进行“倒退”
我在将 [ProducesResponseType] 从 Net Core 更改为有效的 .NET 等效项时遇到问题
我有例如这个代码:
[ApiExplorerSettings(GroupName = "groupName")]
[ProducesResponseType(typeof(something), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(void), StatusCodes.Status500InternalServerError)]
[HttpPost("thing", Name = "creatingThisThing")]
public async Task<IHttpActionResult> PostThing([FromBody]dynamic value)
{
/// Other Stuff
我知道我可以避免使用组名,并且可以像这样调整路线:
[HttpPost]
[Route("", Name = "creatingThisThing")]
/// etc
但我想知道我可以用什么来“替换”前面提到的。
希望我已经足够清楚了。
【问题讨论】:
-
这是在 nuget 中定义的,它与完整的 .net 4.7/4.8 兼容,因为那些 .net 版本可以使用 .net 标准 2.0 库
-
@magicandre1981 那么,我可以在我的 .Net 项目中使用那个 Net Core nuget 吗?
-
兼容 .net 标准 2.0 的 .net 框架可以使用该库。在 this page 上,您会看到该类型可通过 nuget 包用于 .net 标准 2.0。因此,请始终查看 API 页面以查看 API 是否可用
-
属性定义肯定可以链接到框架组件,唯一的问题是它在那里有多大的好处。例如,Framework Swashbuckle 不了解核心属性。 (提示:mattfrear.com/2015/04/21/… - 改用 SwaggerResponse 属性)