-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix : JSONSchema array item reference defs
- Loading branch information
Showing
3 changed files
with
41 additions
and
1 deletion.
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
30 changes: 30 additions & 0 deletions
30
core/src/test/java/com/alibaba/fastjson2/schema/JSONSchemaTest1.java
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,30 @@ | ||
package com.alibaba.fastjson2.schema; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONArray; | ||
import com.alibaba.fastjson2.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.net.URL; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class JSONSchemaTest1 { | ||
@Test | ||
public void test0() { | ||
URL url = JSONSchemaTest.class.getClassLoader().getResource("schema/schema_02.json"); | ||
JSONObject object = JSON.parseObject(url, JSONObject.class); | ||
ArraySchema schema = (ArraySchema) JSONSchema.of(object); | ||
assertFalse(schema.isValid("aa")); | ||
assertFalse(schema.isValid(-1)); | ||
assertFalse(schema.isValid(-1L)); | ||
|
||
assertTrue(schema.isValid(JSONArray.of())); | ||
assertTrue(schema.isValid(JSONArray.of(1))); | ||
|
||
assertFalse(schema.isValid(JSONArray.of("a"))); | ||
assertFalse(schema.isValid(JSONArray.of(-1))); | ||
assertFalse(schema.isValid(JSONArray.of(-1L))); | ||
} | ||
} |
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,10 @@ | ||
{ | ||
"type": "array", | ||
"items": { "$ref": "#/$defs/positiveInteger" }, | ||
"$defs": { | ||
"positiveInteger": { | ||
"type": "integer", | ||
"exclusiveMinimum": 0 | ||
} | ||
} | ||
} |