<commit_before>module ServiceVersionsHelper

  def service_params_markup(service_version)
    name = service_version.service.name
    spec = service_version.spec_with_resolved_refs['definition']
    references = service_version.spec_with_resolved_refs['references']
    content_tag(:div, class: "schema-panel-set detail", data: {name: name, version: service_version.version_number}) do
      content_tag(:h3, "Paths") + service_path_markup(spec, '/', references)
    end
  end

  def service_path_markup(service_spec, json_pointer, references)
    join_markup(service_spec['paths'].map do |path, operations|
      service_path_operation_markup(
        path, operations, json_pointer_path(json_pointer, path), references
      )
    end)
  end

  def service_operations(service_spec)
    join_markup(service_spec['paths'].map do |path, operations|
      join_markup(operations.map do |verb, operation|
        if verb != 'parameters'
          content_tag(:li) do
            content_tag(:a) do
              content_tag(:span, verb, class: 'btn btn-status '+ class_definer(verb) + ' full') +
              content_tag(:span, path, class: 'path')
            end
          end
        end
      end)
    end)
  end

  def service_path_operation_markup(path, operations, json_pointer, references)
    common_parameters = operations.extract!('parameters')['parameters'] || []
    content_tag(:ul, class: 'list-operations') do
      join_markup(operations.map do |verb, operation|
        service_operation_content_markup(path, verb, operation, common_parameters,
          json_pointer, references) + '<br>'.html_safe
      end)
    end
  end

  def class_definer(verb)
    options = {
      'get' => 'info', 'post' => 'success', 'put' => 'warning', 'delete' => 'danger'
    }
    options[verb] || ''
  end

  def service_operation_content_markup(path, verb, operation, common_parameters, json_pointer, references)
    if operation['parameters'].present?
        common_parameters = common_parameters + operation['parameters']
    end
    content_tag(:li) do
      content_tag(:a) do
        content_tag(:span, verb, class: 'btn btn-status '+
          class_definer(verb) + ' full') + path + '<br>'.html_safe +
          content_tag(:h3, operation['summary']) +
          content_tag(:h2, 'Parámetros') +
          service_operation_parameters_distribution(common_parameters) +
          content_tag(:h2, 'Respuestas') +
          service_operation_responses_markup(operation['responses'])
      end
    end
  end

  def service_operation_responses_markup(responses)
    join_markup(responses.map do |name, response|
      content_tag(:h3, name) +
      content_tag(:p, response['description']) +
      response_schema_object_markup(response['schema']) +
      response_headers_markup(response['headers'])
    end)
  end

  def response_headers_markup(headers)
    if headers.present?
      join_markup(headers.map do |name, header|
        schema_object_property_markup(name, header, false, '/', '')
      end)
    end
  end

  def response_schema_object_markup(schema)
    if schema.present?
      case schema["type"]
        when "object"
          schema_object_spec_markup(schema, '/', '')
        else
          schema_object_property_markup('', schema, false, '/', '')
        end
    else
      return ''
    end
  end

  def service_operation_parameters_distribution(parameters)
    distributed_params = {
      'body' => [], 'query' => [], 'header' => [], 'path' => [], 'formData' => []
    }<commit_msg>Add example markup to operation response<commit_after>module ServiceVersionsHelper

  def service_params_markup(service_version)
    name = service_version.service.name
    spec = service_version.spec_with_resolved_refs['definition']
    references = service_version.spec_with_resolved_refs['references']
    content_tag(:div, class: "schema-panel-set detail", data: {name: name, version: service_version.version_number}) do
      content_tag(:h3, "Paths") + service_path_markup(spec, '/', references)
    end
  end

  def service_path_markup(service_spec, json_pointer, references)
    join_markup(service_spec['paths'].map do |path, operations|
      service_path_operation_markup(
        path, operations, json_pointer_path(json_pointer, path), references
      )
    end)
  end

  def service_operations(service_spec)
    join_markup(service_spec['paths'].map do |path, operations|
      join_markup(operations.map do |verb, operation|
        if verb != 'parameters'
          content_tag(:li) do
            content_tag(:a) do
              content_tag(:span, verb, class: 'btn btn-status '+ class_definer(verb) + ' full') +
              content_tag(:span, path, class: 'path')
            end
          end
        end
      end)
    end)
  end

  def service_path_operation_markup(path, operations, json_pointer, references)
    common_parameters = operations.extract!('parameters')['parameters'] || []
    content_tag(:ul, class: 'list-operations') do
      join_markup(operations.map do |verb, operation|
        service_operation_content_markup(path, verb, operation, common_parameters,
          json_pointer, references) + '<br>'.html_safe
      end)
    end
  end

  def class_definer(verb)
    options = {
      'get' => 'info', 'post' => 'success', 'put' => 'warning', 'delete' => 'danger'
    }
    options[verb] || ''
  end

  def service_operation_content_markup(path, verb, operation, common_parameters, json_pointer, references)
    if operation['parameters'].present?
        common_parameters = common_parameters + operation['parameters']
    end
    content_tag(:li) do
      content_tag(:a) do
        content_tag(:span, verb, class: 'btn btn-status '+
          class_definer(verb) + ' full') + path + '<br>'.html_safe +
          content_tag(:h3, operation['summary']) +
          content_tag(:h2, 'Parámetros') +
          service_operation_parameters_distribution(common_parameters) +
          content_tag(:h2, 'Respuestas') +
          service_operation_responses_markup(operation['responses'])
      end
    end
  end

  def service_operation_responses_markup(responses)
    join_markup(responses.map do |name, response|
      content_tag(:h3, name) +
      content_tag(:p, response['description']) +
      response_schema_object_markup(response['schema']) +
      response_headers_markup(response['headers']) +
      response_example_markup(response['examples'])
    end)
  end

  def response_example_markup(example)
    if example.present?
      content_tag(:div, class: 'box-code-example') do
        content_tag(:code, class: 'json') do
          preserve(JSON.pretty_generate example)
        end
      end
    else
      ''
    end
  end

  def response_headers_markup(headers)
    if headers.present?
      join_markup(headers.map do |name, header|
        schema_object_property_markup(name, header, false, '/', '')
      end)
    end
  end

  def response_schema_object_markup(schema)
    if schema.present?
      case schema["type"]
        when "object"
          schema_object_spec_markup(schema, '/', '')
        else
          schema_object_property_markup('', schema, false, '/', '')
        end
    else
      return ''
    end
  end

  def service_operation_parameters_distribution(parameters)
    distributed_params = {
      'body' => [], 'query' => [], 'header' => [], 'path' => [], 'formData' => []
    }
{'fraction_non_alphanumeric': 0.11799810117998101, 'fraction_numerical': 0.001356300013563, 'mean_word_length': 3.31480397893505, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7305014', 'n_tokens_mistral': 2214, 'n_tokens_neox': 2174, 'n_words': 435}