swagger-api / swagger-api/swagger-codegen

[CodeGen][R] Error in sprintf ... invalid format '%d'; use format %f, %e, %g or %a for numeric objects

Open
#8,531 2 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.