swagger-api / swagger-api/swagger-codegen

[Ruby] string interpolation in client code dose not work

Open
#9,094 0 comments 1 reaction 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

Description

The interpolation in the error message of Ruby's client dose not work.

Swagger-codegen version
$ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar version
2.4.2-SNAPSHOT

$ git log --oneline -n 1
c4c5c062c Merge pull request #9080 from swagger-api/update-parser-v1
Swagger declaration file content or url

https://gist.github.com/autopp/5a7375cd9b521b5e5580ba3b1df40c75

The point to notice in this example contains enum in the model.

Command line used for generation
$ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i 'https://gist.githubusercontent.com/autopp/5a7375cd9b521b5e5580ba3b1df40c75/raw/ca1d5eccce457c7337922b4a6a74f002848e4b4c/swagger.yml' -l ruby -o /tmp/gem
Steps to reproduce
  • Run the above command to generate client code for Ruby.
  • Generated /tmp/gem/lib/swagger_client/models/x.rb contains string interpolation notation in single-quote string. (It dose not work!)
    def y=(y)
      validator = EnumAttributeValidator.new('String', ["a"])
      unless validator.valid?(y)
        fail ArgumentError, 'invalid value for "y", must be one of #{validator.allowable_values}.'
      end
      @y = y
    end
    
Related issues/PRs
Suggest a fix/enhancement

The corresponding template is this.

I think that it should be a double-quote string.

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 with modules/swagger-codegen/src/main/resources/ruby/partial_model_generic.mustache at the referenced template location. Generate the Ruby client with the provided Swagger declaration and command, then inspect lib/swagger_client/models/x.rb. Done means the generated validation error uses working Ruby string interpolation rather than literal interpolation text.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.