Description
When a request body offers multiple content types (e.g. application/json + application/xml + application/x-www-form-urlencoded), the generator drops the JSON body and emits an empty form submission, producing a request that sends nothing.
Reproduced with the canonical Swagger Petstore POST /pet (addPet) and PUT /pet (updatePet), whose request body is:
content:
application/json: { schema: { $ref: '#/components/schemas/Pet' } }
application/xml: { ... }
application/x-www-form-urlencoded: { ... }
Generated output:
public suspend fun addPet(): HttpResult<JsonElement, Pet> = safeCall {
client.submitForm(
url = """${baseUrl}/pet""",
formParameters = parameters {
} // <-- empty, and no `body` parameter on the function at all
) { applyAuth() }.toResult()
}
The Pet body is never sent.
Root causes
- Content-type priority (
ContentType enum order: MULTIPART_FORM_DATA, FORM_URL_ENCODED, JSON_CONTENT_TYPE). SpecParser picks the first matching entry, so application/x-www-form-urlencoded wins over application/json. For request bodies, JSON should be preferred.
- Form/multipart extraction ignores
$ref bodies. ParametersGenerator.buildFormParameters / buildMultipartParameters read requestBody.schema.properties, but TypeRef.properties only returns properties for TypeRef.Inline — a $ref (TypeRef.Reference) yields emptyList, so the form has no fields even when the chosen content type is form.
Acceptance criteria
Discovered in
Manual review of generated output for vendored public specs (PR #90, issue #47).
Description
When a request body offers multiple content types (e.g.
application/json+application/xml+application/x-www-form-urlencoded), the generator drops the JSON body and emits an empty form submission, producing a request that sends nothing.Reproduced with the canonical Swagger Petstore
POST /pet(addPet) andPUT /pet(updatePet), whose request body is:Generated output:
The
Petbody is never sent.Root causes
ContentTypeenum order:MULTIPART_FORM_DATA,FORM_URL_ENCODED,JSON_CONTENT_TYPE).SpecParserpicks the first matching entry, soapplication/x-www-form-urlencodedwins overapplication/json. For request bodies, JSON should be preferred.$refbodies.ParametersGenerator.buildFormParameters/buildMultipartParametersreadrequestBody.schema.properties, butTypeRef.propertiesonly returns properties forTypeRef.Inline— a$ref(TypeRef.Reference) yieldsemptyList, so the form has no fields even when the chosen content type is form.Acceptance criteria
$refextract the referenced schema's properties.addPet/updatePetfrom the Swagger Petstore spec generate abody: Petparameter and send it.fixtures/public/swagger-petstore.jsonis a good candidate).Discovered in
Manual review of generated output for vendored public specs (PR #90, issue #47).