Spring MVC Spring Doc 2.2.0和WebMvcConfigurer的时间戳和渲染UI问题

i7uq4tfw  于 6个月前  发布在  Spring
关注(0)|答案(1)|浏览(75)

Sping Boot 3.0.4 Spring Doc 2.2.0
我在渲染OffsetDateTime“eventStart”时遇到问题:1647302400.00000000
为了解决这个问题,我实现了:

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
    }

    private ObjectMapper objectMapper() {
        JavaTimeModule module = new JavaTimeModule();
        return new ObjectMapper()
            .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
            .registerModule(module)
            .registerModule(new JavaTimeModule());
    }

字符串
现在我可以正确渲染OffsetDateTime了:“eventStart”:“2022-03- 15 T00:00:00 Z”,
但是,这会破坏Swagger UI:无法呈现此定义提供的定义未指定有效的版本字段。
请指定有效的Swagger或OpenAPI版本字段。支持的版本字段包括swagger:“2.0”和与openapi:3.x.y匹配的字段(例如openapi:3.1.0)。
application.yml

springdoc:
  swagger-ui:
    # custom path for swagger-ui
    path: /${spring.application.name}.html
  api-docs:
    #custom path for api docs
    path: /docs/api
    version: OPENAPI_3_1
  paths-to-match: /**
  show-actuator: true

agyaoht7

agyaoht71#

尝试删除@EnableWebMvc,它为我解决了类似的问题

相关问题