Skip to content

Commit

Permalink
Merge pull request #32 from zalando/#27_Recursive_model_definitions
Browse files Browse the repository at this point in the history
#27 recursive model definitions
  • Loading branch information
slavaschmidt authored Sep 21, 2016
2 parents 13a6e15 + 4b4dbbd commit 388992c
Show file tree
Hide file tree
Showing 21 changed files with 72 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object Generators extends JsValueGenerators {
{{if test_data_aliases}}

{{for alias in test_data_aliases}}
def {{alias.generator}} = {{alias.generator_name}}{{/for}}{{/if}}
def {{alias.generator}}{{if alias.generator_type}}{{alias.generator_type}}{{/if}} = {{alias.generator_name}}{{/for}}{{/if}}
{{if test_data_classes}}

{{for class in test_data_classes}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ trait DataGeneratorsStep extends EnrichmentStep[Type] {
private def containerGenerator(k: Reference, v: Type)(table: DenotationTable): Map[String, Any] = {
Map(
GENERATOR_NAME -> generatorNameForType(v, table, k),
"generator_type" -> generatorTypeNameForType(v, table, k),
"creator_method" -> prepend("create", generator(k, table)),
"generator" -> generator(k, table)
)
Expand All @@ -67,6 +68,11 @@ trait DataGeneratorsStep extends EnrichmentStep[Type] {
}
)

private val generatorTypeNameForType: (Type, DenotationTable, Reference) => String = {
case (c: Container, table, k) => containerTypeName(c, table, k)
case _ => ""
}

private val generatorNameForType: (Type, DenotationTable, Reference) => String = {
case (s: PrimitiveType, table, _) => primitiveType(s, table)
case (c: Container, table, k) => containerType(c, table, k)
Expand All @@ -92,6 +98,15 @@ trait DataGeneratorsStep extends EnrichmentStep[Type] {
}
}

private def containerTypeName(c: Container, t: DenotationTable, ref: Reference): String = {
lazy val className = typeNameDenotation(t, c.tpe.name)
c match {
case ArrResult(_, _) => s": Gen[List[$className]]"
case CatchAll(_, _) => s": Gen[Map[String, $className]]"
case _ => ""
}
}

private def primitiveType(tpe: Type, t: DenotationTable) =
s"arbitrary[${typeNameDenotation(t, tpe.name)}]"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ object Generators extends JsValueGenerators {



def KeyedArraysAdditionalPropertiesGenerator = _genMap[String,KeyedArraysAdditionalPropertiesCatchAll](arbitrary[String], KeyedArraysAdditionalPropertiesCatchAllGenerator)
def KeyedArraysAdditionalPropertiesCatchAllGenerator = Gen.containerOf[List,BigInt](arbitrary[BigInt])
def KeyedArraysAdditionalPropertiesGenerator: Gen[Map[String, KeyedArraysAdditionalPropertiesCatchAll]] = _genMap[String,KeyedArraysAdditionalPropertiesCatchAll](arbitrary[String], KeyedArraysAdditionalPropertiesCatchAllGenerator)
def KeyedArraysAdditionalPropertiesCatchAllGenerator: Gen[List[BigInt]] = Gen.containerOf[List,BigInt](arbitrary[BigInt])


def createKeyedArraysGenerator = _generate(KeyedArraysGenerator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object Generators extends JsValueGenerators {



def ZooTiersOptGenerator = Gen.containerOf[List,Pet](PetGenerator)
def ZooTiersOptGenerator: Gen[List[Pet]] = Gen.containerOf[List,Pet](PetGenerator)
def ZooTiersGenerator = Gen.option(ZooTiersOptGenerator)
def CatHuntingSkillGenerator = { import CatHuntingSkill._ ; Gen.oneOf(Seq(Clueless, Lazy, Adventurous, Aggressive)) }
def PutDummyGenerator = Gen.option(PetGenerator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ object Generators extends JsValueGenerators {
def ModelSchemaRootLinksGenerator = Gen.option(ModelSchemaRootLinksOptGenerator)
def PetTagsGenerator = Gen.option(PetTagsOptGenerator)
def ModelSchemaSilhouetteIdGenerator = { import ModelSchemaSilhouetteId._ ; Gen.oneOf(Seq(Kitchen, Bikini_top, Toys, Nightwear_combination, Bra, One_piece_underwear, Ball, Cleansing, Skincare, Jewellery, Headgear, Bustier, Beach_trouser, Bedroom, Lounge, Nail, Undershirt, Combination_clothing, Gloves, Fragrance, Other_equipment, Fitness, Bathroom, One_piece_nightwear, Sleeping_bag, Coat, Case, Sandals, Ankle_boots, Stocking, Shirt, Backpack, Face_cosmetic, Travel_equipment, Hair, Sneaker, Beauty_equipment, Bikini_combination, Backless_slipper, Beach_accessoires, Scarf, First_shoe, Voucher, Wallet, Peeling, Glasses, Boards, Sun, Shave, Low_shoe, Underwear_combination, Nightdress, Suit_accessoires, Watch, Headphones, Skates, Boots, Jacket, Etui, Night_shirt, Other_accessoires, Vest, Bag, System, Racket, Trouser, Lip_cosmetic, Keychain, Belt, Ballerina_shoe, One_piece_suit, Night_trouser, Skirt, Tights, Beach_shirt, Dress, Bicycle, Protector, Eye_cosmetic, Bathrobe, Bicycle_equipment, Pullover, One_piece_beachwear, Underpant, Living, Cardigan, Corsage, Shoe_accessoires, Umbrella, Pumps, Tent, T_shirt_top, Ski)) }
def PetPhotoUrlsGenerator = Gen.containerOf[List,String](arbitrary[String])
def PetPhotoUrlsGenerator: Gen[List[String]] = Gen.containerOf[List,String](arbitrary[String])
def ModelSchemaLengthRegisterGenerator = Gen.option(arbitrary[String])
def ModelSchemaAgeGroupsGenerator = Gen.containerOf[List,ModelSchemaAgeGroupsArrResult](ModelSchemaAgeGroupsArrResultGenerator)
def ModelSchemaAgeGroupsGenerator: Gen[List[ModelSchemaAgeGroupsArrResult]] = Gen.containerOf[List,ModelSchemaAgeGroupsArrResult](ModelSchemaAgeGroupsArrResultGenerator)
def PetCategoryGenerator = Gen.option(PetCategoryOptGenerator)
def ModelSchemaAgeGroupsArrResultGenerator = { import ModelSchemaAgeGroupsArrResult._ ; Gen.oneOf(Seq(Baby, Kid, Teen, Adult)) }
def PetTagsOptGenerator = Gen.containerOf[List,PetCategoryOpt](PetCategoryOptGenerator)
def PetTagsOptGenerator: Gen[List[PetCategoryOpt]] = Gen.containerOf[List,PetCategoryOpt](PetCategoryOptGenerator)
def ModelSchemaRootMetaGenerator = Gen.option(ModelSchemaRootMetaOptGenerator)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ object Generators extends JsValueGenerators {



def ModelSchemaSpecialDescriptionsOptGenerator = Gen.containerOf[List,String](arbitrary[String])
def ModelSchemaSpecialDescriptionsOptGenerator: Gen[List[String]] = Gen.containerOf[List,String](arbitrary[String])
def MetaCopyrightGenerator = Gen.option(arbitrary[String])
def ModelSchemaKeywordsGenerator = Gen.option(arbitrary[String])
def ModelSchemaSpecialDescriptionsGenerator = Gen.option(ModelSchemaSpecialDescriptionsOptGenerator)
def ErrorsErrorsOptGenerator = Gen.containerOf[List,Error](ErrorGenerator)
def ErrorsErrorsOptGenerator: Gen[List[Error]] = Gen.containerOf[List,Error](ErrorGenerator)
def ModelSchemaRootDataGenerator = Gen.option(ModelSchemaGenerator)
def ErrorSourceGenerator = Gen.option(ErrorSourceNameClashGenerator)
def ModelSchemaRootLinksGenerator = Gen.option(LinksGenerator)
def ModelSchemaSilhouetteIdGenerator = { import ModelSchemaSilhouetteId._ ; Gen.oneOf(Seq(Kitchen, Bikini_top, Toys, Nightwear_combination, Bra, One_piece_underwear, Ball, Cleansing, Skincare, Jewellery, Headgear, Bustier, Beach_trouser, Bedroom, Lounge, Nail, Undershirt, Combination_clothing, Gloves, Fragrance, Other_equipment, Fitness, Bathroom, One_piece_nightwear, Sleeping_bag, Coat, Case, Sandals, Ankle_boots, Stocking, Shirt, Backpack, Face_cosmetic, Travel_equipment, Hair, Sneaker, Beauty_equipment, Bikini_combination, Backless_slipper, Beach_accessoires, Scarf, First_shoe, Voucher, Wallet, Peeling, Glasses, Boards, Sun, Shave, Low_shoe, Underwear_combination, Nightdress, Suit_accessoires, Watch, Headphones, Skates, Boots, Jacket, Etui, Night_shirt, Other_accessoires, Vest, Bag, System, Racket, Trouser, Lip_cosmetic, Keychain, Belt, Ballerina_shoe, One_piece_suit, Night_trouser, Skirt, Tights, Beach_shirt, Dress, Bicycle, Protector, Eye_cosmetic, Bathrobe, Bicycle_equipment, Pullover, One_piece_beachwear, Underpant, Living, Cardigan, Corsage, Shoe_accessoires, Umbrella, Pumps, Tent, T_shirt_top, Ski)) }
def ModelSchemaLengthRegisterGenerator = Gen.option(arbitrary[String])
def ErrorsErrorsGenerator = Gen.option(ErrorsErrorsOptGenerator)
def ModelSchemaAgeGroupsGenerator = Gen.containerOf[List,ModelSchemaAgeGroupsArrResult](ModelSchemaAgeGroupsArrResultGenerator)
def ModelSchemaAgeGroupsGenerator: Gen[List[ModelSchemaAgeGroupsArrResult]] = Gen.containerOf[List,ModelSchemaAgeGroupsArrResult](ModelSchemaAgeGroupsArrResultGenerator)
def ModelSchemaAgeGroupsArrResultGenerator = { import ModelSchemaAgeGroupsArrResult._ ; Gen.oneOf(Seq(Baby, Kid, Teen, Adult)) }
def ModelSchemaRootMetaGenerator = Gen.option(MetaGenerator)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object Generators extends JsValueGenerators {
def PetsGetLimitGenerator = Gen.option(arbitrary[Int])
def PetsGetTagsOptGenerator = _genList(arbitrary[String], "csv")
def NewPetTagGenerator = Gen.option(arbitrary[String])
def PetsGetResponses200Generator = Gen.containerOf[List,Pet](PetGenerator)
def PetsGetResponses200Generator: Gen[List[Pet]] = Gen.containerOf[List,Pet](PetGenerator)
def PetsGetTagsGenerator = Gen.option(PetsGetTagsOptGenerator)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ object Generators extends JsValueGenerators {
def NullGenerator = arbitrary[Null]
def OrderStatusGenerator = Gen.option(arbitrary[String])
def PetsFindByStatusGetStatusOptGenerator = _genList(arbitrary[String], "multi")
def UsersCreateWithListPostBodyOptGenerator = Gen.containerOf[List,User](UserGenerator)
def UsersCreateWithListPostBodyOptGenerator: Gen[List[User]] = Gen.containerOf[List,User](UserGenerator)
def OrderPetIdGenerator = Gen.option(arbitrary[Long])
def PetsFindByStatusGetResponses200Generator = Gen.containerOf[List,Pet](PetGenerator)
def PetsFindByStatusGetResponses200Generator: Gen[List[Pet]] = Gen.containerOf[List,Pet](PetGenerator)
def PetsPostBodyGenerator = Gen.option(PetGenerator)
def OrderShipDateGenerator = Gen.option(arbitrary[ZonedDateTime])
def UsersUsernamePutBodyGenerator = Gen.option(UserGenerator)
Expand All @@ -49,11 +49,11 @@ object Generators extends JsValueGenerators {
def PetTagsGenerator = Gen.option(PetTagsOptGenerator)
def LongGenerator = arbitrary[Long]
def OrderQuantityGenerator = Gen.option(arbitrary[Int])
def PetPhotoUrlsGenerator = Gen.containerOf[List,String](arbitrary[String])
def PetPhotoUrlsGenerator: Gen[List[String]] = Gen.containerOf[List,String](arbitrary[String])
def UsersCreateWithListPostBodyGenerator = Gen.option(UsersCreateWithListPostBodyOptGenerator)
def PetsFindByStatusGetStatusGenerator = Gen.option(PetsFindByStatusGetStatusOptGenerator)
def PetCategoryGenerator = Gen.option(TagGenerator)
def PetTagsOptGenerator = Gen.containerOf[List,Tag](TagGenerator)
def PetTagsOptGenerator: Gen[List[Tag]] = Gen.containerOf[List,Tag](TagGenerator)


def createUserGenerator = _generate(UserGenerator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ object Generators extends JsValueGenerators {



def ModelSchemaSpecialDescriptionsOptGenerator = Gen.containerOf[List,String](arbitrary[String])
def ModelSchemaSpecialDescriptionsOptGenerator: Gen[List[String]] = Gen.containerOf[List,String](arbitrary[String])
def MetaCopyrightGenerator = Gen.option(arbitrary[String])
def ModelSchemaKeywordsGenerator = Gen.option(arbitrary[String])
def ModelSchemaSpecialDescriptionsGenerator = Gen.option(ModelSchemaSpecialDescriptionsOptGenerator)
def ErrorsErrorsOptGenerator = Gen.containerOf[List,Error](ErrorGenerator)
def ErrorsErrorsOptGenerator: Gen[List[Error]] = Gen.containerOf[List,Error](ErrorGenerator)
def ModelSchemaRootDataGenerator = Gen.option(ModelSchemaGenerator)
def ErrorSourceGenerator = Gen.option(ErrorSourceNameClashGenerator)
def ModelSchemaRootLinksGenerator = Gen.option(LinksGenerator)
def ModelSchemaSilhouetteIdGenerator = { import ModelSchemaSilhouetteId._ ; Gen.oneOf(Seq(Kitchen, Bikini_top, Toys, Nightwear_combination, Bra, One_piece_underwear, Ball, Cleansing, Skincare, Jewellery, Headgear, Bustier, Beach_trouser, Bedroom, Lounge, Nail, Undershirt, Combination_clothing, Gloves, Fragrance, Other_equipment, Fitness, Bathroom, One_piece_nightwear, Sleeping_bag, Coat, Case, Sandals, Ankle_boots, Stocking, Shirt, Backpack, Face_cosmetic, Travel_equipment, Hair, Sneaker, Beauty_equipment, Bikini_combination, Backless_slipper, Beach_accessoires, Scarf, First_shoe, Voucher, Wallet, Peeling, Glasses, Boards, Sun, Shave, Low_shoe, Underwear_combination, Nightdress, Suit_accessoires, Watch, Headphones, Skates, Boots, Jacket, Etui, Night_shirt, Other_accessoires, Vest, Bag, System, Racket, Trouser, Lip_cosmetic, Keychain, Belt, Ballerina_shoe, One_piece_suit, Night_trouser, Skirt, Tights, Beach_shirt, Dress, Bicycle, Protector, Eye_cosmetic, Bathrobe, Bicycle_equipment, Pullover, One_piece_beachwear, Underpant, Living, Cardigan, Corsage, Shoe_accessoires, Umbrella, Pumps, Tent, T_shirt_top, Ski)) }
def ModelSchemaLengthRegisterGenerator = Gen.option(arbitrary[String])
def ErrorsErrorsGenerator = Gen.option(ErrorsErrorsOptGenerator)
def ModelSchemaAgeGroupsGenerator = Gen.containerOf[List,ModelSchemaAgeGroupsArrResult](ModelSchemaAgeGroupsArrResultGenerator)
def ModelSchemaAgeGroupsGenerator: Gen[List[ModelSchemaAgeGroupsArrResult]] = Gen.containerOf[List,ModelSchemaAgeGroupsArrResult](ModelSchemaAgeGroupsArrResultGenerator)
def ModelSchemaAgeGroupsArrResultGenerator = { import ModelSchemaAgeGroupsArrResult._ ; Gen.oneOf(Seq(Baby, Kid, Teen, Adult)) }
def ModelSchemaRootMetaGenerator = Gen.option(MetaGenerator)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object Generators extends JsValueGenerators {
def NullGenerator = arbitrary[Null]
def BigIntGenerator = arbitrary[BigInt]
def PutPetGenerator = Gen.option(PetGenerator)
def GetResponses200Generator = Gen.containerOf[List,Pet](PetGenerator)
def GetResponses200Generator: Gen[List[Pet]] = Gen.containerOf[List,Pet](PetGenerator)


def createPetGenerator = _generate(PetGenerator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ object Generators extends JsValueGenerators {
def MediaIdGenerator = Gen.option(arbitrary[BigInt])
def MediaVideosLow_resolutionGenerator = Gen.option(ImageGenerator)
def UsersUser_idRelationshipPostActionGenerator = Gen.option(UsersUser_idRelationshipPostActionOptGenerator)
def MediaTagsOptGenerator = Gen.containerOf[List,Tag](TagGenerator)
def MediaTagsOptGenerator: Gen[List[Tag]] = Gen.containerOf[List,Tag](TagGenerator)
def MediaImagesGenerator = Gen.option(MediaImagesOptGenerator)
def MediaLikesGenerator = Gen.option(MediaLikesOptGenerator)
def BigIntNameClashGenerator = arbitrary[BigInt]
def MediaUsers_in_photoOptGenerator = Gen.containerOf[List,MiniProfile](MiniProfileGenerator)
def MediaMedia_idLikesGetResponses200DataOptGenerator = Gen.containerOf[List,Like](LikeGenerator)
def MediaUsers_in_photoOptGenerator: Gen[List[MiniProfile]] = Gen.containerOf[List,MiniProfile](MiniProfileGenerator)
def MediaMedia_idLikesGetResponses200DataOptGenerator: Gen[List[Like]] = Gen.containerOf[List,Like](LikeGenerator)
def LocationsSearchGetResponses200DataGenerator = Gen.option(LocationsSearchGetResponses200DataOptGenerator)
def MediaComments_escGenerator = Gen.option(MediaComments_OptGenerator)
def MediaSearchGetResponses200DataOptGenerator = Gen.containerOf[List,MediaSearchGetResponses200DataOptArrResult](MediaSearchGetResponses200DataOptArrResultGenerator)
def MediaSearchGetResponses200DataOptGenerator: Gen[List[MediaSearchGetResponses200DataOptArrResult]] = Gen.containerOf[List,MediaSearchGetResponses200DataOptArrResult](MediaSearchGetResponses200DataOptArrResultGenerator)
def CommentFromGenerator = Gen.option(MiniProfileGenerator)
def LocationsSearchGetResponses200DataOptGenerator = Gen.containerOf[List,Location](LocationGenerator)
def LocationsSearchGetResponses200DataOptGenerator: Gen[List[Location]] = Gen.containerOf[List,Location](LocationGenerator)
def MediaSearchGetResponses200DataGenerator = Gen.option(MediaSearchGetResponses200DataOptGenerator)
def UsersSelfFeedGetResponses200DataOptGenerator = Gen.containerOf[List,Media](MediaGenerator)
def UsersSelfFeedGetResponses200DataOptGenerator: Gen[List[Media]] = Gen.containerOf[List,Media](MediaGenerator)
def UsersUser_idRelationshipPostActionOptGenerator = { import UsersUser_idRelationshipPostActionOpt._ ; Gen.oneOf(Seq(Follow, Approve, Unfollow, Block, Unblock)) }
def MediaComments_DataOptGenerator = Gen.containerOf[List,Comment](CommentGenerator)
def MediaComments_DataOptGenerator: Gen[List[Comment]] = Gen.containerOf[List,Comment](CommentGenerator)
def UsersUser_idGetResponses200DataGenerator = Gen.option(UserGenerator)
def MediaVideosGenerator = Gen.option(MediaVideosOptGenerator)
def MediaLocationGenerator = Gen.option(LocationGenerator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ object Generators extends JsValueGenerators {
def TopicsTopicEventsGetStream_timeoutGenerator = Gen.option(arbitrary[Int])
def IntGenerator = arbitrary[Int]
def EventEvent_typeGenerator = Gen.option(arbitrary[String])
def SimpleStreamEventEventsOptGenerator = Gen.containerOf[List,Event](EventGenerator)
def SimpleStreamEventEventsOptGenerator: Gen[List[Event]] = Gen.containerOf[List,Event](EventGenerator)
def EventMetaDataParent_idGenerator = Gen.option(arbitrary[UUID])
def EventMetadataGenerator = Gen.option(EventMetaDataNameClashGenerator)
def NullGenerator = arbitrary[Null]
def EventMetaDataScopesOptGenerator = Gen.containerOf[List,String](arbitrary[String])
def TopicsTopicPartitionsGetResponses200Generator = Gen.containerOf[List,TopicPartition](TopicPartitionGenerator)
def EventMetaDataScopesOptGenerator: Gen[List[String]] = Gen.containerOf[List,String](arbitrary[String])
def TopicsTopicPartitionsGetResponses200Generator: Gen[List[TopicPartition]] = Gen.containerOf[List,TopicPartition](TopicPartitionGenerator)
def TopicsTopicEventsBatchPostEventGenerator = Gen.option(EventGenerator)
def SimpleStreamEventEventsGenerator = Gen.option(SimpleStreamEventEventsOptGenerator)
def EventMetaDataScopesGenerator = Gen.option(EventMetaDataScopesOptGenerator)
def TopicsGetResponses200Generator = Gen.containerOf[List,Topic](TopicGenerator)
def TopicsGetResponses200Generator: Gen[List[Topic]] = Gen.containerOf[List,Topic](TopicGenerator)


def createEventMetaDataNameClashGenerator = _generate(EventMetaDataNameClashGenerator)
Expand Down
Loading

0 comments on commit 388992c

Please sign in to comment.