Example #1
0
 /// <summary>Addes the Swagger generator to the OWIN pipeline.</summary>
 /// <param name="app">The app.</param>
 /// <param name="controllerTypes">The Web API controller types.</param>
 /// <param name="settings">The Swagger generator settings.</param>
 /// <returns>The app builder.</returns>
 public static IAppBuilder UseSwagger(
     this IAppBuilder app,
     IEnumerable<Type> controllerTypes,
     SwaggerOwinSettings settings)
 {
     return app.UseSwagger(controllerTypes, settings, new SwaggerJsonSchemaGenerator(settings));
 }
Example #2
0
 /// <summary>Addes the Swagger generator and Swagger UI to the OWIN pipeline.</summary>
 /// <param name="app">The app.</param>
 /// <param name="webApiAssembly">The Web API assembly to search for controller types.</param>
 /// <param name="settings">The Swagger generator settings.</param>
 /// <returns>The app builder.</returns>
 public static IAppBuilder UseSwagger(
     this IAppBuilder app,
     Assembly webApiAssembly,
     SwaggerOwinSettings settings)
 {
     return app.UseSwagger(new[] { webApiAssembly }, settings);
 }
Example #3
0
 /// <summary>Initializes a new instance of the <see cref="SwaggerMiddleware"/> class.</summary>
 /// <param name="next">The next middleware.</param>
 /// <param name="path">The path.</param>
 /// <param name="controllerTypes">The controller types.</param>
 /// <param name="settings">The settings.</param>
 /// <param name="schemaGenerator">The schema generator.</param>
 public SwaggerMiddleware(OwinMiddleware next, string path, IEnumerable<Type> controllerTypes, SwaggerOwinSettings settings, SwaggerJsonSchemaGenerator schemaGenerator)
     : base(next)
 {
     _path = path;
     _controllerTypes = controllerTypes;
     _settings = settings;
     _schemaGenerator = schemaGenerator;
 }
Example #4
0
 /// <summary>Addes the Swagger generator and Swagger UI to the OWIN pipeline.</summary>
 /// <param name="app">The app.</param>
 /// <param name="webApiAssemblies">The Web API assemblies to search for controller types.</param>
 /// <param name="settings">The Swagger generator settings.</param>
 /// <returns>The app builder.</returns>
 public static IAppBuilder UseSwagger(
     this IAppBuilder app,
     IEnumerable<Assembly> webApiAssemblies,
     SwaggerOwinSettings settings)
 {
     var controllerTypes = webApiAssemblies.SelectMany(WebApiToSwaggerGenerator.GetControllerClasses);
     return app.UseSwagger(controllerTypes, settings);
 }
Example #5
0
        private static SwaggerOwinSettings ConfigureIdentity(this SwaggerOwinSettings settings, MyUrlsOptions urlOptions)
        {
            settings.DocumentProcessors.Add(
                new SecurityDefinitionAppender(Constants.SecurityDefinition, SwaggerHelper.CreateOAuthSchema(urlOptions)));

            settings.OperationProcessors.Add(new OperationSecurityScopeProcessor(Constants.SecurityDefinition));

            return(settings);
        }
Example #6
0
 /// <summary>Addes the Swagger generator to the OWIN pipeline.</summary>
 /// <param name="app">The app.</param>
 /// <param name="controllerTypes">The Web API controller types.</param>
 /// <param name="settings">The Swagger generator settings.</param>
 /// <param name="schemaGenerator">The schema generator.</param>
 /// <returns>The app builder.</returns>
 public static IAppBuilder UseSwagger(
     this IAppBuilder app,
     IEnumerable<Type> controllerTypes,
     SwaggerOwinSettings settings,
     SwaggerJsonSchemaGenerator schemaGenerator)
 {
     app.Use<SwaggerMiddleware>(settings.ActualSwaggerRoute, controllerTypes, settings, schemaGenerator);
     app.UseStageMarker(PipelineStage.MapHandler);
     return app;
 }
Example #7
0
        public SchemasSwaggerGenerator(IHttpContextAccessor context, SwaggerOwinSettings swaggerSettings, IOptions <MyUrlsOptions> urlOptions)
        {
            this.context = context.HttpContext;

            this.urlOptions = urlOptions.Value;

            schemaGenerator = new SwaggerJsonSchemaGenerator(swaggerSettings);
            schemaResolver  = new SwaggerSchemaResolver(document, swaggerSettings);

            swaggerGenerator = new SwaggerGenerator(schemaGenerator, swaggerSettings, schemaResolver);

            schemaBodyDescription  = SwaggerHelper.LoadDocs("schemabody");
            schemaQueryDescription = SwaggerHelper.LoadDocs("schemaquery");
        }
Example #8
0
        private static SwaggerOwinSettings ConfigurePaths(this SwaggerOwinSettings settings, MyUrlsOptions urlOptions)
        {
            settings.SwaggerRoute = $"{Constants.ApiPrefix}/swagger/v1/swagger.json";

            settings.PostProcess = document =>
            {
                document.BasePath           = Constants.ApiPrefix;
                document.Info.ExtensionData = new Dictionary <string, object>
                {
                    ["x-logo"] = new { url = urlOptions.BuildUrl("images/logo-white.png", false), backgroundColor = "#3f83df" }
                };
            };

            settings.MiddlewareBasePath = Constants.ApiPrefix;

            return(settings);
        }
Example #9
0
        public static void AddMySwaggerSettings(this IServiceCollection services)
        {
            services.AddSingleton(typeof(SwaggerOwinSettings), s =>
            {
                var urlOptions = s.GetService <IOptions <MyUrlsOptions> >().Value;

                var settings =
                    new SwaggerOwinSettings {
                    Title = "Squidex API Specification", IsAspNetCore = false
                }
                .ConfigurePaths(urlOptions)
                .ConfigureSchemaSettings()
                .ConfigureIdentity(urlOptions);

                return(settings);
            });

            services.AddTransient <SchemasSwaggerGenerator>();
        }
Example #10
0
        private static SwaggerOwinSettings ConfigureSchemaSettings(this SwaggerOwinSettings settings)
        {
            settings.DefaultEnumHandling         = EnumHandling.String;
            settings.DefaultPropertyNameHandling = PropertyNameHandling.CamelCase;

            settings.TypeMappers = new List <ITypeMapper>
            {
                new PrimitiveTypeMapper(typeof(Instant), schema =>
                {
                    schema.Type   = JsonObjectType.String;
                    schema.Format = JsonFormatStrings.DateTime;
                }),
                new PrimitiveTypeMapper(typeof(Language), s => s.Type = JsonObjectType.String),
                new PrimitiveTypeMapper(typeof(RefToken), s => s.Type = JsonObjectType.String)
            };

            settings.DocumentProcessors.Add(new XmlTagProcessor());

            settings.OperationProcessors.Add(new XmlTagProcessor());
            settings.OperationProcessors.Add(new XmlResponseTypesProcessor());

            return(settings);
        }