feat: enable swagger configuration in development. (#1328)

pull/1331/head
Ryan Wang 2021-03-27 15:32:26 +08:00 committed by GitHub
parent 444e649169
commit e6b32ac8c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 19 deletions

View File

@ -28,7 +28,6 @@ import org.springframework.lang.NonNull;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.Assert;
import org.springframework.util.PathMatcher;
import run.halo.app.config.properties.HaloProperties;
import run.halo.app.utils.SwaggerUtils;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
@ -66,12 +65,6 @@ import springfox.documentation.swagger.web.UiConfigurationBuilder;
matchIfMissing = true)
public class SwaggerConfiguration {
private final HaloProperties haloProperties;
public SwaggerConfiguration(HaloProperties haloProperties) {
this.haloProperties = haloProperties;
}
@Bean
public Docket haloDefaultApi() {
return buildApiDocket("run.halo.app.content.api",
@ -83,10 +76,6 @@ public class SwaggerConfiguration {
@Bean
public Docket haloAdminApi() {
if (haloProperties.isDocDisabled()) {
log.debug("Doc has been disabled");
}
return buildApiDocket("run.halo.app.admin.api",
"run.halo.app.controller.admin",
"/api/admin/**")

View File

@ -22,12 +22,6 @@ import run.halo.app.model.enums.Mode;
@ConfigurationProperties("halo")
public class HaloProperties {
/**
* Doc api disabled. (Default is true)
*/
@Deprecated
private boolean docDisabled = true;
/**
* Production env. (Default is true)
*/

View File

@ -67,6 +67,9 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
@Value("${spring.datasource.password}")
private String password;
@Value("${springfox.documentation.enabled}")
private Boolean documentationEnabled;
@Override
public void onApplicationEvent(ApplicationStartedEvent event) {
try {
@ -95,9 +98,9 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
log.info(AnsiOutput
.toString(AnsiColor.BRIGHT_BLUE, "Halo admin started at ", blogUrl, "/",
haloProperties.getAdminPath()));
if (!haloProperties.isDocDisabled()) {
if (documentationEnabled) {
log.debug(AnsiOutput
.toString(AnsiColor.BRIGHT_BLUE, "Halo api doc was enabled at ", blogUrl,
.toString(AnsiColor.BRIGHT_BLUE, "Halo api documentation was enabled at ", blogUrl,
"/swagger-ui.html"));
}
log.info(AnsiOutput.toString(AnsiColor.BRIGHT_YELLOW, "Halo has started successfully!"));

View File

@ -61,6 +61,10 @@ logging:
file:
path: ${halo.work-dir}/newLogs
springfox:
documentation:
enabled: true
halo:
auth-enabled: true
mode: development