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

application.MergeCommand.kt Maven / Gradle / Ivy

There is a newer version: 1.3.39
Show newest version
package application

import `in`.specmatic.core.Feature
import `in`.specmatic.core.log.logger
import io.swagger.v3.core.util.Yaml
import picocli.CommandLine
import java.io.File
import java.util.concurrent.Callable

@CommandLine.Command(name = "merge", description = ["Merge the specified contracts"], mixinStandardHelpOptions = true)
class MergeCommand: Callable {
    @CommandLine.Parameters
    var contractFiles: List = emptyList()

    @CommandLine.Option(names = ["--merged-contract"])
    var outputFile: File = File("new-contract.yaml")

    override fun call() {
        if(contractFiles.isEmpty()) {
            logger.log("No contracts were specified.")
            return
        }

        val contracts: List = contractFiles.map {
            try {
                parseContract(it.readText(), it.canonicalPath)
            } catch(e: Throwable) {
                println("Exception loading contract ${it.canonicalPath}")
                e.printStackTrace()
                return
            }
        }

        val mergedFeature = Feature(scenarios = contracts.flatMap { it.scenarios }, name = contracts.first().name)
        val openApi = mergedFeature.toOpenApi()

        logger.log("Writing merged contract file to ${outputFile.path}")
        outputFile.writeText(Yaml.pretty(openApi))
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy