Skip to content

Commit 7cda9ec

Browse files
committed
Fix api name
1 parent 5597763 commit 7cda9ec

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

.generator/src/generator/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def cli(specs, output):
4040
env.filters["return_type"] = openapi.return_type
4141
env.filters["snake_case"] = formatter.snake_case
4242
env.filters["attribute_path"] = formatter.attribute_path
43-
43+
env.filters["class_name"] = formatter.class_name
4444
env.globals["gem_name"] = GEM_NAME
4545
env.globals["module_name"] = MODULE_NAME
4646
env.globals["enumerate"] = enumerate

.generator/src/generator/formatter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ def format_data_with_schema_dict(
342342

343343
return parameters
344344

345+
def class_name(value):
346+
value = re.sub(r'[^a-zA-Z0-9]', '', value)
347+
return value + "API"
345348

346349
def attribute_path(attribute):
347350
return ".".join(attribute_name(a) for a in attribute.split("."))

.generator/src/generator/templates/api.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require 'cgi'
66

77
module {{ module_name }}::{{ version|upper }}
8-
{%- set classname = name.replace(" ", "") + "API" %}
8+
{%- set classname = name|class_name %}
99
class {{ classname }}
1010
attr_accessor :api_client
1111

.generator/src/generator/templates/inflector.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module {{ module_name }}
1818
# APIs
1919
{%- for version, apis in all_apis.items() %}
2020
{%- for api in apis|sort %}
21-
{%- set name = api.replace(" ", "") + "API" %}
21+
{%- set name = api|class_name %}
2222
"{{ version }}.{{ api|snake_case }}_api" => "{{ name }}"{%-if not loop.last %},{% endif %}
2323
{%- endfor %}{%-if not loop.last %},{% endif %}
2424
{%- endfor %}

features/step_definitions/request.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ def undo_operations
123123
@undo_operations
124124
end
125125

126+
# Takes a tag name and converts it into an API class name by removing spaces and dashes, then appending "API"
127+
# For example: "Logs-Archive" -> "LogsArchiveAPI"
128+
# @param name [String] The tag name to convert
129+
# @return [String] The API class name
130+
def build_api_name(name)
131+
name.gsub(/[\s-]/, '') + "API"
132+
end
133+
126134
def build_undo_for(version, operation_id, api_instance = nil)
127135
operation = undo_operations
128136
raise "missing x-undo for #{version}" unless operation.key? version
@@ -134,13 +142,14 @@ def build_undo_for(version, operation_id, api_instance = nil)
134142
return if operation["type"] != "unsafe"
135143

136144
if operation["tag"] != nil
137-
undo_tag = operation["tag"].gsub(/\s/, '')
145+
undo_tag = operation["tag"]
146+
api_name = build_api_name(undo_tag)
138147
undo_api = Object.const_get("DatadogAPIClient")
139148
undo_configuration = from_env(undo_api::Configuration.new)
140149
undo_configuration.api_key = ENV["DD_TEST_CLIENT_API_KEY"]
141150
undo_configuration.application_key = ENV["DD_TEST_CLIENT_APP_KEY"]
142151
undo_api_client = undo_api::APIClient.new undo_configuration
143-
api_instance = undo_api.const_get("V#{version}").const_get("#{undo_tag}API").new undo_api_client
152+
api_instance = undo_api.const_get("V#{version}").const_get(api_name).new undo_api_client
144153
end
145154

146155
api_instance ||= @api_instance
@@ -171,7 +180,7 @@ def build_undo_for(version, operation_id, api_instance = nil)
171180
end
172181

173182
def build_given(api_version, operation)
174-
api_name = operation["tag"].gsub(/\s/, '')
183+
api_name = build_api_name(operation["tag"])
175184
operation_name = operation["operationId"].snakecase
176185

177186
# make sure we have a fresh instance of API client and configuration
@@ -180,7 +189,7 @@ def build_given(api_version, operation)
180189
given_configuration.api_key = ENV["DD_TEST_CLIENT_API_KEY"]
181190
given_configuration.application_key = ENV["DD_TEST_CLIENT_APP_KEY"]
182191
given_api_client = given_api::APIClient.new given_configuration
183-
given_api_instance = given_api.const_get("V#{api_version}").const_get("#{api_name}API").new given_api_client
192+
given_api_instance = given_api.const_get("V#{api_version}").const_get(api_name).new given_api_client
184193
method = given_api_instance.method("#{operation_name}_with_http_info".to_sym)
185194

186195
# find undo method
@@ -240,7 +249,8 @@ def model_builder(param, obj)
240249
end
241250

242251
Given(/^an instance of "([^"]+)" API$/) do |api_name|
243-
@api_instance = api.const_get("V#{@api_version}").const_get("#{api_name}API").new api_client
252+
name = build_api_name(api_name)
253+
@api_instance = api.const_get("V#{@api_version}").const_get(name).new api_client
244254
end
245255

246256
Given('operation {string} enabled') do |name|

0 commit comments

Comments
 (0)