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

com.ancientlightstudios.quarkus.kotlin.openapi.refactoring.SwapSchemaRefactoring.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.inspection.inspect
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformable.SchemaUsage
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformable.TransformableSchema
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformable.components.ArrayItemsComponent
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformable.components.BaseSchemaComponent
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformable.components.ObjectComponent
import com.ancientlightstudios.quarkus.kotlin.openapi.models.transformable.components.SomeOfComponent

class SwapSchemaRefactoring(
    private val current: TransformableSchema,
    private val replacement: TransformableSchema
) : SpecRefactoring {

    override fun RefactoringContext.perform() {
        // helper function to avoid code duplication
        val checkAndReplace: (SchemaUsage) -> Unit = { schemaUsage ->
            if (schemaUsage.schema == current) {
                schemaUsage.schema = replacement
            }
        }

        spec.inspect {
            bundles {
                requests {
                    parameters { checkAndReplace(parameter.content) }

                    body { checkAndReplace(body.content) }

                    responses {
                        headers { checkAndReplace(header.content) }

                        body { checkAndReplace(body.content) }
                    }
                }
            }

            schemas {
                components { checkAndReplace(component) }
                components { checkAndReplace(component) }
                components { component.properties.forEach { checkAndReplace(it) } }
                components { component.schemas.forEach { checkAndReplace(it) } }
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy