OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.81k stars 6.33k forks source link

[BUG] [Ruby] `samples/client/petstore-security-test/ruby` contains syntax errors #2155

Open autopp opened 5 years ago

autopp commented 5 years ago

Bug Report Checklist

Description

Generated Ruby client code in samples/client/petstore-security-test/ruby contains syntax errors.

openapi-generator version
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar version
4.0.0-SNAPSHOT

$ git log --oneline -n 1
b6c2266a14 (HEAD -> master, origin/master, origin/HEAD) [Rust][Client] Code format (#2042)
OpenAPI declaration file content or url

N/A

Command line used for generation
$ cd samples/client/petstore-security-test/ruby
$ rubocop
Steps to reproduce
  1. Run the above command to check syntax of samples.
  2. Get errors:

    $ rubocop -f s
    == lib/petstore/configuration.rb ==
    E:220: 46: Lint/Syntax: unexpected token tEQL
    (Using Ruby 2.2 parser; configure using TargetRubyVersion parameter, under AllCops)
    E:220: 54: Lint/Syntax: bare backslash only allowed before newline
    (Using Ruby 2.2 parser; configure using TargetRubyVersion parameter, under AllCops)
    E:220: 56: Lint/Syntax: bare backslash only allowed before newline
    (Using Ruby 2.2 parser; configure using TargetRubyVersion parameter, under AllCops)
    E:220: 59: Lint/Syntax: bare backslash only allowed before newline
    (Using Ruby 2.2 parser; configure using TargetRubyVersion parameter, under AllCops)
    E:220: 62: Lint/Syntax: bare backslash only allowed before newline
    (Using Ruby 2.2 parser; configure using TargetRubyVersion parameter, under AllCops)
    W:220: 68: Lint/Syntax: *' interpreted as argument prefix
    (Using Ruby 2.2 parser; configure using TargetRubyVersion parameter, under AllCops`)
    F:220: 69: Lint/Syntax: unterminated string meets end of file
    (Using Ruby 2.2 parser; configure using TargetRubyVersion parameter, under AllCops)
    
    15 files inspected, 7 offenses detected
Related issues/PRs

2101

Suggest a fix

The cause is here. I think that the embedded URL must be escaped.

autopp commented 5 years ago

I have found another place to embed {{url}}} as a string literal.

I think that these client codes also have the same problem.

autopp commented 5 years ago

I think that the embedded URL must be escaped.

I also found a place where url is used as HTML escaped in comments. E.g.: https://github.com/OpenAPITools/openapi-generator/blob/1d08296f964c4dc947ac84c058b77f2de551fd66/modules/openapi-generator/src/main/resources/Java/api.mustache#L60 If all urls are escaped with escapeText, it seems to be a problem in such a case.

For string literals it may be better not to use url.