gpt4 book ai didi

spring-boot - OpenAPI 在 Spring Boot 应用程序中转义 JSON 响应

转载 作者:行者123 更新时间:2023-12-04 01:34:38 25 4
gpt4 key购买 nike

我最近尝试为我的 Sprint Boot 应用程序生成 OpenAPI 文档。我在 pom.xml 中添加了以下几行

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.2.30</version>
</dependency>

但是当我在本地主机上点击 swagger-ui URL 时,我得到了这个页面
enter image description here

我在 /v3/api-docs 检查了 JSON我得到了一个开始的回应:
"{\"openapi\":\"3.0.1\",\"info\":{\"title\":\"OpenAPI definition\",\"version\":\"v0\"},\"servers\":[{\"url\":\"https://localhost:8900/tds\",

我可以看到 openapi字段被指定,但看起来整个响应是字符串化的,而不仅仅是 JSON。由于 OpenAPI 似乎没有任何配置,我假设它是从我的 Spring Boot 配置中获取的,但我不知道在哪里。

最佳答案

我有同样的问题。就我而言,我已经覆盖了 configureMessageConverters(List<HttpMessageConverter<?>> converters)在类扩展 WebMvcConfigurer . Springdoc 使用在那里配置的转换器。

首先,我首先将一些自定义转换器添加到转换器中,然后是 StringHttpMessageConverter . canWrite(Class<?> clazz, MediaType mediaType)返回的两个转换器的方法 trueclazz = String.classmediaType = application/json .因此使用了第一个,它将 JSON 转义为字符串。

当我改变它时,StringHttpMessageConverter首先添加,然后使用那个,并在不转义的情况下序列化 JSON 对象。

关于spring-boot - OpenAPI 在 Spring Boot 应用程序中转义 JSON 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60044853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com