Context
The endpoint URL building logic is duplicated across every method in all generated service classes (e.g., AccountHoldersApi, DirectDebitMandatesApi, and others). Each method repeats the same three-line pattern:
endpoint = '/some/{id}/path'.gsub(/{.+?}/, '%s')
endpoint = endpoint.gsub(%r{^/}, '')
endpoint = format(endpoint, id)
This was noted in a review comment on PR #350.
Proposed Change
Extract the repeated endpoint building logic into a private helper method in the base Service class or in the generated classes themselves. The Mustache templates in /templates should be updated to emit a call to this helper instead of inlining the three-step pattern:
def build_endpoint(path, *params)
endpoint = path.gsub(/{.+?}/, '%s').delete_prefix('/')
format(endpoint, *params)
end
Generated methods would then simplify to:
def get_tax_form_summary(id, headers: {}, query_params: {})
endpoint = build_endpoint('/accountHolders/{id}/taxFormSummary', id)
endpoint += create_query_string(query_params)
action = { method: 'get', url: endpoint }
@client.call_adyen_api(@service, action, {}, headers, @version)
end
Benefit
Reduces boilerplate in every generated service method, makes the templates easier to maintain, and lowers the risk of copy-paste mistakes when the URL construction logic needs to change in the future.
Context
The endpoint URL building logic is duplicated across every method in all generated service classes (e.g.,
AccountHoldersApi,DirectDebitMandatesApi, and others). Each method repeats the same three-line pattern:This was noted in a review comment on PR #350.
Proposed Change
Extract the repeated endpoint building logic into a private helper method in the base
Serviceclass or in the generated classes themselves. The Mustache templates in/templatesshould be updated to emit a call to this helper instead of inlining the three-step pattern:Generated methods would then simplify to:
Benefit
Reduces boilerplate in every generated service method, makes the templates easier to maintain, and lowers the risk of copy-paste mistakes when the URL construction logic needs to change in the future.