作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果通过 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/
我是一名优秀的程序员,十分优秀!