<commit_before>package io.flow.lint.linters

import io.flow.lint.Linter
import com.bryzek.apidoc.spec.v0.models.{Method, Operation, Parameter, Resource, Service}

/**
  * For well known parameters, enforce specific types, defaults,
  * minimums and maximums. Validates only GET operations.
  */
case object CommonParameterTypes extends Linter with Helpers {

  case class Spec(
    typ: String,
    default: Option[String] = None,
    minimum: Option[Long] = None,
    maximum: Option[Long] = None
  )

  val Expected = Map(
    "id" -> Spec("[string]", default = None, minimum = None, maximum = Some(100)),
    "limit" -> Spec("long", default = Some("25"), minimum = Some(1), maximum = Some(100)),
    "offset" -> Spec("long", default = Some("0"), minimum = Some(0), maximum = None)
  )

  val Types = Map(
    "sort" -> "string",
    "expand" -> "[string]"
  )

  override def validate(service: Service): Seq[String] = {
    nonHealthcheckResources(service).map(validateResource(service, _)).flatten
  }

  def validateResource(service: Service, resource: Resource): Seq[String] = {
    resource.operations.
      filter(_.method == Method.Get).
      filter(returnsArray(_)).
      flatMap { op =>
        op.parameters.flatMap { param =>
          validateParameter(service, resource, op, param)
        }
      }
  }

  def validateParameter(service: Service, resource: Resource, op: Operation, param: Parameter): Seq[String] = {<commit_msg>Add common param type hint<commit_after>package io.flow.lint.linters

import io.flow.lint.Linter
import com.bryzek.apidoc.spec.v0.models.{Method, Operation, Parameter, Resource, Service}

/**
  * For well known parameters, enforce specific types, defaults,
  * minimums and maximums. Validates only GET operations.
  */
case object CommonParameterTypes extends Linter with Helpers {

  case class Spec(
    typ: String,
    default: Option[String] = None,
    minimum: Option[Long] = None,
    maximum: Option[Long] = None
  )

  val Expected = Map(
    "id" -> Spec("[string]", default = None, minimum = None, maximum = Some(100)),
    "limit" -> Spec("long", default = Some("25"), minimum = Some(1), maximum = Some(100)),
    "offset" -> Spec("long", default = Some("0"), minimum = Some(0), maximum = None)
  )

  val Types = Map(
    "sort" -> "string",
    "expand" -> "[string]"
  )

  override def validate(service: Service): Seq[String] = {
    nonHealthcheckResources(service).
      filter(r => !ignored(r.attributes, "common_parameter_types")).
      map(validateResource(service, _)).flatten
  }

  def validateResource(service: Service, resource: Resource): Seq[String] = {
    resource.operations.
      filter(_.method == Method.Get).
      filter(returnsArray(_)).
      flatMap { op =>
        op.parameters.flatMap { param =>
          validateParameter(service, resource, op, param)
        }
      }
  }

  def validateParameter(service: Service, resource: Resource, op: Operation, param: Parameter): Seq[String] = {
{'fraction_non_alphanumeric': 0.14290506541429052, 'fraction_numerical': 0.008050989600805098, 'mean_word_length': 3.5319148936170213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '4247700', 'n_tokens_mistral': 903, 'n_tokens_neox': 878, 'n_words': 238}