in.specmatic.core.SpecmaticConfig.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of specmatic-core Show documentation
Show all versions of specmatic-core Show documentation
Turn your contracts into executable specifications. Contract Driven Development - Collaboratively Design & Independently Deploy MicroServices & MicroFrontends.
Deprecation Notice for group ID "in.specmatic"
******************************************************************************************************
Updates for "specmatic-core" will no longer be available under the deprecated group ID "in.specmatic".
Please update your dependencies to use the new group ID "io.specmatic".
******************************************************************************************************
package `in`.specmatic.core
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonSubTypes
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.annotation.JsonTypeName
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import `in`.specmatic.core.Configuration.Companion.globalConfigFileName
import `in`.specmatic.core.log.logger
import `in`.specmatic.core.pattern.ContractException
import java.io.File
const val APPLICATION_NAME = "Specmatic"
const val APPLICATION_NAME_LOWER_CASE = "specmatic"
const val DEFAULT_TIMEOUT_IN_SECONDS = "60"
const val CONTRACT_EXTENSION = "spec"
const val YAML = "yaml"
const val WSDL = "wsdl"
const val YML = "yml"
const val JSON = "json"
val OPENAPI_FILE_EXTENSIONS = listOf(YAML, YML, JSON)
val CONTRACT_EXTENSIONS = listOf(CONTRACT_EXTENSION, WSDL) + OPENAPI_FILE_EXTENSIONS
const val DATA_DIR_SUFFIX = "_data"
const val TEST_DIR_SUFFIX = "_tests"
const val EXAMPLES_DIR_SUFFIX = "_examples"
const val SPECMATIC_GITHUB_ISSUES = "https://github.com/znsio/specmatic/issues"
const val DEFAULT_WORKING_DIRECTORY = ".$APPLICATION_NAME_LOWER_CASE"
class WorkingDirectory(private val filePath: File) {
constructor(path: String = DEFAULT_WORKING_DIRECTORY): this(File(path))
val path: String
get() {
return filePath.path
}
}
fun invalidContractExtensionMessage(filename: String): String {
return "The file $filename does not seem like a contract file. Valid extensions for contract files are ${CONTRACT_EXTENSIONS.joinToString(", ")}"
}
fun String.isContractFile(): Boolean {
return File(this).extension in CONTRACT_EXTENSIONS
}
fun String.loadContract(): Feature {
if(!this.isContractFile())
throw ContractException(invalidContractExtensionMessage(this))
return parseContractFileToFeature(File(this))
}
data class Auth(
@JsonProperty("bearer-file") val bearerFile: String = "bearer.txt",
@JsonProperty("bearer-environment-variable") val bearerEnvironmentVariable: String? = null
)
enum class PipelineProvider { azure }
data class Pipeline(
val provider: PipelineProvider = PipelineProvider.azure,
val organization: String = "",
val project: String = "",
val definitionId: Int = 0
)
data class Environment(
val baseurls: Map? = null,
val variables: Map? = null
)
enum class SourceProvider { git, filesystem, web }
data class Source(
val provider: SourceProvider = SourceProvider.filesystem,
val repository: String? = null,
val branch: String? = null,
val test: List? = null,
val stub: List? = null,
val directory: String? = null,
)
data class SpecmaticConfig(
val sources: List