如何在Swagger API定义中发送对象参数?

时间:2018-10-29 17:33:03

标签: java swagger swagger-ui swagger-editor

我具有以下API定义端点:

paths:
  /pricing/reservation:
    get:
      tags:
      - Pricing
      summary: Get a reservation base price
      description: Returns the pricing for a reservation
      operationId: getReservationPricing
      produces:
      - application/json
      parameters:
      - name: beginDate
        in: query
        description: reservation begin date
        required: true
        type: integer
        format: int64
      - name: endDate
        in: query
        description: reservation end date
        required: true
        type: integer
        format: int64
      - in: body
        name: vehicle
        description: Vehicle objec
        required: true
        schema:
          $ref: '#/definitions/Vehicle'
      responses:
        200:
          description: successful operation
          schema:
            type: number
            format: float
        404:
          description: Vehicle not found

我想通过参数请求一个Vehicle对象,然后通过Bitbucket集成,用Java生成API接口。这样,我可以覆盖API控制器并定义端点逻辑。

我的问题是,是否有一种方法可以从Swagger定义中定义一个通用对象,还是我可以像上面的代码中那样定义Swagger对象定义,然后将其映射到Java中?

API使用Swagger模式生成接口:

@ApiOperation(value = "Get a reservation base price", nickname = "getReservationPricing", notes = "Returns the pricing for a reservation", response = Float.class, authorizations = {
    @Authorization(value = "api_key")
}, tags={ "Pricing", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "successful operation", response = Float.class),
    @ApiResponse(code = 404, message = "Vehicle not found") })
@RequestMapping(value = "/pricing/reservation",
    produces = { "application/json" }, 
    method = RequestMethod.GET)
ResponseEntity<Float> getReservationPricing(@NotNull @ApiParam(value = "reservation begin date", required = true) @Valid @RequestParam(value = "beginDate", required = true) Long beginDate,@NotNull @ApiParam(value = "reservation end date", required = true) @Valid @RequestParam(value = "endDate", required = true) Long endDate,@ApiParam(value = "Vehicle object that needs to be added to the fleet" ,required=true )  @Valid @RequestBody Vehicle vechicle);

感谢您的帮助!

0 个答案:

没有答案