Skip to content

Commit ea4a21e

Browse files
committed
better name & home (#247)
1 parent 93d0506 commit ea4a21e

2 files changed

Lines changed: 23 additions & 27 deletions

File tree

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/model/EndpointResponseCollector.kt renamed to openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/converter/ContentTypeResponseCollector.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* PDX-License-Identifier: Apache-2.0
44
*/
55

6-
package io.openapiprocessor.core.model
6+
package io.openapiprocessor.core.converter
77

88
import io.openapiprocessor.core.parser.ContentType
99
import io.openapiprocessor.core.parser.HttpStatus
@@ -31,14 +31,10 @@ private const val EMPTY: String = ""
3131
* success 2x void
3232
* errors 4x
3333
*/
34-
class EndpointResponseCollector(val responses: Map<HttpStatus, Response>, private val resultStyle: ResultStyle) {
35-
val contentTypeResponses: Map<ContentType, Map<HttpStatus, Response>>
34+
class ContentTypeResponseCollector(val responses: Map<HttpStatus, Response>, private val resultStyle: ResultStyle) {
35+
val contentTypeResponses: Map<ContentType, Map<HttpStatus, Response>> = collectResponses(responses)
3636

37-
init {
38-
contentTypeResponses = collect(responses)
39-
}
40-
41-
private fun collect(responses: Map<HttpStatus, Response>): Map<ContentType, Map<HttpStatus, Response>> {
37+
private fun collectResponses(responses: Map<HttpStatus, Response>): Map<ContentType, Map<HttpStatus, Response>> {
4238
val contentTypeResponses = mutableMapOf<ContentType, MutableMap<HttpStatus, Response>>()
4339

4440
responses.forEach { (httpStatus, response) ->
@@ -73,7 +69,6 @@ class EndpointResponseCollector(val responses: Map<HttpStatus, Response>, privat
7369
return contentTypeResponses
7470
}
7571

76-
7772
private fun isError(status: HttpStatus): Boolean {
7873
return status.startsWith("4")
7974
|| status.startsWith("5")

openapi-processor-core/src/test/kotlin/io/openapiprocessor/core/model/EndpointResponseCollectorSpec.kt renamed to openapi-processor-core/src/test/kotlin/io/openapiprocessor/core/converter/ContentTypeResponseCollectorSpec.kt

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
/*
2-
* Copyright 2025 https://github.com/openapi-processor/openapi-processor-base
3-
* PDX-License-Identifier: Apache-2.0
4-
*/
5-
6-
package io.openapiprocessor.core.model
1+
package io.openapiprocessor.core.converter
72

83
import io.kotest.core.spec.style.StringSpec
4+
import io.kotest.core.spec.style.scopes.StringSpecRootScope.invoke
95
import io.kotest.matchers.nulls.shouldBeNull
106
import io.kotest.matchers.nulls.shouldNotBeNull
117
import io.openapiprocessor.core.processor.mapping.v2.ResultStyle
128
import io.openapiprocessor.core.support.parseApi
139

14-
class EndpointResponseCollectorSpec: StringSpec({
10+
class ContentTypeResponseCollectorSpec: StringSpec({
1511

1612
"single empty success response" {
1713
val openApi = parseApi(
@@ -26,11 +22,12 @@ class EndpointResponseCollectorSpec: StringSpec({
2622
| responses:
2723
| '204':
2824
| description: empty
29-
""".trimMargin())
25+
""".trimMargin()
26+
)
3027

3128
val operation = openApi.getPaths()["/foo"]!!.getOperations().first()
3229

33-
val collector = EndpointResponseCollector(operation.getResponses(), ResultStyle.SUCCESS)
30+
val collector = ContentTypeResponseCollector(operation.getResponses(), ResultStyle.SUCCESS)
3431

3532
collector.contentTypeResponses[""]!!["204"].shouldNotBeNull()
3633
}
@@ -52,11 +49,12 @@ class EndpointResponseCollectorSpec: StringSpec({
5249
| application/json:
5350
| schema:
5451
| type: string
55-
""".trimMargin())
52+
""".trimMargin()
53+
)
5654

5755
val operation = openApi.getPaths()["/foo"]!!.getOperations().first()
5856

59-
val collector = EndpointResponseCollector(operation.getResponses(), ResultStyle.SUCCESS)
57+
val collector = ContentTypeResponseCollector(operation.getResponses(), ResultStyle.SUCCESS)
6058

6159
collector.contentTypeResponses["application/json"]!!["200"].shouldNotBeNull()
6260
}
@@ -87,11 +85,12 @@ class EndpointResponseCollectorSpec: StringSpec({
8785
| application/json:
8886
| schema:
8987
| type: string
90-
""".trimMargin())
88+
""".trimMargin()
89+
)
9190

9291
val operation = openApi.getPaths()["/foo"]!!.getOperations().first()
9392

94-
val collector = EndpointResponseCollector(operation.getResponses(), ResultStyle.SUCCESS)
93+
val collector = ContentTypeResponseCollector(operation.getResponses(), ResultStyle.SUCCESS)
9594

9695
collector.contentTypeResponses["application/json"]!!["200"].shouldNotBeNull()
9796
collector.contentTypeResponses["application/json"]!!["201"].shouldNotBeNull()
@@ -122,11 +121,12 @@ class EndpointResponseCollectorSpec: StringSpec({
122121
| schema:
123122
| type: string
124123
| format: two
125-
""".trimMargin())
124+
""".trimMargin()
125+
)
126126

127127
val operation = openApi.getPaths()["/foo"]!!.getOperations().first()
128128

129-
val collector = EndpointResponseCollector(operation.getResponses(), ResultStyle.SUCCESS)
129+
val collector = ContentTypeResponseCollector(operation.getResponses(), ResultStyle.SUCCESS)
130130

131131
collector.contentTypeResponses["application/json"]!!["200"].shouldNotBeNull()
132132
collector.contentTypeResponses["application/json"]!!["201"].shouldNotBeNull()
@@ -167,16 +167,17 @@ class EndpointResponseCollectorSpec: StringSpec({
167167
| type: string
168168
| format: error
169169
|
170-
""".trimMargin())
170+
""".trimMargin()
171+
)
171172

172173
val operation = openApi.getPaths()["/foo"]!!.getOperations().first()
173174

174-
val collectorA = EndpointResponseCollector(operation.getResponses(), ResultStyle.ALL)
175+
val collectorA = ContentTypeResponseCollector(operation.getResponses(), ResultStyle.ALL)
175176
collectorA.contentTypeResponses["application/json"]!!["200"].shouldNotBeNull()
176177
collectorA.contentTypeResponses["application/json"]!!["201"].shouldNotBeNull()
177178
collectorA.contentTypeResponses["application/json"]!!["400"].shouldNotBeNull()
178179

179-
val collectorS = EndpointResponseCollector(operation.getResponses(), ResultStyle.SUCCESS)
180+
val collectorS = ContentTypeResponseCollector(operation.getResponses(), ResultStyle.SUCCESS)
180181
collectorS.contentTypeResponses["application/json"]!!["200"].shouldNotBeNull()
181182
collectorS.contentTypeResponses["application/json"]!!["201"].shouldNotBeNull()
182183
collectorS.contentTypeResponses["application/json"]!!["400"].shouldBeNull()

0 commit comments

Comments
 (0)