Skip to content

Commit

Permalink
feat(DSL): Update min and max array like functions to also take a Dsl…
Browse files Browse the repository at this point in the history
…Part #1799
  • Loading branch information
rholshausen committed Jun 20, 2024
1 parent 527001f commit 029fcaf
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,18 @@ open class PactDslJsonBody : DslPart {
*/
@JvmOverloads
fun minArrayLike(name: String, size: Int, value: PactDslJsonRootValue, numberExamples: Int = 2): PactDslJsonBody {
return minArrayLike(name, size, value as DslPart, numberExamples)
}

/**
* Attribute that is an array of values with a minimum size that are not objects where each item must match
* the following example
* @param name field name
* @param size minimum size of the array
* @param value Value to use to match each item
* @param numberExamples number of examples to generate
*/
fun minArrayLike(name: String, size: Int, value: DslPart, numberExamples: Int): PactDslJsonBody {
require(numberExamples >= size) {
String.format("Number of example %d is less than the minimum size of %d",
numberExamples, size)
Expand Down Expand Up @@ -1534,6 +1546,18 @@ open class PactDslJsonBody : DslPart {
*/
@JvmOverloads
fun maxArrayLike(name: String, size: Int, value: PactDslJsonRootValue, numberExamples: Int = 1): PactDslJsonBody {
return maxArrayLike(name, size, value as DslPart, numberExamples)
}

/**
* Attribute that is an array of values with a maximum size that are not objects where each item must match the
* following example
* @param name field name
* @param size maximum size of the array
* @param value Value to use to match each item
* @param numberExamples number of examples to generate
*/
fun maxArrayLike(name: String, size: Int, value: DslPart, numberExamples: Int): PactDslJsonBody {
require(numberExamples <= size) {
String.format("Number of example %d is more than the maximum size of %d",
numberExamples, size)
Expand Down Expand Up @@ -2074,6 +2098,25 @@ open class PactDslJsonBody : DslPart {
maxSize: Int,
value: PactDslJsonRootValue,
numberExamples: Int
): PactDslJsonBody {
return minMaxArrayLike(name, minSize, maxSize, value as DslPart, numberExamples)
}

/**
* Attribute that is an array of values with a minimum and maximum size that are not objects where each item must
* match the following example
* @param name field name
* @param minSize minimum size
* @param maxSize maximum size
* @param value Value to use to match each item
* @param numberExamples number of examples to generate
*/
fun minMaxArrayLike(
name: String,
minSize: Int,
maxSize: Int,
value: DslPart,
numberExamples: Int
): PactDslJsonBody {
validateMinAndMaxAndExamples(minSize, maxSize, numberExamples)
val path = constructValidPath(name, rootPath)
Expand Down

0 comments on commit 029fcaf

Please sign in to comment.