swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Swagger is unable to fetch the right variable name in the API Request Documentation

Open Jeyabal-B opened this issue 3 years ago • 3 comments

If a variable name starts with a single character followed by camel casing (aSideName), then the swagger is not able to translate the name properly. Instead it pulls the getter method of the variable (getaSideName) and shows it as the input in the swagger page. So, the API won't work now since the field name is wrong. Language: Java

Jeyabal-B avatar Apr 10 '22 18:04 Jeyabal-B

This is an issue introduced by #415 (btw the same problem appears in #2332). The name of the property is sanitized to avoid cluttering it (for example getId doesn't become getGetid) but there are too many exceptions.

It would be great if one of the maintainers could share some thoughts and see if we can change the approach (fixing the current logic seems not the right way as there would be always cases not considered.

gcatanese avatar Apr 12 '22 16:04 gcatanese

A quick fix that I found is to use the @jsonproperty annotation. This results in the swagger picking up the variable name as it is. But, we mostly do not add the annotation for the variables in the DTO class unless we require it for a specific purpose. I think the swagger should be able to identify the variable names perfectly.

Another weird thing that I noticed is that if we rename the getter slightly then it works too.

Ex: updating the getter for the variable aSideName from the default IDE generated format of getaSideName() to getASideName().

Jeyabal-B avatar Apr 12 '22 18:04 Jeyabal-B

The code checks for a get method with a lowercase letter after that (ie getaSideName), this is a fix introduced some time ago but clearly not covering every case. The jsonproperty is the way to go, however swagger-core should (in my opinion) not try to guess/update the variable name but read as is.

gcatanese avatar Apr 12 '22 19:04 gcatanese