Skip to content

Commit 282d9d6

Browse files
author
Oleg
committed
Rename factory method for JsonSchema as the new name makes more sense
1 parent 197730c commit 282d9d6

32 files changed

+101
-101
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import com.github.optimumcode.json.schema.ValidationError
1414
import kotlinx.serialization.json.JsonElement
1515

1616
val key = "\$" // to use $ in multiline string
17-
val schema = JsonSchema.fromDescription(
17+
val schema = JsonSchema.fromDefinition(
1818
"""
1919
{
2020
"${key}schema": "http://json-schema.org/draft-07/schema#",

src/commonMain/kotlin/com/github/optimumcode/json/schema/JsonSchema.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class JsonSchema internal constructor(
3434
* Loads JSON schema from the [schema] definition
3535
*/
3636
@JvmStatic
37-
public fun fromDescription(schema: String): JsonSchema {
37+
public fun fromDefinition(schema: String): JsonSchema {
3838
val schemaElement: JsonElement = Json.parseToJsonElement(schema)
3939
return SchemaLoader().load(schemaElement)
4040
}

src/commonTest/kotlin/com/github/optimumcode/json/schema/assertions/array/JsonSchemaContainsValidationTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import kotlinx.serialization.json.buildJsonObject
1818
@Suppress("unused")
1919
class JsonSchemaContainsValidationTest : FunSpec() {
2020
init {
21-
val schema = JsonSchema.fromDescription(
21+
val schema = JsonSchema.fromDefinition(
2222
"""
2323
{
2424
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -95,7 +95,7 @@ class JsonSchemaContainsValidationTest : FunSpec() {
9595
).forEach {
9696
test("reports $it is invalid value") {
9797
shouldThrow<IllegalArgumentException> {
98-
JsonSchema.fromDescription(
98+
JsonSchema.fromDefinition(
9999
"""
100100
{
101101
"${KEY}schema": "http://json-schema.org/draft-07/schema#",

src/commonTest/kotlin/com/github/optimumcode/json/schema/assertions/array/JsonSchemaItemsValidationTest.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import kotlinx.serialization.json.buildJsonObject
1818
class JsonSchemaItemsValidationTest : FunSpec() {
1919
init {
2020
test("true schema accepts all items") {
21-
val schema = JsonSchema.fromDescription(
21+
val schema = JsonSchema.fromDefinition(
2222
"""
2323
{
2424
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -46,7 +46,7 @@ class JsonSchemaItemsValidationTest : FunSpec() {
4646
}
4747

4848
test("items applied against all items") {
49-
val schema = JsonSchema.fromDescription(
49+
val schema = JsonSchema.fromDefinition(
5050
"""
5151
{
5252
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -71,7 +71,7 @@ class JsonSchemaItemsValidationTest : FunSpec() {
7171
}
7272

7373
test("items array applied against items on corresponding indexes") {
74-
val schema = JsonSchema.fromDescription(
74+
val schema = JsonSchema.fromDefinition(
7575
"""
7676
{
7777
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -106,7 +106,7 @@ class JsonSchemaItemsValidationTest : FunSpec() {
106106
}
107107

108108
test("single item reports error for all elements") {
109-
val schema = JsonSchema.fromDescription(
109+
val schema = JsonSchema.fromDefinition(
110110
"""
111111
{
112112
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -161,7 +161,7 @@ class JsonSchemaItemsValidationTest : FunSpec() {
161161
}
162162

163163
test("collection items reports error for elements on corresponding indexes") {
164-
val schema = JsonSchema.fromDescription(
164+
val schema = JsonSchema.fromDefinition(
165165
"""
166166
{
167167
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -208,7 +208,7 @@ class JsonSchemaItemsValidationTest : FunSpec() {
208208
}
209209

210210
test("additional items ignored when item is a JSON schema") {
211-
val schema = JsonSchema.fromDescription(
211+
val schema = JsonSchema.fromDefinition(
212212
"""
213213
{
214214
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -237,7 +237,7 @@ class JsonSchemaItemsValidationTest : FunSpec() {
237237
}
238238

239239
test("additional items applied to all remaining elements") {
240-
val schema = JsonSchema.fromDescription(
240+
val schema = JsonSchema.fromDefinition(
241241
"""
242242
{
243243
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -298,7 +298,7 @@ class JsonSchemaItemsValidationTest : FunSpec() {
298298
}
299299

300300
test("false additional items reports any additional element") {
301-
val schema = JsonSchema.fromDescription(
301+
val schema = JsonSchema.fromDefinition(
302302
"""
303303
{
304304
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -332,7 +332,7 @@ class JsonSchemaItemsValidationTest : FunSpec() {
332332
}
333333
}
334334

335-
val schema = JsonSchema.fromDescription(
335+
val schema = JsonSchema.fromDefinition(
336336
"""
337337
{
338338
"${KEY}schema": "http://json-schema.org/draft-07/schema#",

src/commonTest/kotlin/com/github/optimumcode/json/schema/assertions/array/JsonSchemaMaxItemsValidationTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import kotlinx.serialization.json.buildJsonObject
1818
@Suppress("unused")
1919
class JsonSchemaMaxItemsValidationTest : FunSpec() {
2020
init {
21-
val schema = JsonSchema.fromDescription(
21+
val schema = JsonSchema.fromDefinition(
2222
"""
2323
{
2424
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -92,7 +92,7 @@ class JsonSchemaMaxItemsValidationTest : FunSpec() {
9292

9393
test("reports negative value") {
9494
shouldThrow<IllegalArgumentException> {
95-
JsonSchema.fromDescription(
95+
JsonSchema.fromDefinition(
9696
"""
9797
{
9898
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -111,7 +111,7 @@ class JsonSchemaMaxItemsValidationTest : FunSpec() {
111111
).forEach {
112112
test("reports not valid integer value $it") {
113113
shouldThrow<IllegalArgumentException> {
114-
JsonSchema.fromDescription(
114+
JsonSchema.fromDefinition(
115115
"""
116116
{
117117
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -130,7 +130,7 @@ class JsonSchemaMaxItemsValidationTest : FunSpec() {
130130
).forEach {
131131
test("reports not integer value $it") {
132132
shouldThrow<IllegalArgumentException> {
133-
JsonSchema.fromDescription(
133+
JsonSchema.fromDefinition(
134134
"""
135135
{
136136
"${KEY}schema": "http://json-schema.org/draft-07/schema#",

src/commonTest/kotlin/com/github/optimumcode/json/schema/assertions/array/JsonSchemaMinItemsValidationTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import kotlinx.serialization.json.buildJsonObject
1818
@Suppress("unused")
1919
class JsonSchemaMinItemsValidationTest : FunSpec() {
2020
init {
21-
val schema = JsonSchema.fromDescription(
21+
val schema = JsonSchema.fromDefinition(
2222
"""
2323
{
2424
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -89,7 +89,7 @@ class JsonSchemaMinItemsValidationTest : FunSpec() {
8989

9090
test("reports negative value") {
9191
shouldThrow<IllegalArgumentException> {
92-
JsonSchema.fromDescription(
92+
JsonSchema.fromDefinition(
9393
"""
9494
{
9595
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -108,7 +108,7 @@ class JsonSchemaMinItemsValidationTest : FunSpec() {
108108
).forEach {
109109
test("reports not valid integer value $it") {
110110
shouldThrow<IllegalArgumentException> {
111-
JsonSchema.fromDescription(
111+
JsonSchema.fromDefinition(
112112
"""
113113
{
114114
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -127,7 +127,7 @@ class JsonSchemaMinItemsValidationTest : FunSpec() {
127127
).forEach {
128128
test("reports not integer value $it") {
129129
shouldThrow<IllegalArgumentException> {
130-
JsonSchema.fromDescription(
130+
JsonSchema.fromDefinition(
131131
"""
132132
{
133133
"${KEY}schema": "http://json-schema.org/draft-07/schema#",

src/commonTest/kotlin/com/github/optimumcode/json/schema/assertions/array/JsonSchemaUniqueItemsValidationTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import kotlinx.serialization.json.buildJsonObject
1818
@Suppress("unused")
1919
class JsonSchemaUniqueItemsValidationTest : FunSpec() {
2020
init {
21-
val validationEnabled = JsonSchema.fromDescription(
21+
val validationEnabled = JsonSchema.fromDefinition(
2222
"""
2323
{
2424
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -27,7 +27,7 @@ class JsonSchemaUniqueItemsValidationTest : FunSpec() {
2727
""".trimIndent(),
2828
)
2929

30-
val validationDisabled = JsonSchema.fromDescription(
30+
val validationDisabled = JsonSchema.fromDefinition(
3131
"""
3232
{
3333
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -170,7 +170,7 @@ class JsonSchemaUniqueItemsValidationTest : FunSpec() {
170170
).forEach {
171171
test("reports not valid boolean value $it") {
172172
shouldThrow<IllegalArgumentException> {
173-
JsonSchema.fromDescription(
173+
JsonSchema.fromDefinition(
174174
"""
175175
{
176176
"${KEY}schema": "http://json-schema.org/draft-07/schema#",

src/commonTest/kotlin/com/github/optimumcode/json/schema/assertions/condition/CollectionSchemaTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import io.kotest.matchers.shouldBe
99
fun FunSpec.testInvalidSchemaInArray(name: String) {
1010
test("reports empty array") {
1111
shouldThrow<IllegalArgumentException> {
12-
JsonSchema.fromDescription(
12+
JsonSchema.fromDefinition(
1313
"""
1414
{
1515
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -22,7 +22,7 @@ fun FunSpec.testInvalidSchemaInArray(name: String) {
2222

2323
test("reports not array") {
2424
shouldThrow<IllegalArgumentException> {
25-
JsonSchema.fromDescription(
25+
JsonSchema.fromDefinition(
2626
"""
2727
{
2828
"${KEY}schema": "http://json-schema.org/draft-07/schema#",
@@ -35,7 +35,7 @@ fun FunSpec.testInvalidSchemaInArray(name: String) {
3535

3636
test("reports element in array is not a valid JSON schema") {
3737
shouldThrow<IllegalArgumentException> {
38-
JsonSchema.fromDescription(
38+
JsonSchema.fromDefinition(
3939
"""
4040
{
4141
"${KEY}schema": "http://json-schema.org/draft-07/schema#",

src/commonTest/kotlin/com/github/optimumcode/json/schema/assertions/condition/JsonSchemaAllOfValidationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import kotlinx.serialization.json.JsonPrimitive
1515
class JsonSchemaAllOfValidationTest : FunSpec() {
1616
init {
1717
testInvalidSchemaInArray("allOf")
18-
JsonSchema.fromDescription(
18+
JsonSchema.fromDefinition(
1919
"""
2020
{
2121
"${KEY}schema": "http://json-schema.org/draft-07/schema#",

src/commonTest/kotlin/com/github/optimumcode/json/schema/assertions/condition/JsonSchemaAnyOfValidationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import kotlinx.serialization.json.buildJsonObject
1616
class JsonSchemaAnyOfValidationTest : FunSpec() {
1717
init {
1818
testInvalidSchemaInArray("anyOf")
19-
JsonSchema.fromDescription(
19+
JsonSchema.fromDefinition(
2020
"""
2121
{
2222
"${KEY}schema": "http://json-schema.org/draft-07/schema#",

0 commit comments

Comments
 (0)