I'm working with a client of a REST API specified through OpenAPI on SwaggerHub. Here I read something like this:
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
The auto-generated client (jaxrs-cxf-client) has the following Java code:
@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);
How can I read the HTTP status of the response?
java
if you use Swagger Codegen). – Helen Jan 14 at 17:59addDemandItem
returnsvoid
notResponse
, then how to read HTTP Status? – Renato Jan 14 at 18:25useGenericResponse
argument. E.g.-DuseGenericResponse=true
if you run codegen from command line; or if you export from SwaggerHub, this option can be set in Export > Codegen Options (assuming you have edit access to the API in question). This will useResponse
as the return type for all methods. – Helen Jan 14 at 19:16