gpt4 book ai didi

java - 开放API 3.0.1只读注解

转载 作者:行者123 更新时间:2023-12-01 18:33:31 25 4
gpt4 key购买 nike

我在使用 Open API 3.0.1 java 注释将特定方法的属性定义为 readOnly 时遇到一些问题。在 POST 操作期间,API 需要一个 NewAccount 模型。这是模型的截断表示;

{
"user": {
"id": "...",
...
},
"account": {
"id": "...",
...
}
}

我需要的是在此操作中将user.idaccount.id定义为readOnly。我的所有文档都是通过注释从代码生成的,这就是我到目前为止所拥有的;

    @POST
@Path("/access/accounts")
@Consumes("application/json")
@Operation(
summary = "Create a new account.",
description = "Create a new account."
)
@Tags({@Tag(name = "account")})
@RequestBody(
description = "New accounts required models.",
required = true,
content = @Content(
schema = @Schema(
implementation = NewAccount.class
)
)
)
@ApiResponses({
@ApiResponse(
responseCode = "201",
description = "The new account.",
content = @Content(
schema = @Schema(
implementation = Account.class
)
)
)
})

最佳答案

您需要将 @Schema(accessMode = Schema.AccessMode.READ_ONLY) 注释添加到 id 属性。这将在生成的 OpenAPI 定义中将 id 属性标记为 readOnly: true

示例 from here :

import io.swagger.v3.oas.annotations.media.Schema;

public class ReadOnlyFields {
@Schema(accessMode = Schema.AccessMode.READ_ONLY)
public Long id;
}

关于java - 开放API 3.0.1只读注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60115468/

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