1

I have the following API definition endpoint:

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

I want to request a Vehicle object by parameter and then, with the Bitbucket integration, generate the API interface in Java. That way I can override the API controller and define the endpoint logic.

My question is, is there a way to define a generic object from Swagger definition, or do I have (as I did in above code) to define my Swagger object definition and then map it in Java?

The API generated inteface with Swagger schema:

@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);

Thanks for your help!

MarioC
  • 81
  • 1
  • 6
  • 1
    As it's currently written, Vehicle is meant to passed in the request body, but GET requests are not supposed to have a body. Do you need to POST JSON instead? If you actually need GET, OpenAPI 3.0 provides several ways to serialize objects into the query string - see [here](https://stackoverflow.com/a/51277233/113116), [here](https://stackoverflow.com/q/34820064/113116) and [here](https://stackoverflow.com/q/49582559/113116). – Helen Oct 29 '18 at 19:24
  • Yes, thanks, it is supossed to be a POST call. In the POST case; I will need a JSON object, or I can define that my object is exactly the one I´m using in java (com....entities.vehicle)? – MarioC Oct 30 '18 at 14:30

0 Answers0