mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.4 KiB
69 lines
2.4 KiB
// ==========================================================================
|
|
// SwaggerUsage.cs
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex Group
|
|
// All rights reserved.
|
|
// ==========================================================================
|
|
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
using NJsonSchema;
|
|
using NJsonSchema.Generation.TypeMappers;
|
|
using NSwag.AspNetCore;
|
|
using Squidex.Configurations.Identity;
|
|
using Squidex.Infrastructure;
|
|
|
|
namespace Squidex.Configurations.Swagger
|
|
{
|
|
public static class SwaggerUsage
|
|
{
|
|
public static void UseMySwagger(this IApplicationBuilder app)
|
|
{
|
|
var options = app.ApplicationServices.GetService<IOptions<MyUrlsOptions>>().Value;
|
|
|
|
var settings =
|
|
new SwaggerOwinSettings { Title = "Squidex API Specification" }
|
|
.ConfigurePaths()
|
|
.ConfigureSchemaSettings()
|
|
.ConfigureIdentity(options);
|
|
|
|
app.UseSwagger(typeof(SwaggerUsage).GetTypeInfo().Assembly, settings);
|
|
}
|
|
|
|
private static SwaggerOwinSettings ConfigurePaths(this SwaggerOwinSettings settings)
|
|
{
|
|
settings.SwaggerRoute = $"{Constants.ApiPrefix}/swagger/v1/swagger.json";
|
|
|
|
settings.PostProcess = document =>
|
|
{
|
|
document.BasePath = Constants.ApiPrefix;
|
|
};
|
|
|
|
settings.MiddlewareBasePath = Constants.ApiPrefix;
|
|
|
|
return settings;
|
|
}
|
|
|
|
private static SwaggerOwinSettings ConfigureSchemaSettings(this SwaggerOwinSettings settings)
|
|
{
|
|
settings.DefaultEnumHandling = EnumHandling.String;
|
|
settings.DefaultPropertyNameHandling = PropertyNameHandling.CamelCase;
|
|
|
|
settings.TypeMappers = new List<ITypeMapper>
|
|
{
|
|
new PrimitiveTypeMapper(typeof(Language), s => s.Type = JsonObjectType.String)
|
|
};
|
|
|
|
settings.DocumentProcessors.Add(new XmlTagProcessor());
|
|
|
|
settings.OperationProcessors.Add(new XmlTagProcessor());
|
|
settings.OperationProcessors.Add(new XmlResponseTypesProcessor());
|
|
|
|
return settings;
|
|
}
|
|
}
|
|
}
|
|
|