[Ruby] Better handling of operationID starting with a number (#719)

* better handling of operationId starting with numbers in Ruby

* update Rubocop to use Layout
This commit is contained in:
William Cheng 2018-08-02 22:00:50 +08:00 committed by GitHub
parent e0020b41da
commit f0425d77ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 19 deletions

View File

@ -462,6 +462,12 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
return newOperationId;
}
// operationId starts with a number
if (operationId.matches("^\\d.*")) {
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
operationId = "call_" + operationId;
}
return underscore(sanitizeName(operationId));
}

View File

@ -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

View File

@ -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

View File

@ -59,10 +59,10 @@ client = Petstore::Client.new # Client | client model
begin
#To test special tags
result = api_instance.test_special_tags(client)
result = api_instance.call_123_test_special_tags(client)
p result
rescue Petstore::ApiError => e
puts "Exception when calling AnotherFakeApi->test_special_tags: #{e}"
puts "Exception when calling AnotherFakeApi->call_123_test_special_tags: #{e}"
end
```
@ -73,7 +73,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*Petstore::AnotherFakeApi* | [**test_special_tags**](docs/AnotherFakeApi.md#test_special_tags) | **PATCH** /another-fake/dummy | To test special tags
*Petstore::AnotherFakeApi* | [**call_123_test_special_tags**](docs/AnotherFakeApi.md#call_123_test_special_tags) | **PATCH** /another-fake/dummy | To test special tags
*Petstore::FakeApi* | [**fake_outer_boolean_serialize**](docs/FakeApi.md#fake_outer_boolean_serialize) | **POST** /fake/outer/boolean |
*Petstore::FakeApi* | [**fake_outer_composite_serialize**](docs/FakeApi.md#fake_outer_composite_serialize) | **POST** /fake/outer/composite |
*Petstore::FakeApi* | [**fake_outer_number_serialize**](docs/FakeApi.md#fake_outer_number_serialize) | **POST** /fake/outer/number |

View File

@ -4,15 +4,15 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
Method | HTTP request | Description
------------- | ------------- | -------------
[**test_special_tags**](AnotherFakeApi.md#test_special_tags) | **PATCH** /another-fake/dummy | To test special tags
[**call_123_test_special_tags**](AnotherFakeApi.md#call_123_test_special_tags) | **PATCH** /another-fake/dummy | To test special tags
# **test_special_tags**
> Client test_special_tags(client)
# **call_123_test_special_tags**
> Client call_123_test_special_tags(client)
To test special tags
To test special tags
To test special tags and operation ID starting with number
### Example
```ruby
@ -24,10 +24,10 @@ client = Petstore::Client.new # Client | client model
begin
#To test special tags
result = api_instance.test_special_tags(client)
result = api_instance.call_123_test_special_tags(client)
p result
rescue Petstore::ApiError => e
puts "Exception when calling AnotherFakeApi->test_special_tags: #{e}"
puts "Exception when calling AnotherFakeApi->call_123_test_special_tags: #{e}"
end
```

View File

@ -20,27 +20,27 @@ module Petstore
@api_client = api_client
end
# To test special tags
# To test special tags
# To test special tags and operation ID starting with number
# @param client client model
# @param [Hash] opts the optional parameters
# @return [Client]
def test_special_tags(client, opts = {})
data, _status_code, _headers = test_special_tags_with_http_info(client, opts)
def call_123_test_special_tags(client, opts = {})
data, _status_code, _headers = call_123_test_special_tags_with_http_info(client, opts)
data
end
# To test special tags
# To test special tags
# To test special tags and operation ID starting with number
# @param client client model
# @param [Hash] opts the optional parameters
# @return [Array<(Client, Fixnum, Hash)>] Client data, response status code and response headers
def test_special_tags_with_http_info(client, opts = {})
def call_123_test_special_tags_with_http_info(client, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: AnotherFakeApi.test_special_tags ...'
@api_client.config.logger.debug 'Calling API: AnotherFakeApi.call_123_test_special_tags ...'
end
# verify the required parameter 'client' is set
if @api_client.config.client_side_validation && client.nil?
fail ArgumentError, "Missing the required parameter 'client' when calling AnotherFakeApi.test_special_tags"
fail ArgumentError, "Missing the required parameter 'client' when calling AnotherFakeApi.call_123_test_special_tags"
end
# resource path
local_var_path = '/another-fake/dummy'
@ -69,7 +69,7 @@ module Petstore
:auth_names => auth_names,
:return_type => 'Client')
if @api_client.config.debugging
@api_client.config.logger.debug "API called: AnotherFakeApi#test_special_tags\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
@api_client.config.logger.debug "API called: AnotherFakeApi#call_123_test_special_tags\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end