mirror of https://github.com/halo-dev/halo
feat: enable swagger configuration in development. (#1328)
parent
444e649169
commit
e6b32ac8c2
|
@ -28,7 +28,6 @@ import org.springframework.lang.NonNull;
|
||||||
import org.springframework.util.AntPathMatcher;
|
import org.springframework.util.AntPathMatcher;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.PathMatcher;
|
import org.springframework.util.PathMatcher;
|
||||||
import run.halo.app.config.properties.HaloProperties;
|
|
||||||
import run.halo.app.utils.SwaggerUtils;
|
import run.halo.app.utils.SwaggerUtils;
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
import springfox.documentation.builders.ApiInfoBuilder;
|
||||||
import springfox.documentation.builders.PathSelectors;
|
import springfox.documentation.builders.PathSelectors;
|
||||||
|
@ -66,12 +65,6 @@ import springfox.documentation.swagger.web.UiConfigurationBuilder;
|
||||||
matchIfMissing = true)
|
matchIfMissing = true)
|
||||||
public class SwaggerConfiguration {
|
public class SwaggerConfiguration {
|
||||||
|
|
||||||
private final HaloProperties haloProperties;
|
|
||||||
|
|
||||||
public SwaggerConfiguration(HaloProperties haloProperties) {
|
|
||||||
this.haloProperties = haloProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Docket haloDefaultApi() {
|
public Docket haloDefaultApi() {
|
||||||
return buildApiDocket("run.halo.app.content.api",
|
return buildApiDocket("run.halo.app.content.api",
|
||||||
|
@ -83,10 +76,6 @@ public class SwaggerConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Docket haloAdminApi() {
|
public Docket haloAdminApi() {
|
||||||
if (haloProperties.isDocDisabled()) {
|
|
||||||
log.debug("Doc has been disabled");
|
|
||||||
}
|
|
||||||
|
|
||||||
return buildApiDocket("run.halo.app.admin.api",
|
return buildApiDocket("run.halo.app.admin.api",
|
||||||
"run.halo.app.controller.admin",
|
"run.halo.app.controller.admin",
|
||||||
"/api/admin/**")
|
"/api/admin/**")
|
||||||
|
|
|
@ -22,12 +22,6 @@ import run.halo.app.model.enums.Mode;
|
||||||
@ConfigurationProperties("halo")
|
@ConfigurationProperties("halo")
|
||||||
public class HaloProperties {
|
public class HaloProperties {
|
||||||
|
|
||||||
/**
|
|
||||||
* Doc api disabled. (Default is true)
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private boolean docDisabled = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Production env. (Default is true)
|
* Production env. (Default is true)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -67,6 +67,9 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
||||||
@Value("${spring.datasource.password}")
|
@Value("${spring.datasource.password}")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
@Value("${springfox.documentation.enabled}")
|
||||||
|
private Boolean documentationEnabled;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(ApplicationStartedEvent event) {
|
public void onApplicationEvent(ApplicationStartedEvent event) {
|
||||||
try {
|
try {
|
||||||
|
@ -95,9 +98,9 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
||||||
log.info(AnsiOutput
|
log.info(AnsiOutput
|
||||||
.toString(AnsiColor.BRIGHT_BLUE, "Halo admin started at ", blogUrl, "/",
|
.toString(AnsiColor.BRIGHT_BLUE, "Halo admin started at ", blogUrl, "/",
|
||||||
haloProperties.getAdminPath()));
|
haloProperties.getAdminPath()));
|
||||||
if (!haloProperties.isDocDisabled()) {
|
if (documentationEnabled) {
|
||||||
log.debug(AnsiOutput
|
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"));
|
"/swagger-ui.html"));
|
||||||
}
|
}
|
||||||
log.info(AnsiOutput.toString(AnsiColor.BRIGHT_YELLOW, "Halo has started successfully!"));
|
log.info(AnsiOutput.toString(AnsiColor.BRIGHT_YELLOW, "Halo has started successfully!"));
|
||||||
|
|
|
@ -61,6 +61,10 @@ logging:
|
||||||
file:
|
file:
|
||||||
path: ${halo.work-dir}/newLogs
|
path: ${halo.work-dir}/newLogs
|
||||||
|
|
||||||
|
springfox:
|
||||||
|
documentation:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
halo:
|
halo:
|
||||||
auth-enabled: true
|
auth-enabled: true
|
||||||
mode: development
|
mode: development
|
||||||
|
|
Loading…
Reference in New Issue