You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot集成OpenAPI3如何隐藏请求响应的Schema仅显示示例值

Spring Boot OpenAPI3 接口文档隐藏请求/响应区域Schema问题

基础环境

当前项目使用springdoc 1.6.9版本生成OpenAPI3接口文档,依赖配置如下:

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

需求

隐藏接口文档中Responses(响应)、Request body(请求体)区域内嵌的Schema模块,仅展示Example Value(示例值)。

已验证的无效方案

  • 在application.properties中添加配置springdoc.swagger-ui.defaultModelsExpandDepth=-1:仅可隐藏页面底部的公共Schema列表,无法移除请求体、响应区域内的内嵌Schema模块
  • 注解配置content= @Content(schema = @Schema(hidden = true )):会将整个请求体/响应内容块全部隐藏,不符合需求

历史配置代码

原有响应配置

@ApiResponses({
            @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(name = "Success response", example = "JsonResponse..."),
                    mediaType = MediaType.APPLICATION_JSON_VALUE)),
            @ApiResponse(responseCode = "400", description = "BAD REQUEST", content = @Content(schema = @Schema(hidden = true))) 
    })

原有请求体配置

@io.swagger.v3.oas.annotations.parameters.RequestBody(
            content= @Content(schema = @Schema(example="JsonRequestBody...")))

已实现的效果

目前响应区域的Schema隐藏方案已验证通过:不在@Content中配置schema属性,直接通过examples属性绑定@ExampleObject定义示例,即可实现响应区仅展示示例值、不显示Schema模块,配置代码如下:

@ApiResponse(responseCode = IConstants.R_str_200, content = @Content(examples=
@ExampleObject(name="SUCCESS RESPONSE",value="Json response..."),
                mediaType = IConstants.MEDIA_JSONVALUE))

待解决问题

目前尚未找到Request Body(请求体)区域隐藏Schema模块、仅保留示例值展示的可行配置方案。


内容的提问来源于stack exchange,提问作者M123

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.01 14:01:26