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

application.SamplesCommand.kt Maven / Gradle / Ivy

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

import io.specmatic.core.*
import io.specmatic.core.log.*
import picocli.CommandLine.*
import io.specmatic.stub.HttpStub
import java.io.File
import java.util.concurrent.Callable

@Command(name = "samples",
        mixinStandardHelpOptions = true,
        description = ["Generate samples of the API requests and responses for all scenarios"])
class SamplesCommand : Callable {
    @Parameters(index = "0", description = ["API specification file path"])
    lateinit var contractFile: File

    override fun call() {
        logger = NonVerbose(CompositePrinter(listOf(JSONConsoleLogPrinter)))

        logException {
            if(!contractFile.exists())
                throw Exception("Could not find file ${contractFile.path}")

            try {
                val feature = parseContractFileToFeature(contractFile)

                HttpStub(feature, emptyList(), "127.0.0.1", 56789).use { stub ->
                    feature.executeTests(stub.client)
                    Contract(feature).samples(stub)
                }
            } catch(e: StackOverflowError) {
                logger.log("Got a stack overflow error. You probably have a recursive data structure definition in your API specification.")
            }
        }
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy