-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #536 from znsio/openapi_file_upload
openapi file upload support
- Loading branch information
Showing
6 changed files
with
383 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
core/src/main/kotlin/in/specmatic/core/pattern/BinaryPattern.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package `in`.specmatic.core.pattern | ||
|
||
import `in`.specmatic.core.Resolver | ||
import `in`.specmatic.core.Result | ||
import `in`.specmatic.core.mismatchResult | ||
import `in`.specmatic.core.value.BinaryValue | ||
import `in`.specmatic.core.value.JSONArrayValue | ||
import `in`.specmatic.core.value.StringValue | ||
import `in`.specmatic.core.value.Value | ||
import org.apache.commons.lang3.RandomUtils | ||
|
||
data class BinaryPattern( | ||
override val typeAlias: String? = null, | ||
) : Pattern, ScalarType { | ||
|
||
override fun matches(sampleData: Value?, resolver: Resolver): Result { | ||
return when (sampleData) { | ||
is StringValue -> return Result.Success() | ||
else -> mismatchResult("string", sampleData, resolver.mismatchMessages) | ||
} | ||
} | ||
|
||
override fun encompasses( | ||
otherPattern: Pattern, | ||
thisResolver: Resolver, | ||
otherResolver: Resolver, | ||
typeStack: TypeStack | ||
): Result { | ||
return encompasses(this, otherPattern, thisResolver, otherResolver, typeStack) | ||
} | ||
|
||
override fun listOf(valueList: List<Value>, resolver: Resolver): Value { | ||
return JSONArrayValue(valueList) | ||
} | ||
|
||
override fun generate(resolver: Resolver): Value = BinaryValue(RandomUtils.nextBytes(20)) | ||
|
||
override fun newBasedOn(row: Row, resolver: Resolver): List<Pattern> = listOf(this) | ||
override fun newBasedOn(resolver: Resolver): List<Pattern> = listOf(this) | ||
override fun negativeBasedOn(row: Row, resolver: Resolver): List<Pattern> { | ||
return listOf(NullPattern, NumberPattern(), BooleanPattern) | ||
} | ||
|
||
override fun parse(value: String, resolver: Resolver): Value = StringValue(value) | ||
override val typeName: String = "string" | ||
|
||
override val pattern: Any = "(string)" | ||
override fun toString(): String = pattern.toString() | ||
} |
61 changes: 61 additions & 0 deletions
61
core/src/main/kotlin/in/specmatic/core/value/BinaryValue.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package `in`.specmatic.core.value | ||
|
||
import `in`.specmatic.core.ExampleDeclarations | ||
import `in`.specmatic.core.Result | ||
import `in`.specmatic.core.pattern.ExactValuePattern | ||
import `in`.specmatic.core.pattern.Pattern | ||
import `in`.specmatic.core.pattern.StringPattern | ||
import io.ktor.http.* | ||
import io.ktor.util.* | ||
import org.w3c.dom.Document | ||
import org.w3c.dom.Node | ||
|
||
data class BinaryValue(val byteArray: ByteArray = ByteArray(0)) : Value, ScalarValue, XMLValue { | ||
override val httpContentType = "application/octet-stream" | ||
|
||
override fun valueErrorSnippet(): String = displayableValue() | ||
|
||
@OptIn(InternalAPI::class) | ||
override fun displayableValue(): String = toStringLiteral().quote() | ||
override fun toStringLiteral() = byteArray.toString() | ||
override fun displayableType(): String = "binary" | ||
override fun exactMatchElseType(): Pattern = ExactValuePattern(this) | ||
|
||
override fun build(document: Document): Node = document.createTextNode(byteArray.toString()) | ||
|
||
override fun matchFailure(): Result.Failure = | ||
Result.Failure("Unexpected child value found: $byteArray") | ||
|
||
override fun addSchema(schema: XMLNode): XMLValue = this | ||
|
||
override fun listOf(valueList: List<Value>): Value { | ||
return JSONArrayValue(valueList) | ||
} | ||
|
||
override fun type(): Pattern = StringPattern() | ||
|
||
override fun typeDeclarationWithKey( | ||
key: String, | ||
types: Map<String, Pattern>, | ||
exampleDeclarations: ExampleDeclarations | ||
): Pair<TypeDeclaration, ExampleDeclarations> = | ||
primitiveTypeDeclarationWithKey(key, types, exampleDeclarations, displayableType(), byteArray.toString()) | ||
|
||
override fun typeDeclarationWithoutKey( | ||
exampleKey: String, | ||
types: Map<String, Pattern>, | ||
exampleDeclarations: ExampleDeclarations | ||
): Pair<TypeDeclaration, ExampleDeclarations> = | ||
primitiveTypeDeclarationWithoutKey( | ||
exampleKey, | ||
types, | ||
exampleDeclarations, | ||
displayableType(), | ||
byteArray.toString() | ||
) | ||
|
||
override val nativeValue: ByteArray | ||
get() = byteArray | ||
|
||
override fun toString() = byteArray.toString() | ||
} |
Oops, something went wrong.