Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Generated Ruby client contains syntax errors when pattern of properties includes single-quote #2069

Closed
5 of 6 tasks
autopp opened this issue Feb 6, 2019 · 4 comments

Comments

@autopp
Copy link
Contributor

autopp commented Feb 6, 2019

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

When pattern includes odd number of single quotes, the generated Ruby client code 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
0b66fa5c82 (HEAD -> master, origin/master, origin/HEAD) add servers to path, operation (#2048)
OpenAPI declaration file content or url

See: https://gist.github.com/autopp/e707d5d2ec36f7cfe6a3950d76d54b6f#file-swagger-yml

The point to notice in this example is that ' is included in the pattern constraint of the property y of the model x.

Command line used for generation
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate --skip-validate-spec -g ruby -o /tmp/gem -i 'https://gist.githubusercontent.com/autopp/e707d5d2ec36f7cfe6a3950d76d54b6f/raw/0ca732fa77402c3dcbb735e41eb5f6e5bc58462d/swagger.yml'
Steps to reproduce
  1. Run the above command to generate client code for Ruby.
  2. Run ruby -c /tmp/gem/lib/openapi_client/models/x.rb to check syntax of the generated model code.
  3. Get errors in lib/openapi_client/models/x.rb:
    /tmp/gem/lib/openapi_client/models/x.rb:51: syntax error, unexpected '.'
    ...ust conform to the pattern /'/.')
    ...                              ^
    /tmp/gem/lib/openapi_client/models/x.rb:60: syntax error, unexpected ')'
    ...y.nil? && @y !~ Regexp.new(/'/)
    ...                              ^
    /tmp/gem/lib/openapi_client/models/x.rb:68: syntax error, unexpected '.'
    ...ust conform to the pattern /'/.'
    ...                              ^
    /tmp/gem/lib/openapi_client/models/x.rb:206: unterminated string meets end of file
    /tmp/gem/lib/openapi_client/models/x.rb:206: syntax error, unexpected end-of-input, expecting keyword_end
    
Related issues/PRs

#2067

Suggest a fix

escapeText of RubyClientCodegen seems to escape for double-quote string literals only. However, the corresponding template uses a single quote string.
I think it is difficult for the generator to determine whether the expansion destination is a single-quote string or a double-quote string. Instead, I think that it is better to unify it with a double-quote string in the template.

@auto-labeler
Copy link

auto-labeler bot commented Feb 6, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@wing328
Copy link
Member

wing328 commented Feb 6, 2019

I think that it is better to unify it with a double-quote string in the template.

Thanks for reporting the issue. Your suggestion sounds good to me.

@autopp
Copy link
Contributor Author

autopp commented Feb 7, 2019

Your suggestion sounds good to me.

Thank you for checking. I will create a PR to resolve this with #2081 together.

@autopp autopp changed the title [BUG] Generated Ruy client contains syntax errors when pattern of properties includes single-quote [BUG] Generated Ruby client contains syntax errors when pattern of properties includes single-quote Feb 7, 2019
@autopp
Copy link
Contributor Author

autopp commented Feb 10, 2019

I will create a PR to resolve this with #2081 together.

This is similar to #2081, but the cause was different.

autopp added a commit to autopp/openapi-generator that referenced this issue Feb 13, 2019
autopp added a commit to autopp/openapi-generator that referenced this issue Feb 13, 2019
wing328 pushed a commit that referenced this issue Feb 18, 2019
* Fix usage of regular expression literals in Ruby client (#2069)

* update samples of Ruby client (#2069)
jimschubert added a commit that referenced this issue Feb 23, 2019
* master: (40 commits)
  [Python] remove default value from being fallback to example (#2213)
  Add petstore integration tests to Ruby OAS3 client (#2211)
  Gradle - make GenerateTask properties optional (#2185)
  skip bats installation (#2198)
  Something in the dependencies changed. This switch is no longer needed. (#1850)
  Use oauth token for basic bearer auth in Rust. (#2161)
  Fix missing nullable (#2189)
  Enable error handling in Java WebClient library, fixes #1243 (#1244)
  [core] fix referenced enum case (#2175)
  rest-template: allow array parameters in path using collectionFormat (#2177)
  update go petstore samples
  Fix string types for cpprestsdk client generator (#1676)
  update kotline samples
  Remove API Key Authentication code for go when cookie is used. (#1601)
  changed the package install instructions to install the .tgz package … (#1989)
  okhttp-gson: allow array parameters in path using collectionFormat (#2137)
  [Ruby] Fix regualr expression in error message (#2069) (#2139)
  [kotlin][client] bytearray conversion (#2166)
  [rust-server] Added client documentation to rust-server (#2159)
  [Java] Getter/Setter naming convention not followed in generated models (#2095)
  ...
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this issue Feb 27, 2019
…penAPITools#2139)

* Fix usage of regular expression literals in Ruby client (OpenAPITools#2069)

* update samples of Ruby client (OpenAPITools#2069)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants