Skip to content

Commit 9bf6d58

Browse files
committed
pre-calculate responses (#247)
1 parent cf16f7a commit 9bf6d58

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

  • openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/converter

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ import io.openapiprocessor.core.parser.HttpMethod
1717
import io.openapiprocessor.core.parser.NullSchema
1818
import io.openapiprocessor.core.parser.RequestBody
1919
import io.openapiprocessor.core.parser.Response
20+
import io.openapiprocessor.core.processor.mapping.v2.ResultStyle
2021
import io.openapiprocessor.core.writer.Identifier
2122
import org.slf4j.Logger
2223
import org.slf4j.LoggerFactory
24+
import kotlin.collections.mutableMapOf
2325
import io.openapiprocessor.core.model.RequestBody as ModelRequestBody
2426
import io.openapiprocessor.core.model.Response as ModelResponse
2527
import io.openapiprocessor.core.model.parameters.Parameter as ModelParameter
@@ -218,7 +220,13 @@ class ApiConverter(
218220
private fun collectResponses(operation: Operation, ctx: ConverterContext): Map<String, List<ModelResponse>> {
219221
val responses: MutableMap<String, List<ModelResponse>> = mutableMapOf()
220222

221-
operation.getResponses().forEach { (httpStatus, httpResponse) ->
223+
val opResponses = operation.getResponses()
224+
225+
val resultStyle = getResultStyle(ctx.path, operation.getMethod())
226+
val responseCollector = ContentTypeResponseCollector(opResponses, resultStyle)
227+
val interfaceCollector = ContentTypeInterfaceCollector(ctx.path, operation.getMethod(), responseCollector)
228+
229+
opResponses.forEach { (httpStatus, httpResponse) ->
222230
val results = createResponses(
223231
operation,
224232
httpStatus,
@@ -386,6 +394,10 @@ class ApiConverter(
386394
return mappingFinder.isEndpointExcluded(MappingFinderQuery(path, method))
387395
}
388396

397+
private fun getResultStyle(path: String, method: HttpMethod): ResultStyle {
398+
return mappingFinder.findResultStyleMapping(MappingFinderQuery(path, method))
399+
}
400+
389401
private fun getInterfaceName(op: Operation, excluded: Boolean): String {
390402
var targetInterfaceName = INTERFACE_DEFAULT_NAME
391403

0 commit comments

Comments
 (0)