Ask a Question

Generated Java endpoints for array body

marcinluczynski
New Contributor

Generated Java endpoints for array body

I have a following parameter definition in a PATCH request:

- name: patch_request
in: body
required: true
schema:
$ref: '#/definitions/JSONResourcePatchRequestModel'

The object in $ref is the following:

JSONResourcePatchRequestModel: 
type: array
items:
$ref: '#/definitions/JSONResourcePatchModel'

Which is converted as expected into the following model class:

public class JSONResourcePatchRequestModel extends ArrayList<JSONResourcePatchModel> implements Serializable{

The API Java method generated by old Swagger looks like this:

Response updateConnection(@ApiParam(value = "Fields to update within the connection." ,required=true) JSONResourcePatchRequestModel patchRequest)

However the very same swagger.yaml and model definitions when passed through Swagger 3.0 result with a slight change:

Response updateConnection(@Parameter(in = ParameterIn.DEFAULT, required=true) List<JSONResourcePatchModel> body)

So instead of a class put as a schema ref, we get its base type (the one that it actually extends). My hunch says that that's the cause of the error that occurs when API gets tested:

Caused by: java.lang.ClassCastException: java.util.LinkedHashMap incompatible with com.ibm.wdp.connect.common.api.models.JSONResourcePatchModel

Apparently the type that's supposed to be there is not exactly the same as expected, Jackson mapper has a problem with proper deserialization of a request so it goes to its fallback which means all the body's JSON content gets mapped into ArrayList<LinkedHashMap> type of the object and it causes the exception.

Why the change? Why would this method simply not receive JSONResourcePatchRequestModel type for the body content?

1 REPLY 1
marcinluczynski
New Contributor

I found the root cause. This behavior is observed with 3.0 libraries and codegen, but with 2.0 version provided in the yaml template.

cancel
Showing results for 
Search instead for 
Did you mean: