Bug Report Checklist
Description
The java okhttp-gson client (and likely other Java clients) always send an empty object in the request body for DELETE (and likely POST and PUT) operations which do not define requestBody. Since DELETE request payload has no defined semantics this is likely to cause compatibility issues (and causes 4XX responses from the API I am working with).
openapi-generator version
The issue first appeared in 0fb1ffa (#98) and still occurs on master (0cb9212).
OpenAPI declaration file content or url
openapi: '3.0.2'
info:
title: delete example
version: '1.0.0'
servers:
- url: http://example.com/api
components:
schemas:
Error:
type: object
properties:
message:
type: string
paths:
/:
delete:
responses:
'204':
description: Deleted
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
(Note: At least one schema must be defined for the generated code to compile, so I added Error for this purpose.)
Command line used for generation
openapi-generator-cli.jar generate -i openapi.yaml -g java -o openapi-generator-test-client
Steps to reproduce
- Generate the code using the YAML spec and command from above, replacing
example.com/api with a test server.
- Create
src/main/java/TestApp.java with content
import org.openapitools.client.*;
import org.openapitools.client.api.*;
public class TestApp {
public static void main(String[] args) throws ApiException {
ApiClient apiClient = new ApiClient();
DefaultApi defaultApi = new DefaultApi(apiClient);
defaultApi.rootDelete();
}
}
- Run
gradle -DmainClass=TestApp execute and observe traffic on the test server.
The client generated from code before 0fb1ffa will send:
DELETE /api/ HTTP/1.1
Accept: application/json
Content-Type: application/json
User-Agent: OpenAPI-Generator/1.0.0/java
Host: example.com
Connection: Keep-Alive
Accept-Encoding: gzip
The client generated with 0fb1ffa or later will send:
DELETE /api/ HTTP/1.1
Accept: application/json
User-Agent: OpenAPI-Generator/1.0.0/java
Content-Type: application/json; charset=utf-8
Content-Length: 2
Host: example.com
Connection: Keep-Alive
Accept-Encoding: gzip
{}
Suggest a fix
This was fixed for resttemplate by #605 but not for jersey2, okhttp-gson, or resteasy. Reverting 0fb1ffa for the other clients would fix this, but presumably reintroduce #98 (although I'm not sure why Jackson would be called to serialize null, presumably we could just stop doing that).
Thoughts from the participants on #98 and #605? @bmordue, @jmini, @rubms
Bug Report Checklist
Description
The java
okhttp-gsonclient (and likely other Java clients) always send an empty object in the request body forDELETE(and likelyPOSTandPUT) operations which do not definerequestBody. SinceDELETErequest payload has no defined semantics this is likely to cause compatibility issues (and causes 4XX responses from the API I am working with).openapi-generator version
The issue first appeared in 0fb1ffa (#98) and still occurs on
master(0cb9212).OpenAPI declaration file content or url
(Note: At least one schema must be defined for the generated code to compile, so I added
Errorfor this purpose.)Command line used for generation
openapi-generator-cli.jar generate -i openapi.yaml -g java -o openapi-generator-test-clientSteps to reproduce
example.com/apiwith a test server.src/main/java/TestApp.javawith contentgradle -DmainClass=TestApp executeand observe traffic on the test server.The client generated from code before 0fb1ffa will send:
The client generated with 0fb1ffa or later will send:
Suggest a fix
This was fixed for resttemplate by #605 but not for
jersey2,okhttp-gson, orresteasy. Reverting 0fb1ffa for the other clients would fix this, but presumably reintroduce #98 (although I'm not sure why Jackson would be called to serializenull, presumably we could just stop doing that).Thoughts from the participants on #98 and #605? @bmordue, @jmini, @rubms