@@ -2,6 +2,7 @@ package io.kotest.extensions.ktor.openapi
2
2
3
3
import io.kotest.core.spec.style.FunSpec
4
4
import io.kotest.matchers.string.shouldInclude
5
+ import io.kotest.matchers.string.shouldNotInclude
5
6
import io.ktor.http.ContentType
6
7
import io.ktor.http.HttpMethod
7
8
import io.ktor.http.HttpStatusCode
@@ -114,4 +115,56 @@ class OpenApiWriterTest : FunSpec({
114
115
file.readText() shouldInclude " beam me up scotty"
115
116
file.readText() shouldInclude " text/css"
116
117
}
118
+
119
+ test("builder should not set example key if only one response") {
120
+ val file = Files .createTempFile("openapi", "test")
121
+ val builder = OpenApiBuilder (OpenApiConfig (path = file))
122
+ builder.addTraces(
123
+ "parth path",
124
+ listOf(
125
+ Trace .default(HttpMethod .Get , "parth path")
126
+ .copy(
127
+ responseBody = "beam me up scotty",
128
+ contentType = ContentType .Text .CSS ,
129
+ status = HttpStatusCode .MovedPermanently ,
130
+ )
131
+ )
132
+ )
133
+ OpenApiWriter (file).write(builder)
134
+ file.readText() shouldInclude " beam me up scotty"
135
+ file.readText() shouldNotInclude " Example 1"
136
+ }
137
+
138
+ test("builder should not include identical response bodies") {
139
+ val file = Files .createTempFile("openapi", "test")
140
+ val builder = OpenApiBuilder (OpenApiConfig (path = file))
141
+ builder.addTraces(
142
+ "parth path",
143
+ listOf(
144
+ Trace .default(HttpMethod .Get , "parth path")
145
+ .copy(
146
+ responseBody = "beam me up scotty",
147
+ contentType = ContentType .Text .CSS ,
148
+ status = HttpStatusCode .MovedPermanently ,
149
+ ),
150
+ Trace .default(HttpMethod .Get , "parth path")
151
+ .copy(
152
+ responseBody = "beam me up jimmy",
153
+ contentType = ContentType .Text .CSS ,
154
+ status = HttpStatusCode .MovedPermanently ,
155
+ ),
156
+ Trace .default(HttpMethod .Get , "parth path")
157
+ .copy(
158
+ responseBody = "beam me up scotty",
159
+ contentType = ContentType .Text .CSS ,
160
+ status = HttpStatusCode .MovedPermanently ,
161
+ )
162
+ )
163
+ )
164
+ OpenApiWriter (file).write(builder)
165
+ file.readText() shouldInclude " beam me up scotty"
166
+ file.readText() shouldInclude " Example 1"
167
+ file.readText() shouldInclude " Example 2"
168
+ file.readText() shouldNotInclude " Example 3"
169
+ }
117
170
})
0 commit comments