如何使Spring Java服务器的OpenApi生成器为PUT请求生成ResponseEntity <Object>?

问题描述

我正在使用openapi-generator-maven-plugin的4.3.1版本在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","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","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",@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请求?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)