swagger-api / swagger-api/swagger-codegen
[CodeGen][R] Error in sprintf ... invalid format '%d'; use format %f, %e, %g or %a for numeric objects
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
I am facing an issue when working with "double" in the API, the R generator uses %d to format these fields but sprintf is not able to coerce correctly and fails with something like the following:
Error in sprintf("{\n \"name\": %s,\n \"lat\": %d,\n \"lon\": %d,\n \"pk\": %s\n }", :
invalid format '%d'; use format %f, %e, %g or %a for numeric objects
For the reference, here is the line where it is done:
https://github.com/swagger-api/swagger-codegen/blob/dbd0a4bb535de0d587c9ccec1465a25c8288ee96/modules/swagger-codegen/src/main/resources/r/model.mustache#L101
Maybe can we simply use %f for numeric types instead?
Besides, it's really useful to have R in now :-).
thanks!
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 at modules/swagger-codegen/src/main/resources/r/model.mustache, specifically the formatting line around L101. Reproduce the reported R sprintf failure with a double field and inspect how numeric types are rendered. Done means generated R models format numeric values without the invalid %d error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100