All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.codecentric.hikaku.converters.openapi.extractors.ConsumesExtractor.kt Maven / Gradle / Ivy

Go to download

A library that tests if the implementation of a REST-API meets its specification. This module contains a converter for OpenAPI specifications.

There is a newer version: 3.3.0
Show newest version
package de.codecentric.hikaku.converters.openapi.extractors

import de.codecentric.hikaku.converters.openapi.extensions.referencedSchema
import io.swagger.v3.oas.models.OpenAPI
import io.swagger.v3.oas.models.Operation

internal class ConsumesExtractor(private val openApi: OpenAPI) {

    operator fun invoke(operation: Operation?): Set {
        return operation?.requestBody
                ?.content
                ?.keys
                .orEmpty()
                .union(extractConsumesFromComponents(operation))
                .toSet()
    }

    private fun extractConsumesFromComponents(operation: Operation?): Set {
        return operation?.requestBody
                ?.referencedSchema
                ?.let {
                    Regex("#/components/requestBodies/(?.+)")
                            .find(it)
                            ?.groups
                            ?.get("key")
                            ?.value
                }
                ?.let {
                    openApi.components
                            .requestBodies[it]
                            ?.content
                            ?.keys
                }
                .orEmpty()
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy