答案 0 :(得分:1)
在其他地方只有一个指针。这是解决方案。将此类添加到您的配置中:
package nl.tibi.config;
import static io.github.jhipster.config.JHipsterConstants.SPRING_PROFILE_SWAGGER;
import static springfox.documentation.builders.PathSelectors.regex;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import javax.servlet.Servlet;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Profile;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.DispatcherServlet;
import io.github.jhipster.config.JHipsterProperties;
import io.github.jhipster.config.apidoc.SwaggerAutoConfiguration;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* An extension of the default Jhipster {@link SwaggerAutoConfiguration} adding
* the pluginV1 group
*/
@Configuration
@ConditionalOnWebApplication
@ConditionalOnClass({
ApiInfo.class,
BeanValidatorPluginsConfiguration.class,
Servlet.class,
DispatcherServlet.class,
Docket.class
})
@Profile(SPRING_PROFILE_SWAGGER)
@AutoConfigureAfter(JHipsterProperties.class)
@EnableSwagger2
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerExtension {
static final String STARTING_MESSAGE = "Starting Swagger";
static final String STARTED_MESSAGE = "Started Swagger in {} ms";
static final String PLUGIN_V1_TITLE_SUFFIX = "Plugin V1 API";
static final String PLUGIN_V1_GROUP_NAME = "pluginV1";
static final String PLUGIN_V1_DESCRIPTION = "Plugin V1 endpoints documentation";
private final JHipsterProperties.Swagger properties;
/**
* <p>
* Constructor for SwaggerAutoConfiguration.
* </p>
*
* @param jHipsterProperties a
* {@link io.github.jhipster.config.JHipsterProperties}
* object.
*/
public SwaggerExtension(JHipsterProperties jHipsterProperties) {
this.properties = jHipsterProperties.getSwagger();
}
/**
* Springfox configuration for the plugin v1 endpoints (actuator) Swagger docs.
*
* @param appName the application name
* @return the Swagger Springfox configuration
*/
@Bean
public Docket swaggerSpringfoxPluginV1Docket(@Value("${spring.application.name:application}") String appName) {
ApiInfo apiInfo = new ApiInfo(
StringUtils.capitalize(appName) + " " + PLUGIN_V1_TITLE_SUFFIX,
PLUGIN_V1_DESCRIPTION,
properties.getVersion(),
"",
ApiInfo.DEFAULT_CONTACT,
"",
"",
new ArrayList<>());
return createDocket()
.apiInfo(apiInfo)
.useDefaultResponseMessages(properties.isUseDefaultResponseMessages())
.groupName("pluginV1")
.host(properties.getHost())
.protocols(new HashSet<>(Arrays.asList(properties.getProtocols())))
.forCodeGeneration(true)
.directModelSubstitute(ByteBuffer.class, String.class)
.genericModelSubstitutes(ResponseEntity.class)
.ignoredParameterTypes(Pageable.class)
.select()
.paths(regex("/api/plugin/v1.*"))
.build();
}
/**
* <p>
* createDocket.
* </p>
*
* @return a {@link springfox.documentation.spring.web.plugins.Docket} object.
*/
protected Docket createDocket() {
return new Docket(DocumentationType.SWAGGER_2);
}
}