Tag: swagger

将查询字符串参数添加到我的Swagger规范中

我使用我的Web API使用Swashbuckle(swagger for C#)。 我有几个返回列表的GET端点,我允许用户在QueryString中添加perpage和page params 示例: http : //myapi.com/endpoint/?page = 5&pagepage = 10 我看到swagger在’query’中确实支持参数但是我如何让Swashbuckle去做呢? 我在其中一条评论中提到我通过创建自定义属性来解决我的问题,以便让我做我需要的事情。 以下是我的解决方案的代码: [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)] public class SwaggerParameterAttribute : Attribute { public SwaggerParameterAttribute(string name, string description) { Name = name; Description = description; } public string Name { get; private set; } public Type DataType { […]

如何配置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设置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 ….} […]

在ASP.NET Core中使用Swagger中的JWT(授权:承载)

我正在ASP.NET Core 1.0中创建一个REST api。 我正在使用Swagger进行测试,但现在我为某些路线添加了JWT授权。 (使用UseJwtBearerAuthentication ) 是否可以修改Swagger请求的标头,以便可以测试具有[Authorize]属性的路由?

Web Api如何在Swagger中为所有API添加Header参数

我搜索了可能的方法来添加一个请求头参数,该参数将自动添加到我的web-api每个方法,但我找不到一个明确的方法。 在搜索时我发现方法OperationFilter()必须对它做一些事情。

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

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