[BUG][KOTLIN] multiplatform/jvm-ktor: `DELETE` without `requestBody` sends `"Content-Type: application/json"` with an empty body
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
Línea de trabajo
Lee modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/ApiClient.kt.mustache y el correspondiente libraries/jvm-ktor/infrastructure/ApiClient.kt.mustache; inspecciona cómo la función request gestiona EmptyContent y los métodos que establecen el tipo de contenido y el cuerpo. Revisa las pruebas existentes de las plantillas para estas bibliotecas y verifica que un DELETE generado sin requestBody omita el tipo de contenido y el cuerpo, mientras que uno con un cuerpo JSON siga enviándolos.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- 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?
Description
For operations without a requestBody, the kotlin client with library=multiplatform generates localVariableBody = io.ktor.client.utils.EmptyContent. ApiClient.request then sets a JSON content type and the body for every PUT, POST, PATCH, and DELETE, regardless of whether there is a body:
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH, RequestMethod.DELETE)) {
val contentType = (requestConfig.headers[HttpHeaders.ContentType]?.let { ContentType.parse(it) }
?: ContentType.Application.Json)
this.contentType(contentType)
this.setBody(body)
}
As a result, a DELETE /items/{id}?row=1 without a request body goes out with Content-Type: application/json and Content-Length: 0. Servers that bind a JSON body whenever the content type says JSON reject the request. ASP.NET Core with FastEndpoints answers:
{"statusCode":400,"message":"One or more errors occurred!","errors":{"/SerializerErrors":["The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0."]}}
The same DELETE succeeds when the client omits the Content-Type header. DELETE operations that do declare a JSON requestBody work as expected.
The same block exists in libraries/jvm-ktor/infrastructure/ApiClient.kt.mustache.
openapi-generator version
7.25.0 (Gradle plugin org.openapi.generator). The same code is in the 7.26.0 templates and on master (modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/ApiClient.kt.mustache, the request function). Not a regression as far as I can tell.
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Delete without body
version: 1.0.0
paths:
/items/{id}:
delete:
operationId: deleteItem
parameters:
- name: id
in: path
required: true
schema:
type: string
- name: rowVersion
in: query
required: true
schema:
type: integer
responses:
'204':
description: Deleted
Generation Details
generatorName: kotlin
library: multiplatform
additionalProperties:
dateLibrary: kotlinx-datetime
Steps to reproduce
- Generate the client from the spec above with
-g kotlin --library multiplatform. - Call
deleteItem("1", 1)against any server, or a request logger. - Observe the request headers:
Content-Type: application/json,Content-Length: 0.
Actual: a JSON content type is sent although the operation has no request body.
Expected: no Content-Type header (and no body) when the operation declares no requestBody.
Related issues/PRs
None found (searched for "multiplatform DELETE content-type empty body" and "EmptyContent Content-Type").
Suggest a fix
Only set the content type and body when there is a body, for example:
if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH, RequestMethod.DELETE) &&
body != null && body !is io.ktor.client.utils.EmptyContent
) {
val contentType = (requestConfig.headers[HttpHeaders.ContentType]?.let { ContentType.parse(it) }
?: ContentType.Application.Json)
this.contentType(contentType)
this.setBody(body)
}
The same change applies to the jvm-ktor template.
- Lenguaje dominante
- Java
- Estrellas
- 26.8k
- Forks
- 7.7k
- Merge medio
- 1 d 15 h
- PR fusionados (30 d)
- 146
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de OpenAPITools/openapi-generator
-
[BUG][RUST] Reqwest - encoding of spaces in path parametersPosiblemente ocupada @GlenWright la tomó hoy. AbiertoIssue: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
OpenAPITools/openapi-generator#25257 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
[BUG] ExampleGenerator returns the string "{}" (or null) for `type: object` schemas without `properties`Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
OpenAPITools/openapi-generator#25237 ·
Los mantenedores suelen responder en 1 día
-
[BUG] OpenApiEvaluator reports "default value not in enum" for numerically equal values with different scale (e.g. 1.5 and 1.50)Posiblemente ocupada @mohitduhan19 la tomó hace 2 días. AbiertoIssue: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
OpenAPITools/openapi-generator#25233 ·
Los mantenedores suelen responder en 1 día
-
[BUG] OpenApiEvaluator emits "Unused model" warnings even when recommendations are disabledPosiblemente ocupada @mohitduhan19 la tomó hace 2 días. AbiertoIssue: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
OpenAPITools/openapi-generator#25232 ·
Los mantenedores suelen responder en 1 día
-
Issue: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
OpenAPITools/openapi-generator#25218 ·
Los mantenedores suelen responder en 1 día
Todos los issues de OpenAPITools/openapi-generator
Issues similares
-
:maddi-inspection-kotlin:test runs out of heap in a full maddi test run; exit 1 with no failing testAbiertobuild/ci front-end:kotlin
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
uwolfer/gerrit-intellij-plugin#768 ·
Los mantenedores suelen responder en 1 día
-
github_actions
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
hiero-ledger/hiero-consensus-node#27621 ·
Los mantenedores suelen responder en 1 día
-
x:knowledge/elementary x:module/practice-exercise
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100