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: 1.3.39
Show newest version
package application

import `in`.specmatic.core.*
import `in`.specmatic.core.log.*
import picocli.CommandLine.*
import `in`.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