Skip to content

Commit 00f74f0

Browse files
committed
simplify success response usage in tests
1 parent 8386766 commit 00f74f0

8 files changed

Lines changed: 59 additions & 53 deletions

File tree

‎openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/converter/ApiConverter.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class ApiConverter(
191191
}
192192

193193
private fun checkSuccessResponse(endpoint: Endpoint) {
194-
if (endpoint.endpointResponses.isEmpty()) {
194+
if (!endpoint.hasSuccessResponse) {
195195
log.warn("endpoint '${endpoint.path}' has no success 1xx/2xx/3xx response.")
196196
}
197197
}

‎openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/model/Endpoint.kt‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@ class Endpoint(
2828
// grouped responses
2929
val endpointResponses: List<EndpointResponse> = createEndpointResponses()
3030

31+
val hasSuccessResponse: Boolean
32+
get() = endpointResponses.isNotEmpty()
33+
34+
// test only
35+
val firstSuccessResponse: EndpointResponse
36+
get() = endpointResponses.first()
37+
3138
fun getRequestBody(): RequestBody {
3239
return requestBodies.first ()
3340
}
3441

3542
/**
36-
* all possible responses for an openapi status ('200', '2xx', ... or 'default'). If the given
43+
* all possible responses for an OpenAPI status ('200', '2xx', ... or 'default'). If the given
3744
* status has no responses, the result is an empty list.
3845
*
3946
* @param status the response status
@@ -80,8 +87,7 @@ class Endpoint(
8087
@Deprecated("only used in test")
8188
fun getProducesContentTypes (status: String): Set<String> {
8289
return endpointResponses
83-
.map { it.contentTypes }
84-
.flatten()
90+
.flatMap { it.contentTypes }
8591
.toSet()
8692
}
8793

‎openapi-processor-core/src/test/groovy/io/openapiprocessor/core/writer/java/MethodWriterGSpec.groovy‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class MethodWriterGSpec extends Specification {
4545
}
4646
4747
when:
48-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
48+
writer.write (target, endpoint, endpoint.firstSuccessResponse)
4949
5050
then:
5151
target.toString () == """\
@@ -79,7 +79,7 @@ class MethodWriterGSpec extends Specification {
7979
}
8080
8181
when:
82-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
82+
writer.write (target, endpoint, endpoint.firstSuccessResponse)
8383
8484
then:
8585
target.toString () == """\
@@ -98,7 +98,7 @@ class MethodWriterGSpec extends Specification {
9898
}
9999
100100
when:
101-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
101+
writer.write (target, endpoint, endpoint.firstSuccessResponse)
102102
103103
then:
104104
target.toString () == """\
@@ -128,7 +128,7 @@ class MethodWriterGSpec extends Specification {
128128
}
129129
130130
when:
131-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
131+
writer.write (target, endpoint, endpoint.firstSuccessResponse)
132132
133133
then:
134134
target.toString () == """\
@@ -162,7 +162,7 @@ class MethodWriterGSpec extends Specification {
162162
}
163163
164164
when:
165-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
165+
writer.write (target, endpoint, endpoint.firstSuccessResponse)
166166
167167
then:
168168
target.toString () == """\
@@ -185,7 +185,7 @@ class MethodWriterGSpec extends Specification {
185185
}
186186
187187
when:
188-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
188+
writer.write (target, endpoint, endpoint.firstSuccessResponse)
189189
190190
then:
191191
target.toString () == """\
@@ -210,7 +210,7 @@ class MethodWriterGSpec extends Specification {
210210
}
211211
212212
when:
213-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
213+
writer.write (target, endpoint, endpoint.firstSuccessResponse)
214214
215215
then:
216216
target.toString () == """\
@@ -236,7 +236,7 @@ class MethodWriterGSpec extends Specification {
236236
}
237237
238238
when:
239-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
239+
writer.write (target, endpoint, endpoint.firstSuccessResponse)
240240
241241
then:
242242
target.toString () == """\
@@ -254,7 +254,7 @@ class MethodWriterGSpec extends Specification {
254254
}
255255
256256
when:
257-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
257+
writer.write (target, endpoint, endpoint.firstSuccessResponse)
258258
259259
then:
260260
target.toString () == """\
@@ -273,7 +273,7 @@ class MethodWriterGSpec extends Specification {
273273
}
274274
275275
when:
276-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
276+
writer.write (target, endpoint, endpoint.firstSuccessResponse)
277277
278278
then:
279279
target.toString () == """\
@@ -297,7 +297,7 @@ class MethodWriterGSpec extends Specification {
297297
}
298298
299299
when:
300-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
300+
writer.write (target, endpoint, endpoint.firstSuccessResponse)
301301
302302
then:
303303
target.toString () == """\
@@ -323,7 +323,7 @@ class MethodWriterGSpec extends Specification {
323323
}
324324
325325
when:
326-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
326+
writer.write (target, endpoint, endpoint.firstSuccessResponse)
327327
328328
then:
329329
target.toString () == """\

‎openapi-processor-core/src/test/kotlin/io/openapiprocessor/core/builder/api/EndpointBuilderSpec.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class EndpointBuilderSpec: StringSpec({
4444
}
4545

4646
ep.endpointResponses.size shouldBe 1
47-
ep.endpointResponses.first().contentType shouldNotBe null
48-
ep.endpointResponses.first().responseType shouldNotBe null
47+
ep.firstSuccessResponse.contentType shouldNotBe null
48+
ep.firstSuccessResponse.responseType shouldNotBe null
4949
}
5050

5151
"adds endpoint parameter" {

‎openapi-processor-core/src/test/kotlin/io/openapiprocessor/core/writer/java/JavaDocFactorySpec.kt‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class JavaDocFactorySpec: FreeSpec({
3838
}
3939
}
4040

41-
val html = factory.create(endpoint, endpoint.endpointResponses.first())
41+
val html = factory.create(endpoint, endpoint.firstSuccessResponse)
4242

4343
html.shouldBeEmpty()
4444
}
@@ -55,7 +55,7 @@ class JavaDocFactorySpec: FreeSpec({
5555
}
5656
}
5757

58-
val html = factory.create(endpoint, endpoint.endpointResponses.first())
58+
val html = factory.create(endpoint, endpoint.firstSuccessResponse)
5959

6060
html shouldBe """
6161
|/**
@@ -76,7 +76,7 @@ class JavaDocFactorySpec: FreeSpec({
7676
}
7777
}
7878

79-
val html = factory.create(endpoint, endpoint.endpointResponses.first())
79+
val html = factory.create(endpoint, endpoint.firstSuccessResponse)
8080

8181
html shouldBe """
8282
|/**
@@ -99,7 +99,7 @@ class JavaDocFactorySpec: FreeSpec({
9999
}
100100
}
101101

102-
val html = factory.create(endpoint, endpoint.endpointResponses.first())
102+
val html = factory.create(endpoint, endpoint.firstSuccessResponse)
103103

104104
html shouldBe """
105105
|/**
@@ -125,7 +125,7 @@ class JavaDocFactorySpec: FreeSpec({
125125
}
126126
}
127127

128-
val html = factory.create(endpoint, endpoint.endpointResponses.first())
128+
val html = factory.create(endpoint, endpoint.firstSuccessResponse)
129129

130130
html shouldBe """
131131
|/**
@@ -150,7 +150,7 @@ class JavaDocFactorySpec: FreeSpec({
150150
}
151151
}
152152

153-
val html = factory.create(endpoint, endpoint.endpointResponses.first())
153+
val html = factory.create(endpoint, endpoint.firstSuccessResponse)
154154

155155
html shouldBe """
156156
|/**
@@ -183,7 +183,7 @@ class JavaDocFactorySpec: FreeSpec({
183183
}
184184
}
185185

186-
val html = factory.create(endpoint, endpoint.endpointResponses.first())
186+
val html = factory.create(endpoint, endpoint.firstSuccessResponse)
187187

188188
html shouldBe """
189189
|/**

‎openapi-processor-core/src/test/kotlin/io/openapiprocessor/core/writer/java/MethodWriterAnnotationSpec.kt‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class MethodWriterAnnotationSpec: StringSpec ({
5151
}
5252
}
5353

54-
val imports = writer(options).write (target, endpoint, endpoint.endpointResponses.first ())
54+
val imports = writer(options).write (target, endpoint, endpoint.firstSuccessResponse)
5555

5656
target.toString () shouldBe
5757
"""
@@ -76,7 +76,7 @@ class MethodWriterAnnotationSpec: StringSpec ({
7676
}
7777
}
7878

79-
val imports = writer(options).write (target, endpoint, endpoint.endpointResponses.first ())
79+
val imports = writer(options).write (target, endpoint, endpoint.firstSuccessResponse)
8080

8181
target.toString () shouldBe
8282
"""
@@ -108,7 +108,7 @@ class MethodWriterAnnotationSpec: StringSpec ({
108108
}
109109

110110
// when:
111-
val imports = writer(options).write (target, endpoint, endpoint.endpointResponses.first ())
111+
val imports = writer(options).write (target, endpoint, endpoint.firstSuccessResponse)
112112

113113
// then:
114114
target.toString () shouldBe
@@ -148,7 +148,7 @@ class MethodWriterAnnotationSpec: StringSpec ({
148148
}
149149

150150
// when:
151-
val imports = writer(options).write (target, endpoint, endpoint.endpointResponses.first ())
151+
val imports = writer(options).write (target, endpoint, endpoint.firstSuccessResponse)
152152

153153
// then:
154154
target.toString () shouldBe
@@ -186,7 +186,7 @@ class MethodWriterAnnotationSpec: StringSpec ({
186186
}
187187

188188
// when:
189-
writer(options).write (target, endpoint, endpoint.endpointResponses.first ())
189+
writer(options).write (target, endpoint, endpoint.firstSuccessResponse)
190190

191191
// then:
192192
target.toString () shouldBe
@@ -219,7 +219,7 @@ class MethodWriterAnnotationSpec: StringSpec ({
219219
}
220220

221221
// when:
222-
writer(options).write (target, endpoint, endpoint.endpointResponses.first ())
222+
writer(options).write (target, endpoint, endpoint.firstSuccessResponse)
223223

224224
// then:
225225
target.toString () shouldBe
@@ -259,7 +259,7 @@ class MethodWriterAnnotationSpec: StringSpec ({
259259
}
260260

261261
// when:
262-
writer(options).write (target, endpoint, endpoint.endpointResponses.first ())
262+
writer(options).write (target, endpoint, endpoint.firstSuccessResponse)
263263

264264
// then:
265265
target.toString () shouldBe
@@ -299,7 +299,7 @@ class MethodWriterAnnotationSpec: StringSpec ({
299299
}
300300
}
301301

302-
writer(options).write (target, endpoint, endpoint.endpointResponses.first ())
302+
writer(options).write (target, endpoint, endpoint.firstSuccessResponse)
303303

304304
target.toString () shouldBe
305305
"""
@@ -324,7 +324,7 @@ class MethodWriterAnnotationSpec: StringSpec ({
324324
}
325325

326326
// when:
327-
val imports = writer(options).write (target, endpoint, endpoint.endpointResponses.first ())
327+
val imports = writer(options).write (target, endpoint, endpoint.firstSuccessResponse)
328328

329329
// then:
330330
target.toString () shouldBe

‎openapi-processor-core/src/test/kotlin/io/openapiprocessor/core/writer/java/MethodWriterResponseStyleSpec.kt‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class MethodWriterResponseStyleSpec: FreeSpec() {
6262
}
6363

6464
// when:
65-
val imports = writer(options).write(target, endpoint, endpoint.endpointResponses.first())
65+
val imports = writer(options).write(target, endpoint, endpoint.firstSuccessResponse)
6666

6767
// then:
6868
target.toString() shouldBe
@@ -102,7 +102,7 @@ class MethodWriterResponseStyleSpec: FreeSpec() {
102102
}
103103

104104
// when:
105-
val imports = writer(options).write (target, endpoint, endpoint.endpointResponses.first ())
105+
val imports = writer(options).write (target, endpoint, endpoint.firstSuccessResponse)
106106

107107
// then:
108108
target.toString() shouldBe
@@ -147,7 +147,7 @@ class MethodWriterResponseStyleSpec: FreeSpec() {
147147
}
148148

149149
// when:
150-
val imports = writer(options).write(target, endpoint, endpoint.endpointResponses.first())
150+
val imports = writer(options).write(target, endpoint, endpoint.firstSuccessResponse)
151151

152152
// then:
153153
target.toString() shouldBe
@@ -180,7 +180,7 @@ class MethodWriterResponseStyleSpec: FreeSpec() {
180180
}
181181

182182
// when:
183-
val imports = writer().write(target, endpoint, endpoint.endpointResponses.first())
183+
val imports = writer().write(target, endpoint, endpoint.firstSuccessResponse)
184184

185185
// then:
186186
target.toString() shouldBe
@@ -219,7 +219,7 @@ class MethodWriterResponseStyleSpec: FreeSpec() {
219219
}
220220

221221
// when:
222-
val imports = writer().write(target, endpoint, endpoint.endpointResponses.first())
222+
val imports = writer().write(target, endpoint, endpoint.firstSuccessResponse)
223223

224224
// then:
225225
target.toString() shouldBe

0 commit comments

Comments
 (0)