مستند سازی ASP.NET Core 2x API توسط OpenAPI Swagger - قسمت هفتم - سفارشی سازی ظاهر مستندات API
نویسنده: وحید نصیری
تاریخ: ۱۳۹۸/۰۲/۰۲ ۱۲:۳۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
/// <remarks>
/// Sample request (this request updates the author's **first name**)
///
/// PATCH /authors/id
/// [
/// {
/// "op": "replace",
/// "path": "/firstname",
/// "value": "new first name"
/// }
/// ]
/// </remarks>
namespace OpenAPISwaggerDoc.Web
{
public class Startup
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// ...
app.UseSwaggerUI(setupAction =>
{
setupAction.SwaggerEndpoint(
url: "/swagger/LibraryOpenAPISpecification/swagger.json",
name: "Library API");
setupAction.RoutePrefix = "";
setupAction.DefaultModelExpandDepth(2);
setupAction.DefaultModelRendering(Swashbuckle.AspNetCore.SwaggerUI.ModelRendering.Model);
setupAction.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None);
setupAction.EnableDeepLinking();
setupAction.DisplayOperationId();
});
// ...
}
}
}
setupAction.InjectStylesheet("/Assets/custom-ui.css");
setupAction.InjectJavaScript("/Assets/custom-js.js"); setupAction.IndexStream = () =>
GetType().Assembly.GetManifestResourceStream(
"OpenAPISwaggerDoc.Web.EmbeddedAssets.index.html"); <Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup>
<None Remove="EmbeddedAssets\index.html" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="EmbeddedAssets\index.html" />
</ItemGroup>
</Project> [HttpPost] [ApiExplorerSettings(GroupName = "v2")] public void Post([FromBody]Product product)
public IServiceProvider ConfigureServices(IServiceCollection services)
{
// ....
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API - V1", Version = "v1" });
c.SwaggerDoc("v2", new Info { Title = "My API - V2", Version = "v2" });
});
// ....
}
public void Configure(IApplicationBuilder app)
{
// ....
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "AbpProjectName API V1");
options.SwaggerEndpoint("/swagger/v2/swagger.json", "AbpProjectName API V2");
}
// ....
}