-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support schema resources * Refactor * Refactor * Refactor * Support uri change in id * Fix schema resource parent and evaluation path * Fix * Fix remote ref paths * Fix * Fix schema location * Support anchors * Refactor * Refactor * Refactor * Refactor shift subschema loading to factory * Fix ref * Refactor ref * Refactor discriminator * Refactor * Refactor validation context * Load validators in constructor * Schema location * Refactor ref validator * Fix enum
- Loading branch information
1 parent
5a94df7
commit 9b73d10
Showing
36 changed files
with
1,309 additions
and
362 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
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
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
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
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,41 @@ | ||
/* | ||
* Copyright (c) 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.networknt.schema; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Supplier that caches the output. | ||
* | ||
* @param <T> the type cached | ||
*/ | ||
public class CachedSupplier<T> implements Supplier<T> { | ||
private final Supplier<T> delegate; | ||
private T cache = null; | ||
|
||
public CachedSupplier(Supplier<T> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public T get() { | ||
if (cache == null) { | ||
cache = delegate.get(); | ||
} | ||
return cache; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/networknt/schema/DiscriminatorContext.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,41 @@ | ||
package com.networknt.schema; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
public class DiscriminatorContext { | ||
private final Map<String, ObjectNode> discriminators = new HashMap<>(); | ||
|
||
private boolean discriminatorMatchFound = false; | ||
|
||
public void registerDiscriminator(final SchemaLocation schemaLocation, final ObjectNode discriminator) { | ||
this.discriminators.put("#" + schemaLocation.getFragment().toString(), discriminator); | ||
} | ||
|
||
public ObjectNode getDiscriminatorForPath(final SchemaLocation schemaLocation) { | ||
return this.discriminators.get("#" + schemaLocation.getFragment().toString()); | ||
} | ||
|
||
public ObjectNode getDiscriminatorForPath(final String schemaLocation) { | ||
return this.discriminators.get(schemaLocation); | ||
} | ||
|
||
public void markMatch() { | ||
this.discriminatorMatchFound = true; | ||
} | ||
|
||
public boolean isDiscriminatorMatchFound() { | ||
return this.discriminatorMatchFound; | ||
} | ||
|
||
/** | ||
* Returns true if we have a discriminator active. In this case no valid match in anyOf should lead to validation failure | ||
* | ||
* @return true in case there are discriminator candidates | ||
*/ | ||
public boolean isActive() { | ||
return !this.discriminators.isEmpty(); | ||
} | ||
} |
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
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
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
Oops, something went wrong.