.generator/src/generator/templates/api.j2 in datadog_api_client-1.11.0 vs .generator/src/generator/templates/api.j2 in datadog_api_client-2.0.0

- old
+ new

@@ -7,11 +7,11 @@ module {{ module_name }}::{{ version|upper }} {%- set classname = name.replace(" ", "") + "API" %} class {{ classname }} attr_accessor :api_client - def initialize(api_client = APIClient.default) + def initialize(api_client = {{ module_name }}::APIClient.default) @api_client = api_client end {%- for path, method, operation in operations|sort(attribute="2.operationId") %} {%- set httpMethod = method.upper() %} @@ -38,19 +38,18 @@ {%- for name, parameter in operation|parameters if not parameter.required %} # @option opts [{{ get_type_for_parameter(parameter) }}] :{{ name|attribute_name }} {{ parameter.get("description", "").replace('\n', ' ') }}{% if "default" in parameter%} (default to {{ parameter.default|json }}) {% endif %} {%- endfor %} # @return [Array<({% if returnType %}{{ returnType }}{% else %}nil{% endif %}, Integer, Hash)>] {% if returnType %}{{ returnType }} data{% else %}nil{% endif %}, response status code and response headers def {{ operation.operationId|snake_case }}_with_http_info({% for name, parameter in operation|parameters if parameter.required %}{{ name|attribute_name }}, {% endfor %}opts = {}) - - if @api_client.config.unstable_operations.has_key?(:{{ operation.operationId|snake_case }}) - unstable_enabled = @api_client.config.unstable_operations[:{{ operation.operationId|snake_case }}] - if unstable_enabled - @api_client.config.logger.warn format("Using unstable operation '%s'", "{{ operation.operationId|snake_case }}") - else - raise APIError.new(message: format("Unstable operation '%s' is disabled", "{{ operation.operationId|snake_case }}")) - end + {%- if "x-unstable" in operation %} + unstable_enabled = @api_client.config.unstable_operations["{{ version }}.{{ operation.operationId|snake_case }}".to_sym] + if unstable_enabled + @api_client.config.logger.warn format("Using unstable operation '%s'", "{{ version }}.{{ operation.operationId|snake_case }}") + else + raise {{ module_name }}::APIError.new(message: format("Unstable operation '%s' is disabled", "{{ version }}.{{ operation.operationId|snake_case }}")) end + {%- endif %} if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: {{classname}}.{{ operation.operationId|snake_case }} ...' end @@ -196,11 +195,12 @@ :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, - :return_type => return_type + :return_type => return_type, + :api_version => "{{ version|upper }}" ) data, status_code, headers = @api_client.call_api(Net::HTTP::{{ httpMethod|camel_case }}, local_var_path, new_options) if @api_client.config.debugging @api_client.config.logger.debug "API called: {{ classname }}#{{ operation.operationId|snake_case }}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" @@ -216,22 +216,23 @@ # # To use it you need to use a block: {{ operation.operationId|snake_case }}_with_pagination { |item| p item } # # @yield [{{ get_type_at_path(operation, pagination.resultsPath) }}] Paginated items def {{ operation.operationId|snake_case }}_with_pagination({% for name, parameter in operation|parameters if parameter.required %}{{ name|attribute_name }}, {% endfor %}opts = {}) + api_version = "{{ version|upper }}" page_size = @api_client.get_attribute_from_path({{ get_container(operation, pagination.limitParam) }}, {{ get_default(operation, pagination.limitParam) }}) - @api_client.set_attribute_from_path({{ get_container(operation, pagination.limitParam, True) }}, page_size) + @api_client.set_attribute_from_path(api_version, {{ get_container(operation, pagination.limitParam, True) }}, page_size) while true do response = {{ operation.operationId|snake_case }}({% for name, parameter in operation|parameters if parameter.required %}{{ name|attribute_name }}, {% endfor %}opts) @api_client.get_attribute_from_path(response, "{{ pagination.resultsPath|attribute_path }}").each { |item| yield(item) } if @api_client.get_attribute_from_path(response, "{{ pagination.resultsPath|attribute_path }}").length < page_size break end {%- if pagination.pageOffsetParam %} - @api_client.set_attribute_from_path({{ get_container(operation, pagination.pageOffsetParam, True) }}, @api_client.get_attribute_from_path({{ get_container(operation, pagination.pageOffsetParam) }}, 0) + page_size) + @api_client.set_attribute_from_path(api_version, {{ get_container(operation, pagination.pageOffsetParam, True) }}, @api_client.get_attribute_from_path({{ get_container(operation, pagination.pageOffsetParam) }}, 0) + page_size) {%- endif %} {%- if pagination.cursorParam %} - @api_client.set_attribute_from_path({{ get_container(operation, pagination.cursorParam, True) }}, @api_client.get_attribute_from_path(response, "{{ pagination.cursorPath }}")) + @api_client.set_attribute_from_path(api_version, {{ get_container(operation, pagination.cursorParam, True) }}, @api_client.get_attribute_from_path(response, "{{ pagination.cursorPath }}")) {%- endif %} end end {%- endif %} {%- if not loop.last %}