Search code examples
data-bindingopenapiballerinaballerina-swan-lake

`error: Payload binding failed` when using OpenAPI client in Ballerina


I have below Ballerina client generated from an Open API. There, it has a type with the below definition.

enter image description here

Now when I execute the program, in runtime I am getting below error.

error: Payload binding failed: 'map<json>' value cannot be converted to 'choreo_marketplace.devportal:API': 
        field 'keyManagers' in record 'choreo_marketplace.devportal:API' should be of type 'choreo_marketplace.devportal:record {| anydata...; |}?', found '["all"]'
    at ballerina.http.2:createPayloadBindingError(http_client_payload_builder.bal:184)
       ballerina.http.2:nonNilablejsonPayloadBuilder(http_client_payload_builder.bal:166)
       ballerina.http.2:jsonPayloadBuilder(http_client_payload_builder.bal:140)
       ballerina.http.2:performDataBinding(http_client_payload_builder.bal:42)
       ballerina.http.2:processResponse(http_client_endpoint.bal:644)
       ballerina.http.2.Client:processGet(http_client_endpoint.bal:286)
cause: {ballerina/lang.value}ConversionError
    at ballerina.lang.value.0:fromJsonWithType(value.bal:370)
       ballerina.http.2:nonNilablejsonPayloadBuilder(http_client_payload_builder.bal:165)
       ... 4 more

What Im doing wrong here?


Solution

  • We get this error when there is a mismatch between the payload and the provided type definition. In this case, it seems like keyManagers is an array. But what we have in the type definition is a record. Changing keyManagers field type to string[] will fix the issue.