<commit_before>package generator

import models.ApidocHeaders
import com.gilt.apidoc.generator.v0.models.InvocationForm
import com.gilt.apidoc.spec.v0.models.Service
import lib.Text._

object ScalaCaseClasses extends CodeGenerator {

  override def invoke(form: InvocationForm): String = invoke(form, generatePlayEnums, addHeader = true)

  def invoke(
    form: InvocationForm,
    genEnums: Seq[ScalaEnum] => String = generatePlayEnums,
    addHeader: Boolean = true
  ): String = {
    val ssd = new ScalaService(form.service)

    val header = addHeader match {
      case false => ""
      case true => ApidocHeaders(form.userAgent).toJavaString() + "\n"
    }

    s"${header}package ${ssd.namespaces.models} {\n\n  " +
    Seq(
      ssd.unions.map { generateUnionTraits(_) }.mkString("\n\n").indent(2),
      "",
      ssd.models.map { generateCaseClass(_) }.mkString("\n\n").indent(2),
      "",
      genEnums(ssd.enums).indent(2)
    ).mkString("\n").trim +
    s"\n\n}"
  }

  def generateUnionTraits(union: ScalaUnion): String = {
    union.description.map { desc => ScalaUtil.textToComment(desc) + "\n" }.getOrElse("") +
    s"sealed trait ${union.name}"
  }

  def generateCaseClass(model: ScalaModel): String = {
    val extendsClause = model.unions match {
      case Nil => ""
      case unions => " extends " + unions.map(_.name).mkString(" with ")
    }

    model.description.map { desc => ScalaUtil.textToComment(desc) + "\n" }.getOrElse("") +
    s"case class ${model.name}(${model.argList.getOrElse("")})" + extendsClause
  }

  private def generatePlayEnums(enums: Seq[ScalaEnum]): String = {
    enums.map { ScalaEnums(_).build }.mkString("\n\n")
  }

}<commit_msg>Add comment<commit_after>package generator

import models.ApidocHeaders
import com.gilt.apidoc.generator.v0.models.InvocationForm
import com.gilt.apidoc.spec.v0.models.Service
import lib.Text._

object ScalaCaseClasses extends CodeGenerator {

  override def invoke(form: InvocationForm): String = invoke(form, generatePlayEnums, addHeader = true)

  def invoke(
    form: InvocationForm,
    genEnums: Seq[ScalaEnum] => String = generatePlayEnums,
    addHeader: Boolean = true
  ): String = {
    val ssd = new ScalaService(form.service)

    val header = addHeader match {
      case false => ""
      case true => ApidocHeaders(form.userAgent).toJavaString() + "\n"
    }

    s"${header}package ${ssd.namespaces.models} {\n\n  " +
    Seq(
      ssd.unions.map { generateUnionTraits(_) }.mkString("\n\n").indent(2),
      "",
      ssd.models.map { generateCaseClass(_) }.mkString("\n\n").indent(2),
      "",
      genEnums(ssd.enums).indent(2)
    ).mkString("\n").trim +
    s"\n\n}"
  }

  def generateUnionTraits(union: ScalaUnion): String = {
    // TODO: handle primitive types

    // For union types across only models, find all common fields and bubble up to the trait

    union.description.map { desc => ScalaUtil.textToComment(desc) + "\n" }.getOrElse("") +
    s"sealed trait ${union.name}"
  }

  def generateCaseClass(model: ScalaModel): String = {
    val extendsClause = model.unions match {
      case Nil => ""
      case unions => " extends " + unions.map(_.name).mkString(" with ")
    }

    model.description.map { desc => ScalaUtil.textToComment(desc) + "\n" }.getOrElse("") +
    s"case class ${model.name}(${model.argList.getOrElse("")})" + extendsClause
  }

  private def generatePlayEnums(enums: Seq[ScalaEnum]): String = {
    enums.map { ScalaEnums(_).build }.mkString("\n\n")
  }

}
{'fraction_non_alphanumeric': 0.15266305895756194, 'fraction_numerical': 0.0028481913984619764, 'mean_word_length': 3.4120603015075375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '4735498', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1172, 'n_words': 233}