com.ancientlightstudios.quarkus.kotlin.openapi.refactoring.ReplaceSimpleAllOfRefactoring.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-kotlin-openapi-maven-plugin Show documentation
Show all versions of quarkus-kotlin-openapi-maven-plugin Show documentation
A Maven plugin to use the OpenAPI generator.
package com.ancientlightstudios.quarkus.kotlin.openapi.refactoring
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformable.components.AllOfComponent.Companion.allOfComponent
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformable.components.SomeOfComponent
class ReplaceSimpleAllOfRefactoring : SpecRefactoring {
override fun RefactoringContext.perform() {
do {
val schemas = spec.schemas.filter { owner ->
val allOf = owner.allOfComponent() ?: return@filter false
// none allOf-item must contain other *of components
allOf.schemas.all { it.schema.components.filterIsInstance().isEmpty() }
}
if (schemas.isEmpty()) {
return
}
schemas.forEach { owner ->
val allOf = owner.allOfComponent() ?: return@forEach
allOf.schemas.forEach { donator ->
owner.components += donator.schema.components
}
owner.components -= allOf
}
} while (true)
}
}