ApiApplicationBuilderExtensions.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. using Microsoft.AspNetCore.Builder;
  2. namespace Jellyfin.Server.Extensions
  3. {
  4. /// <summary>
  5. /// Extensions for adding API specific functionality to the application pipeline.
  6. /// </summary>
  7. public static class ApiApplicationBuilderExtensions
  8. {
  9. /// <summary>
  10. /// Adds swagger and swagger UI to the application pipeline.
  11. /// </summary>
  12. /// <param name="applicationBuilder">The application builder.</param>
  13. /// <returns>The updated application builder.</returns>
  14. public static IApplicationBuilder UseJellyfinApiSwagger(this IApplicationBuilder applicationBuilder)
  15. {
  16. // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
  17. // specifying the Swagger JSON endpoint.
  18. const string specEndpoint = "/swagger/v1/swagger.json";
  19. return applicationBuilder
  20. .UseSwagger()
  21. .UseSwaggerUI(c =>
  22. {
  23. c.SwaggerEndpoint(specEndpoint, "Jellyfin API V1");
  24. c.RoutePrefix = "api-docs/swagger";
  25. })
  26. .UseReDoc(c =>
  27. {
  28. c.SpecUrl(specEndpoint);
  29. c.RoutePrefix = "api-docs/redoc";
  30. });
  31. }
  32. }
  33. }