fix(kotlin-restclient): only emit first consumes type as Content-Type - #24502
Open
bugs84 wants to merge 1 commit into
Open
fix(kotlin-restclient): only emit first consumes type as Content-Type#24502bugs84 wants to merge 1 commit into
bugs84 wants to merge 1 commit into
Conversation
For operations with no formData parameters but multiple declared consumes media types (e.g. a body param whose endpoint also supports a separate multipart variant), the jvm-spring-restclient api.mustache template emitted one localVariableHeaders["Content-Type"] = ... assignment per consumes entry. Since all assignments target the same map key, the last declared media type always won, regardless of which one actually matches the serialized body. Mirror the sibling hasFormParams branch just above (which already uses consumes.0) by only emitting the first consumes entry here too. Fixes OpenAPITools#24500
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #24500.
For operations with no formData parameters but multiple declared consumes media types (e.g. an endpoint that accepts both a JSON body and a separate multipart/form-data variant), the jvm-spring-restclient api.mustache template emitted one localVariableHeaders["Content-Type"] = ... assignment per consumes entry. Since every assignment targets the same map key, the last declared media type always won at runtime — regardless of which one actually matched the body being serialized.
This mirrors the sibling hasFormParams branch a few lines above in the same template, which already guards against this by using consumes.0 instead of iterating over all consumes entries. This PR applies the same fix to the hasFormParams=false branch.
Verified with a minimal reproduction spec (attached to #24500) and by regenerating all jvm-spring-restclient Petstore samples: only samples/client/petstore/kotlin-jvm-spring-3-restclient/.../PetApi.kt changes, removing the previously-bogus second Content-Type assignment on addPet / updatePet (which declare consumes: [application/json, application/xml] ) — confirming the same latent bug was already present in the committed sample and is fixed by this change.
Note: this fix makes content-type selection deterministic by always using the first consumes entry (matching the native Java library's convention), but is still order-dependent, unlike Java's restclient / resttemplate / webclient libraries which use a runtime selectHeaderContentType helper that prefers JSON regardless of position. See comment on #24500 for a possible follow-up.
Summary by cubic
Set Content-Type to the first declared consumes media type in the Kotlin
jvm-spring-restclientgenerator when no form params are present. This prevents duplicate header assignments where the last consumes value wins (fixes #24500).api.mustache, useconsumes.0forContent-TypewhenhasFormParams=falseinstead of iterating allconsumes.hasFormParamsbranch and makes selection deterministic.Content-Typeassignment.Written for commit 763dafb. Summary will update on new commits.