Tag: swashbuckle

如何配置Swashbuckle忽略模型上的属性

我正在使用Swashbuckle为webapi2项目生成swagger文档\ UI。 我们的模型与一些传统接口共享,因此我想在模型上忽略一些属性。 我不能使用JsonIgnore属性,因为旧版接口也需要序列化为JSON,因此我不想全局忽略这些属性,只是在Swashbuckle配置中。 我在这里找到了一种记录方法: https://github.com/domaindrivendev/Swashbuckle/issues/73 但这与目前的Swashbuckle版本似乎已经过时了。 推荐用于旧版Swashbuckle的方法是使用IModelFilter实现,如下所示: public class OmitIgnoredProperties : IModelFilter { public void Apply(DataType model, DataTypeRegistry dataTypeRegistry, Type type) { var ignoredProperties = … // use reflection to find any properties on // type decorated with the ignore attributes foreach (var prop in ignoredProperties) model.Properties.Remove(prop.Name); } } SwaggerSpecConfig.Customize(c => c.ModelFilter()); 但我不确定如何配置Swashbuckle在当前版本中使用IModelFilter? 我正在使用Swashbuckle […]

k__BackingField在C#中删除(通过Swashbuckle / Swagger看到)

我在ASP.NET webapi项目中使用Swashbuckle 5并使用所有默认设置。 它序列化我的方法的输出,以显示回复的模式。 我得到的文档看起来像这样: Response Class (Status 200) Model Model Schema [ { “k__BackingField”: “string”, “k__BackingField”: “string”, “k__BackingField”: 0 } ] 这是通过遵循C#代码生成的 /// /// Fetches all system configuration items /// /// List of items public IList GetAllSystemConfigurationItems() { var result = CommandProcessor.ProcessCommand(new SystemConfigurationQueryCommand()) as SystemConfigurationQueryCommandResponse; return result.Results.ToList(); } 其中result.Results基本上是一个标准的对象列表,每个对象包含这些键/值/ id字段。 我在这里阅读https://conficient.wordpress.com/2014/05/22/getting-rid-of-k__backingfield-in-serialization/,[serializable ]属性可能会影响这个,但我不愿意摆脱它属性,如果可能的话。 是否有任何配方来调整此序列化工件?

Swashbuckle 5找不到我的ApiControllers

我真的需要我的WebAPI 2项目的API文档,我使用了Swashbuckle 5 NuGet包。 开箱即用,我可以点击{myrooturl} / swagger并弹出一个UI,但那里没有控制器,方法或任何东西。 只是我的标题:[base url:/EM.Services,api version:v1] 我看了一下Swashbuckle文档,因为我正在使用由IIS托管的OWIN,所以我修改了SwaggerConfig: c.RootUrl(req => req.RequestUri.GetLeftPart(UriPartial.Authority) + req.GetRequestContext().VirtualPathRoot.TrimEnd(‘/’)); 按照这个文件: https : //github.com/domaindrivendev/Swashbuckle/blob/1326e753ce9b3a823b3c156b0b601134692ffc58/README.md#transitioning-to-swashbuckle-50 我还设置了项目的构建以生成XML文档,并将我的SwaggerConfig指向它: private static string GetXmlCommentsPath() { // tried with an without the \bin return String.Format(@”{0}\bin\EM.Services.XML”, AppDomain.CurrentDomain.BaseDirectory); } 我不确定XML文档的工作/不工作是否与它有关,因为我在swagger-ui页面上完全没有控制器。 值得一提的是,我的所有控制器都inheritance自BaseController,而BaseController又inheritance自ApiController。 我的WebApiConfig有什么东西搞砸了吗? public static void Register(HttpConfiguration config) { config.SuppressDefaultHostAuthentication(); config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); config.Filters.Add(new ValidateModelAttribute()); config.Filters.Add(new BaseAuthenticationAttribute()); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( […]

在文档中对API方法进行分组 – 是否存在一些自定义属性

我有控制器喜欢 public class UserController : ApiController { [Route(“api/user”)] IHttpActionResult GetUser() { … } } public class ResumeController : ApiController { [Route(“api/user/resumes”)] IHttpActionResult GetResumes() { … } } 在swagger上产生的输出就像 有没有办法(除了通过推出自己的ISwaggerProvider或将两个控制器合并为一个来覆盖默认实现)来强制执行组名? 就像是 public class UserController : ApiController { [Route(“api/user”)] [MagicalAttributeName(Group=”User”)] IHttpActionResult GetUser() { … } } public class ResumeController : ApiController { [Route(“api/user/resumes”)] [MagicalAttributeName(Group=”User”)] IHttpActionResult GetResumes() { […]

Swashbuckle设置manualy operationId

我需要知道是否可以设置自定义operationid或命名约定,我的意思是我知道操作filter可以覆盖如何生成operationId的方式 https://azure.microsoft.com/en-us/documentation/articles/app-service-api-dotnet-swashbuckle-customize/ 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); } } } } } 在SwaggerConfig.cs中 c.OperationFilter(); 现在这有助于改变招摇的描述,请检查以下内容: 一切都很好,现在我最终在一个更黑暗的地方,例如类似于可能的情况:在同一个控制器上我有两个端点 发布:/ customer boddy:{email,location ….} […]

如何使用Swashbuckle在Swagger API文档中包含子类?

我在c#中有一个Asp.Net web API 5.2项目,并使用Swashbuckle生成文档。 我有一个包含inheritance的模型,比如从Animal抽象类中获取Animal属性,从中派生出Dog和Cat类。 Swashbuckle只显示Animal类的模式,所以我尝试使用ISchemaFilter(他们也建议),但我无法使它工作,我也找不到合适的例子。 有人可以帮忙吗?