在将Spring Data Rest添加到JHipster生成的项目之后,如何在控制器级别上添加API以及那些Rest API?
@RepositoryRestResource(collectionResourceRel = "api/myEntities", path = "api/myEntites")
我也尝试“/ api / myEntities”。
在Spring Data Rest中,我可以看到那些Rest API就像
/api/myEntities/search/<method name>
以下是我项目中的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"));
}
}
答案 0 :(得分:0)
在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