gpt4 book ai didi

java - 如何在 swagger yaml 中为 Swagger dode 生成提供通用返回类型?

转载 作者:行者123 更新时间:2023-12-01 23:00:45 24 4
gpt4 key购买 nike

如果通过 swaggercodegen 生成的相同剩余方法失败,我必须返回 GetPaymentRepsonse 和 AuthenticationException。

我有一个类似的解决方案

default ResponseEntity<?> getPayment(String id,
String agent,
String contact,
String token) {

return new ResponseEntity<PaymentResponse>(HttpStatus.OK);
}
@Override public ResponseEntity<?> getPayment(String id, String agent, String contact, String token) {

try {
........
..........
return paymentReposne;
} else {
throw new AuthenticationException(Enum.SomeException);
}

} catch (AuthenticationException | IOException | TokenServiceException e) {
return UtilClass.someCustomAuthenticationException(e);
}
}

Swagger 设计

/v2.0/.../.../....:
get:
operationId: getPayment
tags:
- something
description:
xxx xxx xxx xxxx
parameters:
- $ref: "#/parameters/token"
- $ref: "#/parameters/id"
- $ref: "#/parameters/agent"
- $ref: "#/parameters/contact"

responses:
'200':
description: 'Successful response'
schema:
type: object --->Here i want to give Generic type or ? to support my above code on swagger code generation
'400':
description: 'Bad request parameters'

最佳答案

您可以执行如下操作:-

get:
operationId: getPayment
tags:
- something
description:
xxx xxx xxx xxxx
parameters:
- $ref: "#/parameters/token"
- $ref: "#/parameters/id"
- $ref: "#/parameters/agent"
- $ref: "#/parameters/contact"

responses:
'200':
description: Fetched Successfully
content:
application/json:
schema:
$ref: '#/components/schemas/ResponseEntity'
'400':
$ref: '#/components/responses/AuthenticationException'

components:
schemas:
ErrorResponse:
type: object
properties:
statusCode:
type: integer
example: 400
message:
type: string

responses:
AuthenticationException:
description: The specified resource was not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'

关于java - 如何在 swagger yaml 中为 Swagger dode 生成提供通用返回类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58423062/

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