Enable Swagger in host projects.

pull/12794/head
maliming 3 years ago
parent 0fb006d918
commit ba21feccd1
No known key found for this signature in database
GPG Key ID: 096224957E51C89E

@ -126,7 +126,7 @@ public class MyProjectNameModule : AbpModule
ConfigureMultiTenancy();
ConfigureUrls(configuration);
ConfigureAutoMapper(context);
ConfigureSwagger(context.Services);
ConfigureSwagger(context.Services, configuration);
ConfigureAutoApiControllers();
ConfigureVirtualFiles(hostingEnvironment);
ConfigureLocalization();
@ -225,16 +225,20 @@ public class MyProjectNameModule : AbpModule
});
}
private void ConfigureSwagger(IServiceCollection services)
private void ConfigureSwagger(IServiceCollection services, IConfiguration configuration)
{
services.AddAbpSwaggerGen(
services.AddAbpSwaggerGenWithOAuth(
configuration["AuthServer:Authority"],
new Dictionary<string, string>
{
{"MyProjectName", "MyProjectName API"}
},
options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "MyProjectName API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName);
}
);
});
}
private void ConfigureAutoMapper(ServiceConfigurationContext context)

@ -14,6 +14,11 @@
"StringEncryption": {
"DefaultPassPhrase": "gsKnGZ041HLL4IM8"
},
"AuthServer": {
"Authority": "https://localhost:44300",
"RequireHttpsMetadata": "true",
"SwaggerClientId": "MyProjectName_Swagger"
},
"OpenIddict": {
"Applications": {
"MyProjectName_App": {

@ -128,7 +128,7 @@ public class MyProjectNameModule : AbpModule
ConfigureMultiTenancy();
ConfigureUrls(configuration);
ConfigureAutoMapper(context);
ConfigureSwagger(context.Services);
ConfigureSwagger(context.Services, configuration);
ConfigureAutoApiControllers();
ConfigureVirtualFiles(hostingEnvironment);
ConfigureLocalization();
@ -227,16 +227,20 @@ public class MyProjectNameModule : AbpModule
});
}
private void ConfigureSwagger(IServiceCollection services)
private void ConfigureSwagger(IServiceCollection services, IConfiguration configuration)
{
services.AddAbpSwaggerGen(
services.AddAbpSwaggerGenWithOAuth(
configuration["AuthServer:Authority"],
new Dictionary<string, string>
{
{"MyProjectName", "MyProjectName API"}
},
options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "MyProjectName API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName);
}
);
});
}
private void ConfigureAutoMapper(ServiceConfigurationContext context)
@ -343,6 +347,10 @@ public class MyProjectNameModule : AbpModule
app.UseAbpSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "MyProjectName API");
var configuration = context.GetConfiguration();
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
options.OAuthScopes("MyProjectName");
});
app.UseAuditing();

@ -14,6 +14,11 @@
"StringEncryption": {
"DefaultPassPhrase": "gsKnGZ041HLL4IM8"
},
"AuthServer": {
"Authority": "https://localhost:44300",
"RequireHttpsMetadata": "true",
"SwaggerClientId": "MyProjectName_Swagger"
},
"OpenIddict": {
"Applications": {
"MyProjectName_App": {

@ -12,7 +12,7 @@
"Authority": "https://localhost:44301",
"RequireHttpsMetadata": "true",
"SwaggerClientId": "MyProjectName_Swagger"
},
},
"StringEncryption": {
"DefaultPassPhrase": "gsKnGZ041HLL4IM8"
}

Loading…
Cancel
Save