Swagger
Include XML comments
This is a SwaggerGenOptions’ extension to include xml comments from referenced assemblies.
...
using Juice.Extensions.Swagger;
...
services.ConfigureSwaggerGen(c =>
{
...
c.IncludeReferencedXmlComments();
});
The library can be accessed via Nuget:
SwaggerIgnoreFilter
To ignore model properties from Swagger document generator but keep it in serialized JSON, we implement ApiIgnoreAttribute and ISchemaFilter interface to remove properties those have ApiIgnoreAttribute from OpenApiSchema
public class SwaggerIgnoreFilter : ISchemaFilter
{
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
...
}
}
Register filter into DI
...
using Juice.Extensions.Swagger;
...
// use default config
services.AddSwaggerWithDefaultConfigs();
// OR configure swagger yourself
// services.AddSwaggerGen(c =>
// {
// ...
// c.SchemaFilter<SwaggerIgnoreFilter>();
// });
The library can be accessed via Nuget:
ApiIgnore attribute
This attribute is useful to Swagger skip generate API for specified properties when combined with the above SwaggerIgnoreFilter.
using Juice.CompnentModel;
public class ViewMode{
[ApiIgnore]
public int OnlyAppearInJSON { get; set; }
}
The library can be accessed via Nuget: