Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ public static boolean areSchemaTypesCompatible(final @NotNull JsonSchemaObject s
}

public static @Nullable JsonSchemaType getMatchingSchemaType(@NotNull JsonSchemaObject schema, @Nullable JsonSchemaType input) {
if (schema.getConstantSchema() != null) return input;
final JsonSchemaType matchType = schema.getType();
if (matchType != null) {
if (JsonSchemaType._integer.equals(input) && JsonSchemaType._number.equals(matchType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,25 +376,25 @@ private fun <T, V> InheritedJsonSchemaObjectView.baseIfConditionOrOtherWithArgum
argument: V,
condition: (T) -> Boolean,
): T {
return baseIfConditionOrOtherWithArgument(other, base, memberReference, argument, condition)
return baseIfConditionOrOtherWithArgument(base, other, memberReference, argument, condition)
}

private fun <T> InheritedJsonSchemaObjectView.baseIfConditionOrOther(memberReference: JsonSchemaObject.() -> T, condition: (T) -> Boolean): T {
return baseIfConditionOrOther(other, base, memberReference, condition)
return baseIfConditionOrOther(base, other, memberReference, condition)
}

private fun <V> InheritedJsonSchemaObjectView.booleanOrWithArgument(memberReference: JsonSchemaObject.(V) -> Boolean, argument: V): Boolean {
return booleanOrWithArgument(other, base, memberReference, argument)
return booleanOrWithArgument(base, other, memberReference, argument)
}

private fun InheritedJsonSchemaObjectView.booleanAndNullable(memberReference: JsonSchemaObject.() -> Boolean?): Boolean? {
return booleanAndNullable(other, base, memberReference)
return booleanAndNullable(base, other, memberReference)
}

private fun InheritedJsonSchemaObjectView.booleanAnd(memberReference: JsonSchemaObject.() -> Boolean): Boolean {
return booleanAnd(other, base, memberReference)
return booleanAnd(base, other, memberReference)
}

private fun InheritedJsonSchemaObjectView.booleanOr(memberReference: JsonSchemaObject.() -> Boolean): Boolean {
return booleanOr(other, base, memberReference)
return booleanOr(base, other, memberReference)
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ internal data object JsonSchema202012Strategy : JsonSchemaInterpretationStrategy

override fun getValidations(schemaNode: JsonSchemaObject, type: JsonSchemaType?, value: JsonValueAdapter): Sequence<JsonSchemaValidation> {
return sequence {
if (schemaNode.constantSchema != null) {
yield(ConstantSchemaValidation)
return@sequence
}
if (type != null) yieldAll(getTypeValidations(type))
yieldAll(getBaseValidations(value, schemaNode))
}
}

private fun getBaseValidations(value: JsonValueAdapter, schemaNode: JsonSchemaObject): Sequence<JsonSchemaValidation> {
if (schemaNode.constantSchema != null) {
return sequenceOf(ConstantSchemaValidation)
}

return sequence {
yield(EnumValidation.INSTANCE)

Expand Down Expand Up @@ -111,4 +111,4 @@ internal data object JsonSchema202012Strategy : JsonSchemaInterpretationStrategy
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ internal fun getSchema7AndEarlierValidations(schema: JsonSchemaObject,
type: JsonSchemaType?,
value: JsonValueAdapter): Sequence<JsonSchemaValidation> {
return sequence {
if (schema.constantSchema != null) {
yield(ConstantSchemaValidation)
return@sequence
}
if (type != null) yieldAll(getTypeValidations(type))
yieldAll(getBaseValidations(schema, value))
}.distinct()
Expand Down Expand Up @@ -42,10 +46,6 @@ internal fun getTypeValidations(type: JsonSchemaType): Sequence<JsonSchemaValida
}

internal fun getBaseValidations(schema: JsonSchemaObject, value: JsonValueAdapter): Sequence<JsonSchemaValidation> {
if (schema.constantSchema != null) {
return sequenceOf(ConstantSchemaValidation)
}

return sequence {
yield(EnumValidation.INSTANCE)
if (!value.isShouldBeIgnored) {
Expand Down Expand Up @@ -78,4 +78,4 @@ internal fun getBaseValidations(schema: JsonSchemaObject, value: JsonValueAdapte

internal fun hasMinMaxLengthChecks(schema: JsonSchemaObject): Boolean {
return schema.minLength != null || schema.maxLength != null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,34 @@ public void testReadNestedSchemaObject() {
Assert.assertNull(nonTextualNode);
}

public void testDraft202012ConstKeywordInSchemaIsValid() {
myFixture.enableInspections(new JsonSchemaComplianceInspection());
Disposer.register(getTestRootDisposable(), () -> JsonSchemaTestServiceImpl.setProvider(null));

myFixture.configureByFiles("schema202012ConstKeywordSchema.json");
final List<HighlightInfo> infos = myFixture.doHighlighting();
for (HighlightInfo info : infos) {
if (!HighlightSeverity.INFORMATION.equals(info.getSeverity())) {
fail(String.format("%s in: %s", info.getDescription(),
myFixture.getEditor().getDocument().getText(TextRange.create(info))));
}
}
}

public void testDraft202012DynamicRefInSchemaIsValid() {
myFixture.enableInspections(new JsonSchemaComplianceInspection());
Disposer.register(getTestRootDisposable(), () -> JsonSchemaTestServiceImpl.setProvider(null));

myFixture.configureByFiles("schema202012DynamicRefSchema.json");
final List<HighlightInfo> infos = myFixture.doHighlighting();
for (HighlightInfo info : infos) {
if (!HighlightSeverity.INFORMATION.equals(info.getSeverity())) {
fail(String.format("%s in: %s", info.getDescription(),
myFixture.getEditor().getDocument().getText(TextRange.create(info))));
}
}
}

private void doTestSchemaReadNotHung(final File file) throws Exception {
// because of threading
if (Runtime.getRuntime().availableProcessors() < 2) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "example-schema.json",
"type": "object",
"properties": {
"test": {
"type": "string",
"const": "hello-world"
}
},
"required": [
"test"
],
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$dynamicAnchor": "meta",
"type": "object",
"additionalProperties": {
"$dynamicRef": "#meta"
}
}