首页 > 解决方案 > 如何在 Swagger Codegen 生成的 jaxrs-cxf-client 中读取响应的 HTTP 状态?

问题描述

我正在使用通过 SwaggerHub 上的 OpenAPI 指定的 REST API 的客户端。在这里,我读到了这样的内容:

    put:
      tags:
        - load
      summary: adds a Demand item
      operationId: addDemandItem
      description: Adds a Demand item to the system
      security:
        - basicAuth: []
      responses:
        '200':
          description: item correctly saved
        '401':
          description: 'unauthorized'
        '400':
          description: 'invalid input, object invalid'
      parameters:
        - in: path
          name: partnerReferenceId
          schema:
            type: string
          required: true
          description: partnerReferenceId identifying the demand
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DemandItem'
        description: Demand item to add

自动生成的客户端 (jaxrs-cxf-client) 具有以下 Java 代码:

    @PUT
    @Path(value = "/demands/{partnerReferenceId}")
    @Consumes(value = {"application/json"})
    @Operation(summary = "adds a Demand item", tags = {})
    @ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "item correctly saved"),
        @ApiResponse(responseCode = "400", description = "invalid input, object invalid"),
        @ApiResponse(responseCode = "401", description = "unauthorized")})
    public void addDemandItem(@PathParam(value = "partnerReferenceId") String string, DemandItem di);

如何读取响应的 HTTP 状态?

标签: javarestswaggerswagger-codegen

解决方案


推荐阅读