@@ -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)
240249end
241250
242251Given ( /^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
244254end
245255
246256Given ( 'operation {string} enabled' ) do |name |
0 commit comments