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

com.ancientlightstudios.quarkus.kotlin.openapi.verify.EnumVerifier.kt Maven / Gradle / Ivy

There is a newer version: 0.4.14
Show newest version
package com.ancientlightstudios.quarkus.kotlin.openapi.verify

import com.ancientlightstudios.quarkus.kotlin.openapi.models.openapi.ApiSpec
import com.ancientlightstudios.quarkus.kotlin.openapi.models.openapi.schema.Schema
import com.ancientlightstudios.quarkus.kotlin.openapi.models.openapi.schema.validation.EnumValidation
import com.ancientlightstudios.quarkus.kotlin.openapi.utils.SpecIssue

class EnumVerifier : Verifier {

    override fun verify(apiSpec: ApiSpec) {
        val enumSchemas = apiSpec.getAllSchemas()
            .filterIsInstance()
            .filter { it.defaultValue != null }
            .filter { it.validations.any { it is EnumValidation } }
            .associateWith { it.validations.filterIsInstance().first() }

        enumSchemas.forEach { (schema, validation) ->
            if (!validation.values.contains(schema.defaultValue)) {
                SpecIssue("Default value for schema ${schema.originPath} is not a valid enum value.")
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy