【发布时间】:2019-06-13 00:08:21
【问题描述】:
我遇到了 Spring AutoRest Docs 的问题。似乎源于这段代码
.alwaysDo<DefaultMockMvcBuilder>(JacksonResultHandlers.prepareJackson(objectMapper))
完整配置:
mockMvc = MockMvcBuilders
.webAppContextSetup(webApplicationContext)
.alwaysDo<DefaultMockMvcBuilder>(JacksonResultHandlers.prepareJackson(objectMapper))
.alwaysDo<DefaultMockMvcBuilder>(document("{class-name}/{method-name}",
Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
Preprocessors.preprocessResponse(Preprocessors.prettyPrint())))
.apply<DefaultMockMvcBuilder>(documentationConfiguration(this.restDocumentation)
.uris()
.withScheme("https")
.withHost("localhost")
.and().snippets()
.withDefaults(CliDocumentation.curlRequest(),
HttpDocumentation.httpRequest(),
HttpDocumentation.httpResponse(),
AutoDocumentation.requestFields()
.failOnUndocumentedFields(true),
AutoDocumentation.responseFields()
.failOnUndocumentedFields(true),
AutoDocumentation.pathParameters(),
AutoDocumentation.requestParameters(),
AutoDocumentation.description(),
AutoDocumentation.methodAndPath(),
AutoDocumentation.section(),
AutoDocumentation.links()))
.build()
我对杰克逊进行了一些定制,但 autorest 似乎不喜欢这样。当我输入我的objectMapper 时,我收到以下警告:
No Javadoc found for class java.lang.Object
No Javadoc found for class java.io.Serializable
No description found for constraint com.domain.CLASS: Can't find resource for bundle java.util.PropertyResourceBundle, key com.domain.CLASS.description
我已经尝试注入其他方法来获取对象映射器,包括
MappingJackson2HttpMessageConverter
ObjectMapperResolver
我也尝试过启动一个新的 Spring Boot 应用程序并且没有遇到任何错误。但是,如果删除了prepareJackson,则不再出现警告,则自动生成的文档中没有数据。
我已经被这个问题困扰了很长一段时间,不知道如何解决它。任何指导将不胜感激。
【问题讨论】:
-
前两个警告是说项目中的两个类没有 Javadoc。这是意料之中的,因为这些类是标准库的一部分,而不是您的项目的一部分。最后一个警告说没有约束 CLASS 的描述。这些都没有暗示 ObjectMapper 有任何问题。你的测试结果如何?您是否按照scacap.github.io/spring-auto-restdocs/#gettingstarted-usage 中的步骤操作?
-
正确我遵循了这些步骤,并且我所有的类/控制器上都有 Javadocs。我还注意到,从 2.0.5 -> 2.0.3 开始,some 类的“无约束消息描述”消失了……我今天将尝试制作一个演示项目并在此处回复.
-
在将项目中的 auto-restdocs 从 1.0.10 升级到 2.0.5 后,我今天看到了相同的行为。我注意到警告中包含的类不是约束(注释)类。相反,它们是模型类。乍一看,这似乎是 spring-auto-restdocs 中的一个小错误,还是我遗漏了什么?
-
@FlorianBenz 您也可以在您的 travis 日志中找到这些警告:travis-ci.org/ScaCap/spring-auto-restdocs/jobs/544592362#L2367
-
确实是这样,最新版本中出现了更多“没有找到约束的描述”警告。我创建了一个问题并开始了 PR github.com/ScaCap/spring-auto-restdocs/issues/336
标签: spring-boot jackson spring-restdocs spring-auto-restdocs