@@ -20,6 +20,7 @@ import io.openapiprocessor.core.parser.HttpMethod
20
20
import io.openapiprocessor.core.parser.RequestBody
21
21
import io.openapiprocessor.core.parser.Response
22
22
import io.openapiprocessor.core.processor.mapping.v2.ResultStyle
23
+ import io.openapiprocessor.core.support.capitalizeFirstChar
23
24
import io.openapiprocessor.core.writer.Identifier
24
25
import org.slf4j.Logger
25
26
import org.slf4j.LoggerFactory
@@ -219,10 +220,7 @@ class ApiConverter(
219
220
220
221
private fun collectResponses (responses : Map <HttpStatus , Response >, ctx : ApiConverterContext ): Map <String , List <ModelResponse >> {
221
222
val resultResponses: MutableMap <String , List <ModelResponse >> = mutableMapOf ()
222
-
223
- val resultStyle = getResultStyle(ctx.path, ctx.method)
224
- val responseCollector = ContentTypeResponseCollector (responses, resultStyle)
225
- val interfaceCollector = ContentTypeInterfaceCollector (ctx.path, ctx.method, responseCollector)
223
+ val contentTypeInterfaces = collectContentTypeInterfaces(responses, ctx)
226
224
227
225
responses.forEach { (httpStatus, httpResponse) ->
228
226
val results = createResponses(
@@ -236,6 +234,38 @@ class ApiConverter(
236
234
return resultResponses
237
235
}
238
236
237
+ private fun collectContentTypeInterfaces (responses : Map <HttpStatus , Response >, ctx : ApiConverterContext )
238
+ : Map <ContentType , ContentTypeInterface > {
239
+ val resultStyle = getResultStyle(ctx.path, ctx.method)
240
+ val responseCollector = ContentTypeResponseCollector (responses, resultStyle)
241
+
242
+ // to check if a response marker interface is wanted it is necessary to know if the responses have the same
243
+ // result data type. In case they have the same data type we do not need the marker interface.
244
+ //
245
+ // Unfortunately we have to calculate the result data types to achieve this because it is currently not possible
246
+ // to detect this from the parsed OpenAPI.
247
+
248
+ val checkResponses: MutableMap <String , List <ModelResponse >> = mutableMapOf ()
249
+
250
+ val checkDataTypes = ctx.dataTypes.copy()
251
+ responses.forEach { (httpStatus, httpResponse) ->
252
+ val results = createResponses(
253
+ httpStatus,
254
+ httpResponse,
255
+ ctx.with (checkDataTypes)
256
+ )
257
+
258
+ checkResponses[httpStatus] = results
259
+ }
260
+
261
+ val interfaceCollector = ContentTypeInterfaceCollector (ctx.path, ctx.method)
262
+ val contentTypeInterfaces = interfaceCollector.collectContentTypeInterfaces(
263
+ responseCollector.contentTypeResponses,
264
+ checkResponses
265
+ )
266
+ return contentTypeInterfaces
267
+ }
268
+
239
269
private fun createParameter (parameter : Parameter , ctx : ApiConverterContext ): ModelParameter {
240
270
val info = SchemaInfo (
241
271
SchemaInfo .Endpoint (ctx.path, ctx.method),
@@ -409,4 +439,12 @@ class ApiConverter(
409
439
return targetInterfaceName
410
440
}
411
441
442
+ private fun getResponseMarkerInterfaceName (path : String , method : HttpMethod , contentType : String ): String {
443
+ return listOf (
444
+ method.method.capitalizeFirstChar(),
445
+ identifier.toClass(path),
446
+ identifier.toClass(contentType),
447
+ " Response"
448
+ ).joinToString(" " )
449
+ }
412
450
}
0 commit comments