<commit_before>package com.iheart.playSwagger

import com.iheart.playSwagger.Domain.{Definition, SwaggerParameter}
import org.specs2.mutable.Specification

case class Foo(barStr: String, barInt: Int, barLong: Option[Long], reffedFoo: ReffedFoo)
case class ReffedFoo(name: String, refrefFoo: RefReffedFoo)
case class RefReffedFoo(bar: String)

case class FooWithSeq(seq: Seq[SeqItem])

case class SeqItem(bar: String)

case class FooWithSeq2(abc1: Seq[Bar.Bar], abc2: Seq[Seq[Bar.Foo]])

object Bar {
  type Bar = String
  type Foo = Int
}

case class WithListOfPrimitive(seq: Seq[Int])

case class FooWithOption(op: Option[OptionItem])
case class OptionItem(bar: String)

object MyObject {
  type MyId = Int
  case class MyInnerClass(bar: String, id: MyId)
}
class DefinitionGeneratorSpec extends Specification {
  implicit val cl = getClass.getClassLoader

  "definition" >> {

    "generate name correctly" >> {
      DefinitionGenerator().definition[Foo].name === "com.iheart.playSwagger.Foo"
    }

    "generate from string classname " >> {
      DefinitionGenerator().definition("com.iheart.playSwagger.Foo").name === "com.iheart.playSwagger.Foo"
    }

    "generate properties" >> {

      val result = DefinitionGenerator("com.iheart.playSwagger").definition[Foo].properties

      result.length === 4

      "with correct string property" >> {
        result.head === SwaggerParameter(name = "barStr", `type` = Some("string"))
      }

      "with correct int32 property" >> {
        result(1) === SwaggerParameter(name = "barInt", `type` = Some("integer"), format = Some("int32"))
      }

      "with correct long property" >> {
        result(2) === SwaggerParameter(name = "barLong", `type` = Some("integer"), format = Some("int64"), required = false)
      }

      "with reference type" >> {
        result(3) === SwaggerParameter(name = "reffedFoo", referenceType = Some("com.iheart.playSwagger.ReffedFoo"))
      }

    }

    "read class in Object" >> {
      val result = DefinitionGenerator("com.iheart").definition("com.iheart.playSwagger.MyObject.MyInnerClass")
      result.properties.head.name === "bar"
    }

    "read alias type in Object" >> {
      val result = DefinitionGenerator("com.iheart").definition("com.iheart.playSwagger.MyObject.MyInnerClass")
      result.properties.last.name === "id"
      result.properties.last.`type` === Some("integer")
      result.properties.last.referenceType === None
    }

    "read seqence items" >> {
      val result = DefinitionGenerator("com.iheart").definition("com.iheart.playSwagger.FooWithSeq")
      result.properties.head.items.get.referenceType === Some("com.iheart.playSwagger.SeqItem")
    }<commit_msg>Add test case for sequences of reference types<commit_after>package com.iheart.playSwagger

import com.iheart.playSwagger.Domain.{Definition, SwaggerParameter}
import org.specs2.mutable.Specification

case class Foo(barStr: String, barInt: Int, barLong: Option[Long], reffedFoo: ReffedFoo, seqReffedFoo: Seq[ReffedFoo], optionSeqReffedFoo: Option[Seq[ReffedFoo]])
case class ReffedFoo(name: String, refrefFoo: RefReffedFoo)
case class RefReffedFoo(bar: String)

case class FooWithSeq(seq: Seq[SeqItem])

case class SeqItem(bar: String)

case class FooWithSeq2(abc1: Seq[Bar.Bar], abc2: Seq[Seq[Bar.Foo]])

object Bar {
  type Bar = String
  type Foo = Int
}

case class WithListOfPrimitive(seq: Seq[Int])

case class FooWithOption(op: Option[OptionItem])
case class OptionItem(bar: String)

object MyObject {
  type MyId = Int
  case class MyInnerClass(bar: String, id: MyId)
}
class DefinitionGeneratorSpec extends Specification {
  implicit val cl = getClass.getClassLoader

  "definition" >> {

    "generate name correctly" >> {
      DefinitionGenerator().definition[Foo].name === "com.iheart.playSwagger.Foo"
    }

    "generate from string classname " >> {
      DefinitionGenerator().definition("com.iheart.playSwagger.Foo").name === "com.iheart.playSwagger.Foo"
    }

    "generate properties" >> {

      val result = DefinitionGenerator("com.iheart.playSwagger").definition[Foo].properties

      result.length === 6

      "with correct string property" >> {
        result.head === SwaggerParameter(name = "barStr", `type` = Some("string"))
      }

      "with correct int32 property" >> {
        result(1) === SwaggerParameter(name = "barInt", `type` = Some("integer"), format = Some("int32"))
      }

      "with correct long property" >> {
        result(2) === SwaggerParameter(name = "barLong", `type` = Some("integer"), format = Some("int64"), required = false)
      }

      "with reference type" >> {
        result(3) === SwaggerParameter(name = "reffedFoo", referenceType = Some("com.iheart.playSwagger.ReffedFoo"))
      }

      "with sequence of reference type" >> {
        val itemsParam = SwaggerParameter(name = "seqReffedFoo", referenceType = Some("com.iheart.playSwagger.ReffedFoo"))
        result(4) === SwaggerParameter(name = "seqReffedFoo", `type` = Some("array"), items = Some(itemsParam))
      }

      "with optional sequence of reference type" >> {
        val itemsParam = SwaggerParameter(name = "optionSeqReffedFoo", referenceType = Some("com.iheart.playSwagger.ReffedFoo"))
        result(5) === SwaggerParameter(name = "optionSeqReffedFoo", `type` = Some("array"), items = Some(itemsParam), required = false)
      }

    }

    "read class in Object" >> {
      val result = DefinitionGenerator("com.iheart").definition("com.iheart.playSwagger.MyObject.MyInnerClass")
      result.properties.head.name === "bar"
    }

    "read alias type in Object" >> {
      val result = DefinitionGenerator("com.iheart").definition("com.iheart.playSwagger.MyObject.MyInnerClass")
      result.properties.last.name === "id"
      result.properties.last.`type` === Some("integer")
      result.properties.last.referenceType === None
    }

    "read seqence items" >> {
      val result = DefinitionGenerator("com.iheart").definition("com.iheart.playSwagger.FooWithSeq")
      result.properties.head.items.get.referenceType === Some("com.iheart.playSwagger.SeqItem")
    }
{'fraction_non_alphanumeric': 0.13901639344262295, 'fraction_numerical': 0.004918032786885246, 'mean_word_length': 3.976345840130506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 51, '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': '1918889', 'n_tokens_mistral': 1931, 'n_tokens_neox': 1854, 'n_words': 392}