Skip to content

Commit 33e3ef6

Browse files
authored
Broken tests (#77)
* WIP: Request headers in tests * Test: changed expectations for generated tests
1 parent 3b40e17 commit 33e3ef6

20 files changed

+133
-194
lines changed

api-first-core/src/main/scala/de/zalando/apifirst/ast.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ object Application {
399399
security: Set[Security.Constraint] = Set.empty
400400
) {
401401
def asReference: Reference = (path.prepend("paths") / verb.toString.toLowerCase).ref
402+
val requiresBody: Boolean = Set[Http.Verb](Http.POST, Http.PUT, Http.PATCH).contains(verb)
402403
}
403404

404405
type ParameterLookupTable = Map[ParameterRef, Parameter]

play-scala-generator/src/main/scala/de/zalando/apifirst/generators/CallTestsStep.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ trait CallTestsStep extends EnrichmentStep[ApiCall] with ActionResults with Para
5757
) ++ parameters(call)(table)
5858
}
5959

60-
def acceptHeader(call: ApiCall): Set[Map[String, String]] =
61-
call.mimeOut.map(_.name).map { header =>
60+
def acceptHeader(call: ApiCall): Set[Map[String, String]] = {
61+
lazy val defined = call.mimeOut.map(_.name).map { header =>
6262
Map("name" -> header)
6363
}
64+
if (call.requiresBody) defined else Set(Map("name" -> "*/*"))
65+
}
6466

6567
def contentTypes(call: ApiCall): Set[Map[String, String]] =
6668
call.mimeIn.map(_.name).map { header =>
@@ -159,4 +161,4 @@ trait ActionResults extends EnrichmentStep[ApiCall] {
159161
}
160162
}
161163

162-
}
164+
}

play-scala-generator/src/test/resources/expected_results/tests/echo_api_yaml.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ class Echo_api_yamlSpec extends WordSpec with OptionValues with WsScalaTestClien
5858

5959
val url = s"""/echo/test-path/${toPath(id)}"""
6060
val contentTypes: Seq[String] = Seq()
61-
val acceptHeaders: Seq[String] = Seq()
61+
val acceptHeaders: Seq[String] = Seq(
62+
"*/*"
63+
)
6264
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
6365
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
6466

@@ -100,7 +102,9 @@ class Echo_api_yamlSpec extends WordSpec with OptionValues with WsScalaTestClien
100102

101103
val url = s"""/echo/test-path/${toPath(id)}"""
102104
val contentTypes: Seq[String] = Seq()
103-
val acceptHeaders: Seq[String] = Seq()
105+
val acceptHeaders: Seq[String] = Seq(
106+
"*/*"
107+
)
104108
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
105109
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
106110

play-scala-generator/src/test/resources/expected_results/tests/error_in_array_yaml.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class Error_in_array_yamlSpec extends WordSpec with OptionValues with WsScalaTes
5959

6060
val url = s"""/schema/model"""
6161
val contentTypes: Seq[String] = Seq()
62-
val acceptHeaders: Seq[String] = Seq()
62+
val acceptHeaders: Seq[String] = Seq(
63+
"*/*"
64+
)
6365
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
6466
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
6567

@@ -104,7 +106,9 @@ class Error_in_array_yamlSpec extends WordSpec with OptionValues with WsScalaTes
104106

105107
val url = s"""/schema/model"""
106108
val contentTypes: Seq[String] = Seq()
107-
val acceptHeaders: Seq[String] = Seq()
109+
val acceptHeaders: Seq[String] = Seq(
110+
"*/*"
111+
)
108112
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
109113
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
110114

play-scala-generator/src/test/resources/expected_results/tests/expanded_polymorphism_yaml.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class Expanded_polymorphism_yamlSpec extends WordSpec with OptionValues with WsS
189189
"application/json"
190190
)
191191
val acceptHeaders: Seq[String] = Seq(
192-
"application/json"
192+
"*/*"
193193
)
194194
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
195195
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -236,7 +236,7 @@ class Expanded_polymorphism_yamlSpec extends WordSpec with OptionValues with WsS
236236
"application/json"
237237
)
238238
val acceptHeaders: Seq[String] = Seq(
239-
"application/json"
239+
"*/*"
240240
)
241241
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
242242
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -317,7 +317,7 @@ class Expanded_polymorphism_yamlSpec extends WordSpec with OptionValues with WsS
317317
"application/json"
318318
)
319319
val acceptHeaders: Seq[String] = Seq(
320-
"application/json"
320+
"*/*"
321321
)
322322
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
323323
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -363,7 +363,7 @@ class Expanded_polymorphism_yamlSpec extends WordSpec with OptionValues with WsS
363363
"application/json"
364364
)
365365
val acceptHeaders: Seq[String] = Seq(
366-
"application/json"
366+
"*/*"
367367
)
368368
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
369369
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")

play-scala-generator/src/test/resources/expected_results/tests/full_petstore_api_yaml.scala

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,7 @@ class Full_petstore_api_yamlSpec extends WordSpec with OptionValues with WsScala
437437
val url = s"""/v2/users/login?${toQuery("username", username)}&${toQuery("password", password)}"""
438438
val contentTypes: Seq[String] = Seq()
439439
val acceptHeaders: Seq[String] = Seq(
440-
"application/json",
441-
442-
"application/xml"
440+
"*/*"
443441
)
444442
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
445443
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -484,9 +482,7 @@ class Full_petstore_api_yamlSpec extends WordSpec with OptionValues with WsScala
484482
val url = s"""/v2/users/login?${toQuery("username", username)}&${toQuery("password", password)}"""
485483
val contentTypes: Seq[String] = Seq()
486484
val acceptHeaders: Seq[String] = Seq(
487-
"application/json",
488-
489-
"application/xml"
485+
"*/*"
490486
)
491487
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
492488
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -566,9 +562,7 @@ class Full_petstore_api_yamlSpec extends WordSpec with OptionValues with WsScala
566562
val url = s"""/v2/stores/order/${toPath(orderId)}"""
567563
val contentTypes: Seq[String] = Seq()
568564
val acceptHeaders: Seq[String] = Seq(
569-
"application/json",
570-
571-
"application/xml"
565+
"*/*"
572566
)
573567
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
574568
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -612,9 +606,7 @@ class Full_petstore_api_yamlSpec extends WordSpec with OptionValues with WsScala
612606
val url = s"""/v2/stores/order/${toPath(orderId)}"""
613607
val contentTypes: Seq[String] = Seq()
614608
val acceptHeaders: Seq[String] = Seq(
615-
"application/json",
616-
617-
"application/xml"
609+
"*/*"
618610
)
619611
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
620612
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -691,9 +683,7 @@ class Full_petstore_api_yamlSpec extends WordSpec with OptionValues with WsScala
691683
val url = s"""/v2/users/${toPath(username)}"""
692684
val contentTypes: Seq[String] = Seq()
693685
val acceptHeaders: Seq[String] = Seq(
694-
"application/json",
695-
696-
"application/xml"
686+
"*/*"
697687
)
698688
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
699689
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -737,9 +727,7 @@ class Full_petstore_api_yamlSpec extends WordSpec with OptionValues with WsScala
737727
val url = s"""/v2/users/${toPath(username)}"""
738728
val contentTypes: Seq[String] = Seq()
739729
val acceptHeaders: Seq[String] = Seq(
740-
"application/json",
741-
742-
"application/xml"
730+
"*/*"
743731
)
744732
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
745733
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -940,9 +928,7 @@ class Full_petstore_api_yamlSpec extends WordSpec with OptionValues with WsScala
940928
val url = s"""/v2/users/${toPath(username)}"""
941929
val contentTypes: Seq[String] = Seq()
942930
val acceptHeaders: Seq[String] = Seq(
943-
"application/json",
944-
945-
"application/xml"
931+
"*/*"
946932
)
947933
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
948934
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -986,9 +972,7 @@ class Full_petstore_api_yamlSpec extends WordSpec with OptionValues with WsScala
986972
val url = s"""/v2/users/${toPath(username)}"""
987973
val contentTypes: Seq[String] = Seq()
988974
val acceptHeaders: Seq[String] = Seq(
989-
"application/json",
990-
991-
"application/xml"
975+
"*/*"
992976
)
993977
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
994978
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -1064,9 +1048,7 @@ class Full_petstore_api_yamlSpec extends WordSpec with OptionValues with WsScala
10641048
val url = s"""/v2/stores/order/${toPath(orderId)}"""
10651049
val contentTypes: Seq[String] = Seq()
10661050
val acceptHeaders: Seq[String] = Seq(
1067-
"application/json",
1068-
1069-
"application/xml"
1051+
"*/*"
10701052
)
10711053
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
10721054
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -1110,9 +1092,7 @@ class Full_petstore_api_yamlSpec extends WordSpec with OptionValues with WsScala
11101092
val url = s"""/v2/stores/order/${toPath(orderId)}"""
11111093
val contentTypes: Seq[String] = Seq()
11121094
val acceptHeaders: Seq[String] = Seq(
1113-
"application/json",
1114-
1115-
"application/xml"
1095+
"*/*"
11161096
)
11171097
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
11181098
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")

play-scala-generator/src/test/resources/expected_results/tests/hackweek_yaml.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class Hackweek_yamlSpec extends WordSpec with OptionValues with WsScalaTestClien
5959

6060
val url = s"""/boo/schema/model"""
6161
val contentTypes: Seq[String] = Seq()
62-
val acceptHeaders: Seq[String] = Seq()
62+
val acceptHeaders: Seq[String] = Seq(
63+
"*/*"
64+
)
6365
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
6466
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
6567

@@ -104,7 +106,9 @@ class Hackweek_yamlSpec extends WordSpec with OptionValues with WsScalaTestClien
104106

105107
val url = s"""/boo/schema/model"""
106108
val contentTypes: Seq[String] = Seq()
107-
val acceptHeaders: Seq[String] = Seq()
109+
val acceptHeaders: Seq[String] = Seq(
110+
"*/*"
111+
)
108112
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
109113
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
110114

play-scala-generator/src/test/resources/expected_results/tests/heroku_petstore_api_yaml.scala

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ class Heroku_petstore_api_yamlSpec extends WordSpec with OptionValues with WsSca
198198
"text/xml"
199199
)
200200
val acceptHeaders: Seq[String] = Seq(
201-
"application/json",
202-
203-
"text/html"
201+
"*/*"
204202
)
205203
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
206204
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -248,9 +246,7 @@ class Heroku_petstore_api_yamlSpec extends WordSpec with OptionValues with WsSca
248246
"text/xml"
249247
)
250248
val acceptHeaders: Seq[String] = Seq(
251-
"application/json",
252-
253-
"text/html"
249+
"*/*"
254250
)
255251
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
256252
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -329,9 +325,7 @@ class Heroku_petstore_api_yamlSpec extends WordSpec with OptionValues with WsSca
329325
"text/xml"
330326
)
331327
val acceptHeaders: Seq[String] = Seq(
332-
"application/json",
333-
334-
"text/html"
328+
"*/*"
335329
)
336330
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
337331
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -379,9 +373,7 @@ class Heroku_petstore_api_yamlSpec extends WordSpec with OptionValues with WsSca
379373
"text/xml"
380374
)
381375
val acceptHeaders: Seq[String] = Seq(
382-
"application/json",
383-
384-
"text/html"
376+
"*/*"
385377
)
386378
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
387379
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")

play-scala-generator/src/test/resources/expected_results/tests/nakadi_yaml.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Nakadi_yamlSpec extends WordSpec with OptionValues with WsScalaTestClient
6363
"application/json"
6464
)
6565
val acceptHeaders: Seq[String] = Seq(
66-
"application/json"
66+
"*/*"
6767
)
6868
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
6969
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -110,7 +110,7 @@ class Nakadi_yamlSpec extends WordSpec with OptionValues with WsScalaTestClient
110110
"application/json"
111111
)
112112
val acceptHeaders: Seq[String] = Seq(
113-
"application/json"
113+
"*/*"
114114
)
115115
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
116116
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -192,7 +192,7 @@ class Nakadi_yamlSpec extends WordSpec with OptionValues with WsScalaTestClient
192192
"application/json"
193193
)
194194
val acceptHeaders: Seq[String] = Seq(
195-
"application/json"
195+
"*/*"
196196
)
197197
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
198198
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -241,7 +241,7 @@ class Nakadi_yamlSpec extends WordSpec with OptionValues with WsScalaTestClient
241241
"application/json"
242242
)
243243
val acceptHeaders: Seq[String] = Seq(
244-
"application/json"
244+
"*/*"
245245
)
246246
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
247247
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -339,7 +339,7 @@ class Nakadi_yamlSpec extends WordSpec with OptionValues with WsScalaTestClient
339339
"application/json"
340340
)
341341
val acceptHeaders: Seq[String] = Seq(
342-
"application/json"
342+
"*/*"
343343
)
344344
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
345345
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -386,7 +386,7 @@ class Nakadi_yamlSpec extends WordSpec with OptionValues with WsScalaTestClient
386386
"application/json"
387387
)
388388
val acceptHeaders: Seq[String] = Seq(
389-
"application/json"
389+
"*/*"
390390
)
391391
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
392392
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -619,7 +619,7 @@ class Nakadi_yamlSpec extends WordSpec with OptionValues with WsScalaTestClient
619619
"application/json"
620620
)
621621
val acceptHeaders: Seq[String] = Seq(
622-
"application/json"
622+
"*/*"
623623
)
624624
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
625625
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -665,7 +665,7 @@ class Nakadi_yamlSpec extends WordSpec with OptionValues with WsScalaTestClient
665665
"application/json"
666666
)
667667
val acceptHeaders: Seq[String] = Seq(
668-
"application/json"
668+
"*/*"
669669
)
670670
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
671671
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")

play-scala-generator/src/test/resources/expected_results/tests/nested_arrays_validation_yaml.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Nested_arrays_validation_yamlSpec extends WordSpec with OptionValues with
6161
"application/json"
6262
)
6363
val acceptHeaders: Seq[String] = Seq(
64-
"application/json"
64+
"*/*"
6565
)
6666
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
6767
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")
@@ -110,7 +110,7 @@ class Nested_arrays_validation_yamlSpec extends WordSpec with OptionValues with
110110
"application/json"
111111
)
112112
val acceptHeaders: Seq[String] = Seq(
113-
"application/json"
113+
"*/*"
114114
)
115115
val contentHeaders = for { ct <- contentTypes; ac <- acceptHeaders } yield (ac, ct)
116116
if (contentHeaders.isEmpty) throw new IllegalStateException(s"No 'produces' defined for the $url")

0 commit comments

Comments
 (0)