Java 如何将其他属性设置为布尔值

Java 如何将其他属性设置为布尔值,java,spring,spring-boot,swagger,openapi,Java,Spring,Spring Boot,Swagger,Openapi,我试图将元素设置到OpenAPI模式3.X中,但不幸的是,我在文档中找不到任何对我有帮助的东西。 我在SpringBoot中有一个应用程序,它使用SpringDocOAS,它依赖于Swagger OAS作为可传递依赖项。 让我在这里挑选一些代码片段: @GetMapping("/{accountId}") @Operation(summary = "Get account by account id", tags = TAG) @ApiResponses(

我试图将元素设置到OpenAPI模式3.X中,但不幸的是,我在文档中找不到任何对我有帮助的东西。 我在SpringBoot中有一个应用程序,它使用SpringDocOAS,它依赖于Swagger OAS作为可传递依赖项。 让我在这里挑选一些代码片段:

@GetMapping("/{accountId}")
@Operation(summary = "Get account by account id", tags = TAG)
@ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "Return a specific account queried by path",
                content = { @Content(mediaType = "application/json",
                        schema = @Schema(implementation = AccountDetailsDTO.class)) }),
        @ApiResponse(responseCode = "404", description = "No accounts found",
                content = @Content) })
public ResponseEntity<AccountDetailsDTO> getAccountDetailsByClientId(@PathVariable("accountId") Integer accountId) { }
@GetMapping(“/{accountId}”)
@操作(summary=“按帐户id获取帐户”,tags=TAG)
@ApiResponses(值={
@ApiResponse(responseCode=“200”,description=“返回按路径查询的特定账户”,
content={@content(mediaType=“application/json”,
schema=@schema(实现=AccountDetailsDTO.class))}),
@ApiResponse(responseCode=“404”,description=“未找到帐户”,
content=@content)})

公共响应性

一个解决方法可能是定义一个包含类型信息的伪类,然后将其用作
@apisresponse
中的
@Schema#实现

static class YourTypeMap extends java.util.HashMap<String, YourType> {};

学分

如果要显式将属性设置为false,可以使用TransformationFilter(annoted@Component for Spring)将规范中的每个组件的附加属性设置为false(如果使用Springfox)

如果您使用的是Springdoc,那么可以添加OpenApiCustomiser bean,请参见示例

Springdoc OpenAPI示例

@Bean
公共OpenApiCustomiser OpenApiCustomiser(){
返回openApi->openApi.getComponents().getSchemas().values().forEach(s->s.setAdditionalProperties(false));
}
Springfox框架示例

@组件
@顺序(有序。最高优先级+1)
公共类OpenAPitTransformationFilter实现WebMvcOpenApiTransformationFilter
{
公共布尔值支持(@NotNull DocumentationType分隔符)
{
返回SwaggerPluginSupport.pluginDoesApply(分隔符);
}
@凌驾
公共OpenAPI转换(OpenAPI转换上下文)
{
OpenAPI=context.getSpecification();
openApi.getComponents().getSchemas().values().forEach(schema->schema.setAdditionalProperties(false));
返回openApi;
}
}

不幸的是,它不适合我的用途,因为我需要的是作为布尔类型的附加属性,而不是对象包装器(我没有使用SpringFox,所以让我试着弄清楚springdoc openapi是如何实现它的。谢谢!哦,好的,让我看看springdocthen@JanR.Krejci让我知道我的更新是否帮助您解决了您的案件。
@APIResponse(
  responseCode = "200",
  content = @Content(
    mediaType = "application/json", 
    schema = @Schema(implementation = YourTypeMap.class)))