OpenAPITools / OpenAPITools/openapi-generator
[BUG] Java Jersey2 client throw exception when post multipart/form-data body
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I tried to generate Java Jersey 2 client based on json file (attached below), when I test operation "/stbCheckout" that POST multipart/form-data, I caught this error:
client.ApiException: multipart/form-data not yet supported for serializeToString (http signature authentication)
I found this error cause by method "ApiClient.invokeAPI", it called:
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
serializeToString(body, formParams, contentType, isBodyNullable),
method,
target.getUri());
and serializeToString method throw exception when contentType == multipart/form-data:
public String serializeToString(Object obj, Map<String, Object> formParams, String contentType, boolean isBodyNullable) throws ApiException {
try {
if (contentType.startsWith("multipart/form-data")) {
throw new ApiException("multipart/form-data not yet supported for serializeToString (http signature authentication)");
} else if (contentType.startsWith("application/x-www-form-urlencoded")) {
String formString = "";
for (Entry<String, Object> param : formParams.entrySet()) {
formString = param.getKey() + "=" + URLEncoder.encode(parameterToString(param.getValue()), "UTF-8") + "&";
}
openapi-generator version
OpenAPI declaration file content or url
{
"openapi": "3.0.2",
"info": {
"title": "Sacombank Subscription Gateway",
"version": "3.0"
},
"servers": [
{
"url": "https://cardtest.sacombank.com.vn:9448/checkout"
}
],
"components": {
"schemas": {
"CheckoutRequestBody": {
"type": "object",
"required": [
"ProfileID",
"AccessKey",
"TransactionID",
"TransactionDateTime",
"Language",
"IsTokenRequest",
"Currency",
"FirstName",
"LastName",
"Gender",
"Address",
"District",
"City",
"Country",
"Email",
"Mobile",
"ReturnUrl",
"CancelUrl",
"Signature"
],
"properties": {
"ProfileID": {
"type": "string",
"description": "Merchant's profile id",
"minLength": 1,
"maxLength": 32
},
"AccessKey": {
"type": "string",
"minLength": 1,
"maxLength": 32
},
"TransactionID": {
"type": "string",
"minLength": 1,
"maxLength": 32
},
"TransactionDateTime": {
"type": "string",
"format": "date-time",
"minLength": 1,
"maxLength": 32
},
"Language": {
"type": "string",
"minLength": 2,
"maxLength": 2
},
"SubscribeOnly": {
"type": "boolean"
},
"IsTokenRequest": {
"type": "boolean"
},
"Description": {
"type": "string",
"minLength": 1,
"maxLength": 60
},
"TotalAmount": {
"type": "number",
"minLength": 1,
"maxLength": 15
},
"DomesticFee": {
"type": "number",
"minLength": 1,
"maxLength": 15
},
"InternationalFee": {
"type": "number",
"minLength": 1,
"maxLength": 15
},
"SSN": {
"type": "string"
},
"Currency": {
"type": "string",
"minLength": 3,
"maxLength": 3
},
"CorporateCust": {
"type": "boolean"
},
"TaxIdentificationNumber": {
"type": "string",
"maxLength": 20
},
"CompanyName": {
"type": "string",
"maxLength": 50
},
"FirstName": {
"type": "string",
"minLength": 1,
"maxLength": 60
},
"LastName": {
"type": "string",
"minLength": 1,
"maxLength": 60
},
"Gender": {
"type": "string",
"minLength": 1,
"maxLength": 1
},
"Address": {
"type": "string",
"minLength": 1,
"maxLength": 60
},
"District": {
"type": "string",
"minLength": 1,
"maxLength": 60
},
"City": {
"type": "string",
"minLength": 1,
"maxLength": 60
},
"PostalCode": {
"type": "string",
"minLength": 1,
"maxLength": 15
},
"Country": {
"type": "string"
},
"Email": {
"type": "string",
"minLength": 1,
"maxLength": 255
},
"Mobile": {
"type": "string",
"minLength": 1,
"maxLength": 15
},
"ReturnUrl": {
"type": "string"
},
"CancelUrl": {
"type": "string"
},
"Signature": {
"type": "string"
}
}
}
}
},
"paths": {
"/stbCheckout": {
"post": {
"tags": [
"Sacombank Subscription Service"
],
"operationId": "stbCheckout",
"description": "Checkout",
"requestBody": {
"description": "Request Body",
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"$ref": "#/components/schemas/CheckoutRequestBody"
}
}
}
},
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/stbCheckoutJSON": {
"post": {
"tags": [
"Sacombank Subscription Service"
],
"operationId": "stbCheckoutJSON",
"description": "Checkout",
"requestBody": {
"description": "Request Body",
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CheckoutRequestBody"
}
}
}
},
"responses": {
"200": {
"description": "OK"
}
}
}
}
}
}
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
I can temporary fix it by create a derived class of ApiClient that overload serializeToString to allow multipart/form-data content type, but I think should not throw exception in this method
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated Java Jersey2 ApiClient.invokeAPI entry point and its serializeToString method, using the supplied OpenAPI declaration with the /stbCheckout multipart/form-data operation. Reproduce the HTTP signature authentication path and trace how multipart parameters are handled; done means the operation no longer fails with the reported serializeToString exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100