【发布时间】:2020-10-28 15:27:12
【问题描述】:
我正在使用 4.3.1 版本的 openapi-generator-maven-plugin 在 Java 11 中生成 SpringBoot 服务器。
对于 PUT 请求,我希望能够在成功时将 URI 返回到创建/更新的对象,并在不成功时返回带有问题信息的纯文本。
我的 API json 包含以下 PUT 请求内容:
"put": {
"summary": "Create or update a Service",
"deprecated": false,
"operationId": "putIndividualServiceUsingPUT",
"responses": {
"200": {
"description": "Service updated"
},
"201": {
"description": "Service created",
"content": {
"text/plain": {
"schema": {
"type": "string",
"example": "services/DroneIdentifier"
}
}
}
},
"400": {
"description": "Provided service is not correct",
"content": {
"text/plain": {
"schema": {
"type": "string",
"example": "Service is missing required property version"
}
}
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
}
},
"parameters": [
{
"name": "serviceName",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"example": "DroneIdentifier"
}
],
"requestBody": {
"description": "Service to create/update",
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/service"
}
}
}
}
生成的 API:
/**
* PUT /services/{serviceName} : Create or update a Service
*
* @param serviceName (required)
* @param service Service to create/update (required)
* @return Service updated (status code 200)
* or Service created (status code 201)
* or Provided service is not correct (status code 400)
* or Unauthorized (status code 401)
* or Forbidden (status code 403)
*/
@ApiOperation(value = "Create or update a Service", nickname = "putIndividualServiceUsingPUT", notes = "", tags={ "rAPP Catalogue API", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Service updated"),
@ApiResponse(code = 201, message = "Service created", response = String.class),
@ApiResponse(code = 400, message = "Provided service is not correct", response = String.class),
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 403, message = "Forbidden") })
@RequestMapping(value = "/services/{serviceName}",
produces = { "text/plain" },
consumes = { "application/json" },
method = RequestMethod.PUT)
default ResponseEntity<Void> putIndividualServiceUsingPUT(@ApiParam(value = "",required=true) @PathVariable("serviceName") String serviceName,@ApiParam(value = "Service to create/update" ,required=true ) @Valid @RequestBody Service service) {
return getDelegate().putIndividualServiceUsingPUT(serviceName, service);
}
但是,该方法的返回类型是ResponseEntity<Void>,这意味着我无法在响应正文中放入任何内容。
我做错了吗?还是生成器被硬编码为不允许在 PUT 请求的响应中使用主体?
【问题讨论】:
标签: java spring-boot code-generation openapi