application.MergeCommand.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of specmatic-executable Show documentation
Show all versions of specmatic-executable Show documentation
Command-line standalone executable jar for Specmatic
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