我使用IdentityServer3来保护具有客户端凭据授权的Web API.对于文档我使用Swashbuckle但无法弄清楚如何在SwaggerConfig中为客户端凭据(应用程序)流启用Oauth2.任何帮助,将不胜感激!
我需要知道是否可以设置自定义operationid或命名约定,我的意思是我知道操作过滤器可以覆盖如何生成operationId的方式
using Swashbuckle.Swagger;
using System.Web.Http.Description;
namespace Something
{
public class MultipleOperationsWithSameVerbFilter : IOperationFilter
{
public void Apply(
Operation operation,
SchemaRegistry schemaRegistry,
ApiDescription apiDescription)
{
if (operation.parameters != null)
{
operation.operationId += "By";
foreach (var parm in operation.parameters)
{
operation.operationId += string.Format("{0}",parm.name);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在SwaggerConfig.cs中
c.OperationFilter<MultipleOperationsWithSameVerbFilter>();
Run Code Online (Sandbox Code Playgroud)
现在这有助于改变招摇的描述,请检查以下内容:
一切都很好,现在我最终在一个更黑暗的地方,例如类似于可能的情况:在同一个控制器上我有两个端点
这个例子不太正确(最后一篇文章应该是get)但仍然假设webapi无法更改(新的控制器用于分离)对于这个特殊情况我会试着找出一种方法来为每个动作以某种方式生成operationId diffrent,但我的问题是:
是否有可能以某种方式装饰与[JsonIgnore]或[Route("customer/delete")]类似的控制器动作,以明确有关operationId的信息.
c# asp.net-web-api swagger asp.net-web-api-routing swashbuckle
我在ASP.NET webapi项目中使用Swashbuckle 5并使用所有默认设置.它序列化我的方法的输出,以显示回复的模式.我收到的文档看起来像这样:
Response Class (Status 200)
Model Model Schema
[
{
"<Key>k__BackingField": "string",
"<Value>k__BackingField": "string",
"<Id>k__BackingField": 0
}
]
Run Code Online (Sandbox Code Playgroud)
这是通过遵循C#代码生成的
/// <summary>
/// Fetches all system configuration items
/// </summary>
/// <returns>List of <see cref="SystemConfigurationDto" /> items</returns>
public IList<SystemConfigurationDto> GetAllSystemConfigurationItems()
{
var result = CommandProcessor.ProcessCommand(new SystemConfigurationQueryCommand()) as SystemConfigurationQueryCommandResponse;
return result.Results.ToList();
}
Run Code Online (Sandbox Code Playgroud)
其中result.Results基本上是一个标准的对象列表,每个对象包含这些键/值/ id字段.我在这里阅读https://conficient.wordpress.com/2014/05/22/getting-rid-of-k__backingfield-in-serialization/ [serializable]属性可能会影响这个但我不愿意摆脱它属性,如果可能的话.是否有任何配方来调整此序列化工件?
我正在使用swagger/swashbuckle为Web Api 2中实现的api生成文档.
唯一识别的xml文档标签是<summary>,<remarks>和<param>.
这意味着我无法使用<para>标记在新行或段落中格式化我的文本,所有内容都在文档的Implementation Notes条目中生成为连续的长段落.
有没有办法做到这一点?
我使用Swagger作为我的API工具框架,到目前为止它运作良好.我刚看到这个页面https://petstore.swagger.io/
并看到每个方法如何描述.例如,
POST: pet/描述add a new Pet to the store.我想添加类似[Description("Description text")]应该做的事情,但事实并非如此.我怎样才能做到这一点?
我正在使用Swashbuckle库.目前没有stackoverflow标记.
我不太明白这里的文档:https://github.com/domaindrivendev/Swashbuckle/blob/master/README.md
标题为"描述安全/授权方案"的部分提到了一段代码
c.ApiKey("apiKey")
.Description("API Key Authentication")
.Name("apiKey")
.In("header");
Run Code Online (Sandbox Code Playgroud)
然而,当我包括这个没有任何反应.我还希望这只出现在某些API方法上.确实提到了
"需要在文件中加上相应的"安全"财产"
但我不明白这一点.
谁能解释一下?
我目前在我的项目中使用招摇,我在那里有超过100个控制器.我想由于控制器数量众多,swagger UI文档页面需要超过5分钟才能加载其控制器.是否可以在UI页面中选择特定控制器并仅为它们加载选项?或者还有其他方法可以更快地加载UI页面?帮我!
请帮助我,一开始看起来很容易,现在我在项目中迟到了:
我正在尝试为Swager和ASP.NET WebApi项目设置API版本.API版本控制正常,调用不同的版本会返回正确的结果(见下文).
相反,Swagger无法为这两个版本提供服务.在调试时,我注意到当c.MultipleApiVersions(...)在SwaggerConfig.cs中调用时,报告的控制器apiDesc.ActionDescriptor.ControllerDescriptor总是PingController从不Ping11Controller.
有人可以指出要解决这个问题需要做些什么,并且Swagger也适用于这两个版本?
下面,API版本的代码和证明工作正常,而Swagger仅适用于v1.0.
谢谢!
Swagger for v1.0很好: (http:// localhost:50884/v1.0/swagger)
{
"swagger":"2.0",
"info":{
"version":"v1.0",
"title":"My API v1.0"
},
"host":"localhost:50884",
"schemes":[
"http"
],
"paths":{
"/api/ping":{
"get":{
"tags":[
"Ping"
],
"summary":"Get a pong.",
"operationId":"GetAPong",
"consumes":[
],
"produces":[
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"responses":{
"200":{
"description":"OK"
},
"404":{
"description":"NotFound"
}
}
}
}
},
"definitions":{
}
}
Run Code Online (Sandbox Code Playgroud)
Swagger for v1.1为空: (http:// localhost:50884/v1.1/swagger)
{
"swagger":"2.0",
"info":{ …Run Code Online (Sandbox Code Playgroud) 我已经安装nuget package manager了Swashbuckle.AspNetCore.Swagger并且已经Swashbuckle.AspNetCore.Swagger在顶部包含了 using ,但是我在Info{ Title}方法上遇到了错误。任何人都可以请建议如何解决这个问题。
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My DAB API", Version = "V3.2.2" });
});
Run Code Online (Sandbox Code Playgroud) swashbuckle ×10
swagger ×8
c# ×7
swagger-ui ×4
asp.net-core ×1
authorize ×1
line-breaks ×1
oauth-2.0 ×1
openid ×1
restful-url ×1