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

com.ancientlightstudios.quarkus.kotlin.openapi.refactoring.ReplaceSimpleAllOfRefactoring.kt Maven / Gradle / Ivy

There is a newer version: 0.4.14
Show newest version
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)
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy