io.openapiprocessor.jsonschema.schema.JsonInstance Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-schema-validator Show documentation
Show all versions of json-schema-validator Show documentation
OpenAPI Parser JSON-Schema Validator
/*
* Copyright 2022 https://github.com/openapi-processor/openapi-parser
* PDX-License-Identifier: Apache-2.0
*/
package io.openapiprocessor.jsonschema.schema;
import io.openapiprocessor.jsonschema.converter.TypeMismatchException;
import io.openapiprocessor.jsonschema.support.Types;
import io.openapiprocessor.jsonschema.validator.support.Equals;
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Collection;
import java.util.Map;
public class JsonInstance {
private final @Nullable Object value;
private final JsonPointer location;
public JsonInstance (@Nullable Object value) {
this.value = value;
this.location = JsonPointer.empty();
}
public JsonInstance (JsonPointer location, @Nullable Object value) {
this.value = value;
this.location = location;
}
public JsonPointer getLocation () {
return location;
}
public String getPath () {
return location.toString ();
}
public @Nullable Object getRawValue () {
return value;
}
public JsonInstance getPropertyName (String propertyName) {
return new JsonInstance (
location.append (propertyName),
getPropertyKey (propertyName));
}
public JsonInstance getValue (String property) {
return new JsonInstance (
location.append (property),
getPropertyValue (property));
}
public JsonInstance getValue (int idx) {
return new JsonInstance (
location.append (idx),
getArrayValue (idx));
}
public int getArraySize () {
return getArraySizeX ();
}
public @Nullable Map asObject () {
return Types.asMap (value);
}
public @Nullable Collection