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

[Ruby] Use double-quote string to enable string interpolation #2068

Merged
merged 1 commit into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
def {{{name}}}=({{{name}}})
validator = EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}])
unless validator.valid?({{{name}}})
fail ArgumentError, 'invalid value for "{{{name}}}", must be one of #{validator.allowable_values}.'
fail ArgumentError, "invalid value for \"{{{name}}}\", must be one of #{validator.allowable_values}."
end
@{{{name}}} = {{{name}}}
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.1-SNAPSHOT
4.0.0-SNAPSHOT
2 changes: 1 addition & 1 deletion samples/client/petstore-security-test/ruby/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Style/UnneededPercentQ:

# Align `end` with the matching keyword or starting expression except for
# assignments, where it should be aligned with the LHS.
Lint/EndAlignment:
Layout/EndAlignment:
Enabled: true
EnforcedStyleAlignWith: variable
AutoCorrect: true
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore-security-test/ruby/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ gemspec

group :development, :test do
gem 'rake', '~> 12.0.0'
gem 'pry-byebug'
end
2 changes: 1 addition & 1 deletion samples/client/petstore-security-test/ruby/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ require 'petstore'

api_instance = Petstore::FakeApi.new
opts = {
unknown_base_type: Petstore::UNKNOWN_BASE_TYPE.new # Object |
test_code_inject____end____rn_n_r: 'test_code_inject____end____rn_n_r_example' # String | To test code injection */ ' \\\" =_end -- \\\\r\\\\n \\\\n \\\\r
}

begin
Expand Down
8 changes: 5 additions & 3 deletions samples/client/petstore-security-test/ruby/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ Method | HTTP request | Description

To test code injection */ ' \" =_end -- \\r\\n \\n \\r

To test code injection */ ' \" =_end -- \\r\\n \\n \\r

### Example
```ruby
# load the gem
require 'petstore'

api_instance = Petstore::FakeApi.new
opts = {
unknown_base_type: Petstore::UNKNOWN_BASE_TYPE.new # Object |
test_code_inject____end____rn_n_r: 'test_code_inject____end____rn_n_r_example' # String | To test code injection */ ' \\\" =_end -- \\\\r\\\\n \\\\n \\\\r
}

begin
Expand All @@ -34,7 +36,7 @@ end

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**unknown_base_type** | [**Object**](UNKNOWN_BASE_TYPE.md)| | [optional]
**test_code_inject____end____rn_n_r** | **String**| To test code injection */ ' \\\" =_end -- \\\\r\\\\n \\\\n \\\\r | [optional]

### Return type

Expand All @@ -46,7 +48,7 @@ No authorization required

### HTTP request headers

- **Content-Type**: application/json, */ \" =_end --
- **Content-Type**: application/x-www-form-urlencoded, */ \" =_end --
- **Accept**: Not defined


Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore-security-test/ruby/lib/petstore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r
Contact: [email protected] */ ' \" =_end -- \\r\\n \\n \\r
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 3.1.1-SNAPSHOT
OpenAPI Generator version: 4.0.0-SNAPSHOT

=end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r
Contact: [email protected] */ ' \" =_end -- \\r\\n \\n \\r
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 3.1.1-SNAPSHOT
OpenAPI Generator version: 4.0.0-SNAPSHOT

=end

Expand All @@ -20,17 +20,19 @@ def initialize(api_client = ApiClient.default)
@api_client = api_client
end
# To test code injection */ ' \" =_end -- \\r\\n \\n \\r
# To test code injection */ ' \" =_end -- \\r\\n \\n \\r
# @param [Hash] opts the optional parameters
# @option opts [Object] :unknown_base_type
# @option opts [String] :test_code_inject____end____rn_n_r To test code injection */ ' \\\" =_end -- \\\\r\\\\n \\\\n \\\\r
# @return [nil]
def test_code_inject____end__rn_n_r(opts = {})
test_code_inject____end__rn_n_r_with_http_info(opts)
nil
end

# To test code injection */ ' \" =_end -- \\r\\n \\n \\r
# To test code injection */ ' \" =_end -- \\r\\n \\n \\r
# @param [Hash] opts the optional parameters
# @option opts [Object] :unknown_base_type
# @option opts [String] :test_code_inject____end____rn_n_r To test code injection */ ' \\\" =_end -- \\\\r\\\\n \\\\n \\\\r
# @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers
def test_code_inject____end__rn_n_r_with_http_info(opts = {})
if @api_client.config.debugging
Expand All @@ -45,13 +47,14 @@ def test_code_inject____end__rn_n_r_with_http_info(opts = {})
# header parameters
header_params = {}
# HTTP header 'Content-Type'
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json', '*/ \" =_end -- '])
header_params['Content-Type'] = @api_client.select_header_content_type(['application/x-www-form-urlencoded', '*/ \" =_end -- '])

# form parameters
form_params = {}
form_params['test code inject */ &#39; &quot; &#x3D;end -- \r\n \n \r'] = opts[:'test_code_inject____end____rn_n_r'] if !opts[:'test_code_inject____end____rn_n_r'].nil?

# http body (model)
post_body = @api_client.object_to_http_body(opts[:'unknown_base_type'])
post_body = nil
auth_names = []
data, status_code, headers = @api_client.call_api(:PUT, local_var_path,
:header_params => header_params,
Expand All @@ -64,5 +67,6 @@ def test_code_inject____end__rn_n_r_with_http_info(opts = {})
end
return data, status_code, headers
end

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
OpenAPI spec version: 1.0.0 */ &#39; \&quot; &#x3D;_end -- \\r\\n \\n \\r
Contact: [email protected] */ ' \" =_end -- \\r\\n \\n \\r
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 3.1.1-SNAPSHOT
OpenAPI Generator version: 4.0.0-SNAPSHOT

=end

Expand Down Expand Up @@ -143,7 +143,7 @@ def json_mime?(mime)
# Deserialize the response to the given return type.
#
# @param [Response] response HTTP response
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
def deserialize(response, return_type)
body = response.body

Expand Down Expand Up @@ -210,9 +210,7 @@ def convert_to_type(data, return_type)
end
else
# models, e.g. Pet
Petstore.const_get(return_type).new.tap do |model|
model.build_from_hash data
end
Petstore.const_get(return_type).build_from_hash(data)
end
end

Expand Down Expand Up @@ -244,7 +242,7 @@ def download_file(request)
tempfile.write(chunk)
end
request.on_complete do |response|
tempfile.close
tempfile.close if tempfile
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
OpenAPI spec version: 1.0.0 */ &#39; \&quot; &#x3D;_end -- \\r\\n \\n \\r
Contact: [email protected] */ ' \" =_end -- \\r\\n \\n \\r
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 3.1.1-SNAPSHOT
OpenAPI Generator version: 4.0.0-SNAPSHOT

=end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
OpenAPI spec version: 1.0.0 */ &#39; \&quot; &#x3D;_end -- \\r\\n \\n \\r
Contact: [email protected] */ ' \" =_end -- \\r\\n \\n \\r
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 3.1.1-SNAPSHOT
OpenAPI Generator version: 4.0.0-SNAPSHOT

=end

Expand Down Expand Up @@ -212,5 +212,47 @@ def auth_settings
},
}
end

# Returns an array of Server setting
def server_settings
[
{
url: "//petstore.swagger.io */ ' " =end -- \r\n \n \r/v2 */ ' " =end -- \r\n \n \r",
description: "No descriptoin provided",
}
]
end

# Returns URL based on server settings
#
# @param index array index of the server settings
# @param variables hash of variable and the corresponding value
def server_url(index, variables = {})
servers = server_settings

# check array index out of bound
if (index < 0 || index >= servers.size)
fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
end

server = servers[index]
url = server[:url]

# go through variable and assign a value
server[:variables].each do |name, variable|
if variables.key?(name)
if (server[:variables][name][:enum_values].include? variables[name])
url.gsub! "{" + name.to_s + "}", variables[name]
else
fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
end
else
# use default value
url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
end
end

url
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
OpenAPI spec version: 1.0.0 */ &#39; \&quot; &#x3D;_end -- \\r\\n \\n \\r
Contact: [email protected] */ ' \" =_end -- \\r\\n \\n \\r
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 3.1.1-SNAPSHOT
OpenAPI Generator version: 4.0.0-SNAPSHOT

=end

Expand Down Expand Up @@ -78,6 +78,13 @@ def hash
[_return].hash
end

# Builds the object from hash
# @param [Hash] attributes Model attributes in the form of hash
# @return [Object] Returns the model itself
def self.build_from_hash(attributes)
new.build_from_hash(attributes)
end

# Builds the object from hash
# @param [Hash] attributes Model attributes in the form of hash
# @return [Object] Returns the model itself
Expand Down Expand Up @@ -135,8 +142,7 @@ def _deserialize(type, value)
end
end
else # model
temp_model = Petstore.const_get(type).new
temp_model.build_from_hash(value)
Petstore.const_get(type).build_from_hash(value)
end
end

Expand Down Expand Up @@ -181,5 +187,7 @@ def _to_hash(value)
value
end
end

end

end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
OpenAPI spec version: 1.0.0 */ &#39; \&quot; &#x3D;_end -- \\r\\n \\n \\r
Contact: [email protected] */ ' \" =_end -- \\r\\n \\n \\r
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 3.1.1-SNAPSHOT
OpenAPI Generator version: 4.0.0-SNAPSHOT

=end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
OpenAPI spec version: 1.0.0 */ &#39; \&quot; &#x3D;_end -- \\r\\n \\n \\r
Contact: [email protected] */ ' \" =_end -- \\r\\n \\n \\r
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 3.1.1-SNAPSHOT
OpenAPI Generator version: 4.0.0-SNAPSHOT

=end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def valid?
def just_symbol=(just_symbol)
validator = EnumAttributeValidator.new('String', ['>=', '$'])
unless validator.valid?(just_symbol)
fail ArgumentError, 'invalid value for "just_symbol", must be one of #{validator.allowable_values}.'
fail ArgumentError, "invalid value for \"just_symbol\", must be one of #{validator.allowable_values}."
end
@just_symbol = just_symbol
end
Expand Down
8 changes: 4 additions & 4 deletions samples/client/petstore/ruby/lib/petstore/models/enum_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def valid?
def enum_string=(enum_string)
validator = EnumAttributeValidator.new('String', ['UPPER', 'lower', ''])
unless validator.valid?(enum_string)
fail ArgumentError, 'invalid value for "enum_string", must be one of #{validator.allowable_values}.'
fail ArgumentError, "invalid value for \"enum_string\", must be one of #{validator.allowable_values}."
end
@enum_string = enum_string
end
Expand All @@ -138,7 +138,7 @@ def enum_string=(enum_string)
def enum_string_required=(enum_string_required)
validator = EnumAttributeValidator.new('String', ['UPPER', 'lower', ''])
unless validator.valid?(enum_string_required)
fail ArgumentError, 'invalid value for "enum_string_required", must be one of #{validator.allowable_values}.'
fail ArgumentError, "invalid value for \"enum_string_required\", must be one of #{validator.allowable_values}."
end
@enum_string_required = enum_string_required
end
Expand All @@ -148,7 +148,7 @@ def enum_string_required=(enum_string_required)
def enum_integer=(enum_integer)
validator = EnumAttributeValidator.new('Integer', ['1', '-1'])
unless validator.valid?(enum_integer)
fail ArgumentError, 'invalid value for "enum_integer", must be one of #{validator.allowable_values}.'
fail ArgumentError, "invalid value for \"enum_integer\", must be one of #{validator.allowable_values}."
end
@enum_integer = enum_integer
end
Expand All @@ -158,7 +158,7 @@ def enum_integer=(enum_integer)
def enum_number=(enum_number)
validator = EnumAttributeValidator.new('Float', ['1.1', '-1.2'])
unless validator.valid?(enum_number)
fail ArgumentError, 'invalid value for "enum_number", must be one of #{validator.allowable_values}.'
fail ArgumentError, "invalid value for \"enum_number\", must be one of #{validator.allowable_values}."
end
@enum_number = enum_number
end
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/ruby/lib/petstore/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def valid?
def status=(status)
validator = EnumAttributeValidator.new('String', ['placed', 'approved', 'delivered'])
unless validator.valid?(status)
fail ArgumentError, 'invalid value for "status", must be one of #{validator.allowable_values}.'
fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
end
@status = status
end
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/ruby/lib/petstore/models/pet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def valid?
def status=(status)
validator = EnumAttributeValidator.new('String', ['available', 'pending', 'sold'])
unless validator.valid?(status)
fail ArgumentError, 'invalid value for "status", must be one of #{validator.allowable_values}.'
fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
end
@status = status
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def valid?
def just_symbol=(just_symbol)
validator = EnumAttributeValidator.new('String', ['>=', '$'])
unless validator.valid?(just_symbol)
fail ArgumentError, 'invalid value for "just_symbol", must be one of #{validator.allowable_values}.'
fail ArgumentError, "invalid value for \"just_symbol\", must be one of #{validator.allowable_values}."
end
@just_symbol = just_symbol
end
Expand Down
Loading