Пример #1
0
        public static IServiceCollection AddApskOpenApiDocument(this IServiceCollection services, IConfiguration configuration)
        {
            var apiSetting = new OpenApiSetting();

            configuration.GetSection(nameof(OpenApiSetting)).Bind(apiSetting);

            if (apiSetting is null)
            {
                throw new System.ArgumentNullException(nameof(apiSetting));
            }

            if (string.IsNullOrWhiteSpace(apiSetting.Title))
            {
                apiSetting.Title = Assembly.GetEntryAssembly().GetName().Name;
            }

            services.AddOpenApiDocument(opt =>
            {
                opt.DocumentName = $"{apiSetting.Title}:{apiSetting.Version}";
                opt.Title        = apiSetting.Title;
                opt.Version      = apiSetting.Version;
                opt.Description  = apiSetting.Description;
            });
            return(services);
        }
Пример #2
0
        public static void UseApskOpenApiDocument(this IApplicationBuilder app, IConfiguration config)
        {
            var apiSetting = new OpenApiSetting();

            config.GetSection(nameof(OpenApiSetting)).Bind(apiSetting);

            if (apiSetting is null)
            {
                throw new System.ArgumentNullException(nameof(apiSetting));
            }

            if (string.IsNullOrWhiteSpace(apiSetting.Title))
            {
                apiSetting.Title = Assembly.GetEntryAssembly().GetName().Name;
            }

            app.UseOpenApi(setting =>
            {
                setting.DocumentName = $"{apiSetting.Title}:{apiSetting.Version}";
            });
            app.UseSwaggerUi3();
            app.UseReDoc();
        }