.NET中有哪个等效于Net Core中的"ProducesResponseType"?

3

我需要从使用NET CORE构建的API进行“反向”转换到.NET

我遇到了一个问题,就是如何将Net Core中的[ProducesResponseType]修改为在.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 Standard 2.0库。 - magicandre1981
@magicandre1981,那么我可以在我的 .Net 项目中使用 Net Core nuget 吗? - ParticleDuality
1
一个兼容 .NET Standard 2.0 的 .NET Framework 可以使用该库。在 此页面 上,您可以看到通过 NuGet 包可用于 .NET Standard 2.0 的类型。因此,始终查看 API 页面以查看 API 是否可用。 - magicandre1981
1
属性定义肯定可以链接到框架程序集,唯一的问题是它在那里有多大的作用。例如,框架Swashbuckle不理解核心属性。(提示: https://mattfrear.com/2015/04/21/generating-swagger-example-responses-with-swashbuckle/ - 使用SwaggerResponse属性代替) - Yuri Makassiouk
1个回答

2

我在使用 .NET 4.6.1 成功地使用了来自 System.Web.Http.Description[ResponseType(typeof(SomeClass))]


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,