How to use JsonSchema.Builder.decimal method of io.kotest.assertions.json.schema.JsonSchema class

Best Kotest code snippet using io.kotest.assertions.json.schema.JsonSchema.JsonSchema.Builder.decimal

builder.kt

Source:builder.kt Github

copy

Full Screen

1package io.kotest.assertions.json.schema2import io.kotest.common.ExperimentalKotest3import io.kotest.matchers.Matcher4import kotlinx.serialization.Contextual5import kotlinx.serialization.ExperimentalSerializationApi6import kotlinx.serialization.SerialName7import kotlinx.serialization.Serializable8@DslMarker9annotation class JsonSchemaMarker10@JsonSchemaMarker11@ExperimentalKotest12@Serializable(with = SchemaDeserializer::class)13sealed interface JsonSchemaElement {14 fun typeName(): String15}16internal interface ValueNode<T> {17 val matcher: Matcher<T>?18 get() = null19}20@ExperimentalKotest21data class JsonSchema(22 val root: JsonSchemaElement23) {24 /**25 * Provides a way to access pre-defined schemas in a conventional way (e.g. `type()`). Example:26 * ```kotlin27 * val addressSchema = jsonSchema {28 * obj {29 * withProperty("street") { string() }30 * withProperty("zipCode") { integer { beEven() } }31 * }32 * }33 *34 * val personSchema = jsonSchema {35 * obj {36 * withProperty("name") { string() }37 * withProperty("address") { addressSchema() }38 * }39 * }40 * ```41 */42 @ExperimentalKotest43 operator fun invoke() = root44 object Builder45 internal interface JsonNumber46 @Serializable47 data class JsonArray(val elementType: JsonSchemaElement) : JsonSchemaElement {48 override fun typeName() = "array"49 }50 class JsonObjectBuilder {51 var additionalProperties: Boolean = true52 var minProperties: Int = 053 var maxProperties: Int? = null54 var properties: MutableMap<String, JsonSchemaElement> = mutableMapOf()55 /**56 * https://json-schema.org/understanding-json-schema/reference/object.html#required-properties57 */58 var requiredProperties: MutableList<String> = mutableListOf()59 /**60 * By default properties are optional.61 * Using [required], you can specify that it must be included.62 */63 fun withProperty(64 name: String,65 required: Boolean = false,66 elementBuilder: JsonSchema.Builder.() -> JsonSchemaElement67 ) {68 properties[name] = JsonSchema.Builder.elementBuilder()69 if (required) requiredProperties.add(name)70 }71 fun build() = JsonObject(72 additionalProperties = additionalProperties,73 minProperties = minProperties,74 maxProperties = maxProperties,75 properties = properties,76 requiredProperties = requiredProperties.toTypedArray()77 )78 }79 @Serializable80 data class JsonObject(81 /**82 * Controls whether this node allows additional properties to be defined or not.83 * By default, additional properties are _allowed_84 *85 * https://json-schema.org/understanding-json-schema/reference/object.html#additional-properties86 */87 val additionalProperties: Boolean = true,88 val minProperties: Int = 0,89 val maxProperties: Int? = null,90 val properties: Map<String, JsonSchemaElement>,91 /**92 * https://json-schema.org/understanding-json-schema/reference/object.html#required-properties93 */94 val requiredProperties: Array<String> = emptyArray(),95 ) : JsonSchemaElement {96 operator fun get(name: String) = properties.get(name)97 override fun typeName() = "object"98 }99 data class JsonString(override val matcher: Matcher<String>? = null) : JsonSchemaElement, ValueNode<String> {100 override fun typeName() = "string"101 }102 data class JsonInteger(103 override val matcher: Matcher<Long>? = null104 ) : JsonSchemaElement, JsonNumber, ValueNode<Long> {105 override fun typeName() = "integer"106 }107 data class JsonDecimal(108 override val matcher: Matcher<Double>? = null109 ) : JsonSchemaElement, JsonNumber, ValueNode<Double> {110 override fun typeName() = "number"111 }112 @Serializable113 object JsonBoolean : JsonSchemaElement, ValueNode<Boolean> {114 override fun typeName() = "boolean"115 }116 @Serializable117 object Null : JsonSchemaElement {118 override fun typeName() = "null"119 }120}121/**122 * Creates a [JsonSchema.JsonString] node, which is a leaf node that will hold a [String] value.123 * Optionally, you can provide a [matcherBuilder] that constructs a [Matcher] which the node will be tested with.124 */125@ExperimentalKotest126fun JsonSchema.Builder.string(matcherBuilder: () -> Matcher<String>? = { null }) =127 JsonSchema.JsonString(matcherBuilder())128/**129 * Creates a [JsonSchema.JsonInteger] node, which is a leaf node that will hold a [Long] value.130 * Optionally, you can provide a [matcherBuilder] that constructs a [Matcher] which the node will be tested with.131 */132@ExperimentalKotest133fun JsonSchema.Builder.integer(matcherBuilder: () -> Matcher<Long>? = { null }) =134 JsonSchema.JsonInteger(matcherBuilder())135/**136 * Creates a [JsonSchema.JsonDecimal] node, which is a leaf node that will hold a [Double] value.137 * Optionally, you can provide a [matcherBuilder] that constructs a [Matcher] which the node will be tested with.138 */139@ExperimentalKotest140fun JsonSchema.Builder.number(matcherBuilder: () -> Matcher<Double>? = { null }) =141 JsonSchema.JsonDecimal(matcherBuilder())142/**143 * Alias for [number]144 *145 * Creates a [JsonSchema.JsonDecimal] node, which is a leaf node that will hold a [Double] value.146 * Optionally, you can provide a [matcherBuilder] that constructs a [Matcher] which the node will be tested with.147 */148@ExperimentalKotest149fun JsonSchema.Builder.decimal(matcherBuilder: () -> Matcher<Double>? = { null }) =150 JsonSchema.JsonDecimal(matcherBuilder())151/**152 * Creates a [JsonSchema.JsonBoolean] node, which is a leaf node that will hold a [Boolean] value.153 * It supports no further configuration. The actual value must always be either true or false.154 */155@ExperimentalKotest156fun JsonSchema.Builder.boolean() =157 JsonSchema.JsonBoolean158/**159 * Creates a [JsonSchema.Null] node, which is a leaf node that must always be null, if present.160 */161@ExperimentalKotest162fun JsonSchema.Builder.`null`() =163 JsonSchema.Null164/**165 * Creates a [JsonSchema.JsonObject] node. Expand on the object configuration using the [dsl] which lets you specify166 * properties using [withProperty]167 *168 * Example:169 * ```kotlin170 * val personSchema = jsonSchema {171 * obj {172 * withProperty("name") { string() }173 * withProperty("age") { number() }174 * }175 * }176 * ```177 */178@ExperimentalKotest179fun JsonSchema.Builder.obj(dsl: JsonSchema.JsonObjectBuilder.() -> Unit = {}) =180 JsonSchema.JsonObjectBuilder().apply(dsl).build()181/**182 * Defines a [JsonSchema.JsonArray] node where the elements are of the type provided by [typeBuilder].183 */184@ExperimentalKotest185fun JsonSchema.Builder.array(typeBuilder: () -> JsonSchemaElement) =186 JsonSchema.JsonArray(typeBuilder())187@ExperimentalKotest188fun jsonSchema(189 rootBuilder: JsonSchema.Builder.() -> JsonSchemaElement190): JsonSchema =191 JsonSchema(192 JsonSchema.Builder.rootBuilder()193 )...

Full Screen

Full Screen

JsonSchema.Builder.decimal

Using AI Code Generation

copy

Full Screen

1val jsonSchema = JsonSchema.Builder.decimal()2val jsonSchema = JsonSchema.Builder.number()3val jsonSchema = JsonSchema.Builder.integer()4val jsonSchema = JsonSchema.Builder.`null`()5val jsonSchema = JsonSchema.Builder.`boolean`()6val jsonSchema = JsonSchema.Builder.string()7val jsonSchema = JsonSchema.Builder.array()8val jsonSchema = JsonSchema.Builder.`object`()9val jsonSchema = JsonSchema.Builder.enum()10val jsonSchema = JsonSchema.Builder.const()11val jsonSchema = JsonSchema.Builder.ref()12val jsonSchema = JsonSchema.Builder.allOf()13val jsonSchema = JsonSchema.Builder.anyOf()14val jsonSchema = JsonSchema.Builder.oneOf()15val jsonSchema = JsonSchema.Builder.not()16val jsonSchema = JsonSchema.Builder.properties()

Full Screen

Full Screen

JsonSchema.Builder.decimal

Using AI Code Generation

copy

Full Screen

1import io.kotest.assertions.json.schema.JsonSchema2val schema = JsonSchema.decimal()3import io.kotest.assertions.json.schema.JsonSchema4val schema = JsonSchema.integer()5import io.kotest.assertions.json.schema.JsonSchema6val schema = JsonSchema.`null`()7import io.kotest.assertions.json.schema.JsonSchema8val schema = JsonSchema.number()9import io.kotest.assertions.json.schema.JsonSchema10val schema = JsonSchema.object()11import io.kotest.assertions.json.schema.JsonSchema12val schema = JsonSchema.string()13import io.kotest.assertions.json.schema.JsonSchema14val schema = JsonSchema.`object`().withAdditionalProperties(JsonSchema.`null`())15import io.kotest.assertions.json.schema.JsonSchema16val schema = JsonSchema.`object`().withAllOf(listOf(JsonSchema.`object`()))17import io.kotest.assertions.json.schema.JsonSchema18val schema = JsonSchema.`object`().withAnyOf(listOf(JsonSchema.`object`()))19import io.kotest.assertions.json.schema.JsonSchema20val schema = JsonSchema.`object`().withConst("value")21import io.kotest.assertions.json.schema.JsonSchema22val schema = JsonSchema.`object`().withContains(JsonSchema.`null`())

Full Screen

Full Screen

JsonSchema.Builder.decimal

Using AI Code Generation

copy

Full Screen

1import io.kotest.assertions.json.schema.JsonSchema2import io.kotest.assertions.json.schema.decimal3val schema = JsonSchema.decimal()4import io.kotest.assertions.json.schema.JsonSchema5import io.kotest.assertions.json.schema.double6val schema = JsonSchema.double()7import io.kotest.assertions.json.schema.JsonSchema8import io.kotest.assertions.json.schema.enum9val schema = JsonSchema.enum()10import io.kotest.assertions.json.schema.JsonSchema11import io.kotest.assertions.json.schema.integer12val schema = JsonSchema.integer()13import io.kotest.assertions.json.schema.JsonSchema14import io.kotest.assertions.json.schema.string15val schema = JsonSchema.string()16import io.kotest.assertions.json.schema.JsonSchema17import io.kotest.assertions.json.schema.array18val schema = JsonSchema.array()19import io.kotest.assertions.json.schema.JsonSchema20import io.kotest.assertions.json.schema.`object`21val schema = JsonSchema.`object`()22import io.kotest.assertions.json.schema.JsonSchema23import io.kotest.assertions.json.schema.properties24val schema = JsonSchema.properties()25import io.kotest.assertions.json.schema.JsonSchema26import io.kotest.assertions.json.schema.required27val schema = JsonSchema.required()28import io.kotest.assertions.json.schema.JsonSchema29import io.kotest.assertions.json.schema.null

Full Screen

Full Screen

JsonSchema.Builder.decimal

Using AI Code Generation

copy

Full Screen

1import io.kotest.assertions.json.schema.JsonSchema2fun testDecimal() {3 val jsonSchema = JsonSchema.decimal()4 jsonSchema.validate(json)5}6import io.kotest.assertions.json.schema.JsonSchema7fun testEnum() {8 val jsonSchema = JsonSchema.enum("a", "b", "c")9 jsonSchema.validate(json)10}11import io.kotest.assertions.json.schema.JsonSchema12fun testInteger() {13 val jsonSchema = JsonSchema.integer()14 jsonSchema.validate(json)15}16import io.kotest.assertions.json.schema.JsonSchema17fun testNullable() {18 val jsonSchema = JsonSchema.nullable()19 jsonSchema.validate(json)20}21import io.kotest.assertions.json.schema.JsonSchema22fun testNumber() {23 val jsonSchema = JsonSchema.number()24 jsonSchema.validate(json)25}26import io.kotest.assertions.json.schema.JsonSchema27fun testString() {28 val jsonSchema = JsonSchema.string()29 jsonSchema.validate(json)30}31import io.kotest.assertions.json.schema.JsonSchema32fun testStringEnum() {33 val jsonSchema = JsonSchema.stringEnum("a", "b", "c")34 jsonSchema.validate(json)35}36import io.kotest.assertions.json.schema.JsonSchema37fun testStringPattern() {

Full Screen

Full Screen

JsonSchema.Builder.decimal

Using AI Code Generation

copy

Full Screen

1val result = JsonSchema.Builder.decimal()2result should haveType(JsonSchema.Type.Number)3result should haveFormat(JsonSchema.Format.Decimal)4result should haveMinimum(BigDecimal("1.1"))5result should haveExclusiveMinimum(true)6result should haveMaximum(BigDecimal("2.2"))7result should haveExclusiveMaximum(true)8result should haveMultipleOf(BigDecimal("3.3"))9val result = JsonSchema.Builder.decimal()10result should haveType(JsonSchema.Type.Number)11result should haveFormat(JsonSchema.Format.Decimal)12result should haveMinimum(BigDecimal("1.1"))13result should haveExclusiveMinimum(true)14result should haveMaximum(BigDecimal("2.2"))15result should haveExclusiveMaximum(true)16result should haveMultipleOf(BigDecimal("3.3"))17val result = JsonSchema.Builder.decimal()18result should haveType(JsonSchema.Type.Number)19result should haveFormat(JsonSchema.Format.Decimal)20result should haveMinimum(BigDecimal("1.1"))21result should haveExclusiveMinimum(true)22result should haveMaximum(BigDecimal("2.2"))23result should haveExclusiveMaximum(true)24result should haveMultipleOf(BigDecimal("3.3"))25val result = JsonSchema.Builder.decimal()26result should haveType(JsonSchema.Type.Number)27result should haveFormat(JsonSchema.Format.Decimal)28result should haveMinimum(BigDecimal("1.1"))29result should haveExclusiveMinimum(true)30result should haveMaximum(BigDecimal("2.2"))31result should haveExclusiveMaximum(true)32result should haveMultipleOf(BigDecimal("3.3"))33val result = JsonSchema.Builder.decimal()34result should haveType(JsonSchema.Type.Number)35result should haveFormat(JsonSchema.Format.Decimal)36result should haveMinimum(BigDecimal("1.1"))37result should haveExclusiveMinimum(true)38result should haveMaximum(BigDecimal("2.2"))39result should haveExclusiveMaximum(true)40result should haveMultipleOf(BigDecimal("3.3"))41val result = JsonSchema.Builder.decimal()42result should haveType(JsonSchema.Type.Number)43result should haveFormat(Json

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful