Skip to content

Commit f0425d7

Browse files
authored
[Ruby] Better handling of operationID starting with a number (#719)
* better handling of operationId starting with numbers in Ruby * update Rubocop to use Layout
1 parent e0020b4 commit f0425d7

6 files changed

Lines changed: 25 additions & 19 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,12 @@ public String toOperationId(String operationId) {
462462
return newOperationId;
463463
}
464464

465+
// operationId starts with a number
466+
if (operationId.matches("^\\d.*")) {
467+
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
468+
operationId = "call_" + operationId;
469+
}
470+
465471
return underscore(sanitizeName(operationId));
466472
}
467473

modules/openapi-generator/src/main/resources/ruby-client/rubocop.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Style/UnneededPercentQ:
136136

137137
# Align `end` with the matching keyword or starting expression except for
138138
# assignments, where it should be aligned with the LHS.
139-
Lint/EndAlignment:
139+
Layout/EndAlignment:
140140
Enabled: true
141141
EnforcedStyleAlignWith: variable
142142
AutoCorrect: true

samples/client/petstore/ruby/.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Style/UnneededPercentQ:
136136

137137
# Align `end` with the matching keyword or starting expression except for
138138
# assignments, where it should be aligned with the LHS.
139-
Lint/EndAlignment:
139+
Layout/EndAlignment:
140140
Enabled: true
141141
EnforcedStyleAlignWith: variable
142142
AutoCorrect: true

samples/client/petstore/ruby/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ client = Petstore::Client.new # Client | client model
5959

6060
begin
6161
#To test special tags
62-
result = api_instance.test_special_tags(client)
62+
result = api_instance.call_123_test_special_tags(client)
6363
p result
6464
rescue Petstore::ApiError => e
65-
puts "Exception when calling AnotherFakeApi->test_special_tags: #{e}"
65+
puts "Exception when calling AnotherFakeApi->call_123_test_special_tags: #{e}"
6666
end
6767

6868
```
@@ -73,7 +73,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
7373

7474
Class | Method | HTTP request | Description
7575
------------ | ------------- | ------------- | -------------
76-
*Petstore::AnotherFakeApi* | [**test_special_tags**](docs/AnotherFakeApi.md#test_special_tags) | **PATCH** /another-fake/dummy | To test special tags
76+
*Petstore::AnotherFakeApi* | [**call_123_test_special_tags**](docs/AnotherFakeApi.md#call_123_test_special_tags) | **PATCH** /another-fake/dummy | To test special tags
7777
*Petstore::FakeApi* | [**fake_outer_boolean_serialize**](docs/FakeApi.md#fake_outer_boolean_serialize) | **POST** /fake/outer/boolean |
7878
*Petstore::FakeApi* | [**fake_outer_composite_serialize**](docs/FakeApi.md#fake_outer_composite_serialize) | **POST** /fake/outer/composite |
7979
*Petstore::FakeApi* | [**fake_outer_number_serialize**](docs/FakeApi.md#fake_outer_number_serialize) | **POST** /fake/outer/number |

samples/client/petstore/ruby/docs/AnotherFakeApi.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
44

55
Method | HTTP request | Description
66
------------- | ------------- | -------------
7-
[**test_special_tags**](AnotherFakeApi.md#test_special_tags) | **PATCH** /another-fake/dummy | To test special tags
7+
[**call_123_test_special_tags**](AnotherFakeApi.md#call_123_test_special_tags) | **PATCH** /another-fake/dummy | To test special tags
88

99

10-
# **test_special_tags**
11-
> Client test_special_tags(client)
10+
# **call_123_test_special_tags**
11+
> Client call_123_test_special_tags(client)
1212
1313
To test special tags
1414

15-
To test special tags
15+
To test special tags and operation ID starting with number
1616

1717
### Example
1818
```ruby
@@ -24,10 +24,10 @@ client = Petstore::Client.new # Client | client model
2424

2525
begin
2626
#To test special tags
27-
result = api_instance.test_special_tags(client)
27+
result = api_instance.call_123_test_special_tags(client)
2828
p result
2929
rescue Petstore::ApiError => e
30-
puts "Exception when calling AnotherFakeApi->test_special_tags: #{e}"
30+
puts "Exception when calling AnotherFakeApi->call_123_test_special_tags: #{e}"
3131
end
3232
```
3333

samples/client/petstore/ruby/lib/petstore/api/another_fake_api.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ def initialize(api_client = ApiClient.default)
2020
@api_client = api_client
2121
end
2222
# To test special tags
23-
# To test special tags
23+
# To test special tags and operation ID starting with number
2424
# @param client client model
2525
# @param [Hash] opts the optional parameters
2626
# @return [Client]
27-
def test_special_tags(client, opts = {})
28-
data, _status_code, _headers = test_special_tags_with_http_info(client, opts)
27+
def call_123_test_special_tags(client, opts = {})
28+
data, _status_code, _headers = call_123_test_special_tags_with_http_info(client, opts)
2929
data
3030
end
3131

3232
# To test special tags
33-
# To test special tags
33+
# To test special tags and operation ID starting with number
3434
# @param client client model
3535
# @param [Hash] opts the optional parameters
3636
# @return [Array<(Client, Fixnum, Hash)>] Client data, response status code and response headers
37-
def test_special_tags_with_http_info(client, opts = {})
37+
def call_123_test_special_tags_with_http_info(client, opts = {})
3838
if @api_client.config.debugging
39-
@api_client.config.logger.debug 'Calling API: AnotherFakeApi.test_special_tags ...'
39+
@api_client.config.logger.debug 'Calling API: AnotherFakeApi.call_123_test_special_tags ...'
4040
end
4141
# verify the required parameter 'client' is set
4242
if @api_client.config.client_side_validation && client.nil?
43-
fail ArgumentError, "Missing the required parameter 'client' when calling AnotherFakeApi.test_special_tags"
43+
fail ArgumentError, "Missing the required parameter 'client' when calling AnotherFakeApi.call_123_test_special_tags"
4444
end
4545
# resource path
4646
local_var_path = '/another-fake/dummy'
@@ -69,7 +69,7 @@ def test_special_tags_with_http_info(client, opts = {})
6969
:auth_names => auth_names,
7070
:return_type => 'Client')
7171
if @api_client.config.debugging
72-
@api_client.config.logger.debug "API called: AnotherFakeApi#test_special_tags\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
72+
@api_client.config.logger.debug "API called: AnotherFakeApi#call_123_test_special_tags\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
7373
end
7474
return data, status_code, headers
7575
end

0 commit comments

Comments
 (0)