swagger-api / swagger-api/swagger-codegen
[ALL] [3.0] No description for parameters in form-data request bodies
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I'm switching from Swagger to OpenAPI and noticed that Codegen no longer generates descriptions for parameters of "form-data" request bodies. This used to work (and should be working if I interpret the spec correctly).
Swagger-codegen version
I'm using version 3.0.4. It's a regression to Swagger (i.e. v2).
Swagger declaration file content or url
openapi: 3.0.0
info:
title: Test Api
version: '1.0.0'
paths:
"/pet":
post:
summary: Updates a pet in the store with form data
operationId: updatePetWithForm
requestBody:
description: pet update data
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
name:
description: Updated name of the pet
type: string
status:
description: Updated status of the pet
type: string
responses:
"405":
description: Invalid input
Command line used for generation
java -jar swagger-codegen-cli-3.0.4.jar generate --input-spec test.openapi.yaml --lang java --output generated
Steps to reproduce
- Generate code with information above
- Inspect file
generated/src/main/java/io/swagger/client/api/DefaultApi.java
Notice that the generated documentation for updatePetWithForm() is like this:
/**
* Updates a pet in the store with form data
*
* @param name (optional)
* @param status (optional)
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
Notice how no description is inserted for name or status.
Related issues/PRs
I found no related issues.
Suggest a fix/enhancement
The problem is "introduced" in DefaultCodegenConfig.fromOperation(). There is a block that handles request bodies with mime types application/x-www-form-urlencoded and multipart/form-data. In that block the CodegenParameter instances are created like this:
CodegenParameter formParameter = fromParameter(new Parameter()
.name(propertyName)
.schema(propertyMap.get(propertyName)), imports);
The problem now is that the description is (only) in the schema - but neither Parameter.schema() nor Parameter.getDescription() "transfer" the description from the schema.
Thus, when the CodegenParameter is created by DefaultCodegenConfig.fromParameter(), this code "generates" an empty description:
codegenParameter.description = escapeText(parameter.getDescription());
The problem could be solved in all of these 4 places - but I have no idea what would be the best place (although I think the last option would be the "worst"):
DefaultCodegenConfig.fromOperation()Parameter.schema()Parameter.getDescription()DefaultCodegenConfig.fromParameter()
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 in DefaultCodegenConfig.fromOperation(), where form-data CodegenParameter instances are created, then trace DefaultCodegenConfig.fromParameter() and the schema description handling. Re-run the shown Java generation command and inspect generated/src/main/java/io/swagger/client/api/DefaultApi.java; done means the generated updatePetWithForm() documentation includes descriptions for name and status.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100