显示Spring Data Rest的API
问题描述:
将Spring Data Rest添加到JHipster生成的项目后,如何使这些Rest API在控制器级别的API上可见?显示Spring Data Rest的API
@RepositoryRestResource(collectionResourceRel = "api/myEntities", path = "api/myEntites")
我也尝试“/ api/myEntities”。
在Spring数据休息时,我就可以看到这些REST API的类似
以下是我的项目中SwaggerConfiguration类。我看不出我如何定制它来显示Spring Data Rest的API。
@Configuration
@EnableSwagger2
@Profile("!"+Constants.SPRING_PROFILE_PRODUCTION)
public class SwaggerConfiguration implements EnvironmentAware {
private final Logger log = LoggerFactory.getLogger(SwaggerConfiguration.class);
public static final String DEFAULT_INCLUDE_PATTERN = "/api/.*";
private RelaxedPropertyResolver propertyResolver;
@Override
public void setEnvironment(Environment environment) {
this.propertyResolver = new RelaxedPropertyResolver(environment, "swagger.");
}
/**
* Swagger Springfox configuration.
*/
@Bean
public Docket swaggerSpringfoxDocket() {
log.debug("Starting Swagger");
StopWatch watch = new StopWatch();
watch.start();
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.genericModelSubstitutes(ResponseEntity.class)
.forCodeGeneration(true)
.genericModelSubstitutes(ResponseEntity.class)
.directModelSubstitute(org.joda.time.LocalDate.class, String.class)
.directModelSubstitute(org.joda.time.LocalDateTime.class, Date.class)
.directModelSubstitute(org.joda.time.DateTime.class, Date.class)
.directModelSubstitute(java.time.LocalDate.class, String.class)
.directModelSubstitute(java.time.ZonedDateTime.class, Date.class)
.directModelSubstitute(java.time.LocalDateTime.class, Date.class)
.select()
.paths(regex(DEFAULT_INCLUDE_PATTERN))
.build();
watch.stop();
log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
return docket;
}
/**
* API Info as it appears on the swagger-ui page.
*/
private ApiInfo apiInfo() {
return new ApiInfo(
propertyResolver.getProperty("title"),
propertyResolver.getProperty("description"),
propertyResolver.getProperty("version"),
propertyResolver.getProperty("termsOfServiceUrl"),
propertyResolver.getProperty("contact"),
propertyResolver.getProperty("license"),
propertyResolver.getProperty("licenseUrl"));
}
}
答
在xx.xx.config.apidoc.SwaggerConfiguration.java
以下是默认的模式在SwaggerConfiguration包括这将显示在您的管理标签API。
public static final String DEFAULT_INCLUDE_PATTERN = "/api/.*";
而继从相同类
.paths(regex(DEFAULT_INCLUDE_PATTERN))
线加入上述图案。
因此,您可以添加另一个自己的,检查Spring Data Rest
api模式。并且像上面那样在paths()
函数中添加该api模式。
在这里,我与jhipster交谈2.18.0
尝试寻找在xx.xx.config.apidoc.SwaggerConfiguration.java – pmverma
@pmverma感谢您的信息。我看不到如何更改类以获取新添加的API。 – vic