io.openapiprocessor.jsonschema.schema.ResolverId 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 2023 https://github.com/openapi-processor/openapi-parser
* PDX-License-Identifier: Apache-2.0
*/
package io.openapiprocessor.jsonschema.schema;
import io.openapiprocessor.jsonschema.converter.BooleanConverter;
import io.openapiprocessor.jsonschema.converter.StringNullableConverter;
import io.openapiprocessor.jsonschema.support.Types;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.net.URI;
import java.util.Collection;
public class ResolverId {
private final ResolverContext context;
public ResolverId (ResolverContext context) {
this.context = context;
}
public void resolve (Bucket bucket) {
resolveId (bucket);
walkBucket (bucket);
}
@SuppressWarnings({"dereference.of.nullable"})
private void walkBucket (Bucket bucket) {
URI currentId = getId (bucket);
registerId (currentId, bucket);
resolveId (bucket);
// since 2019-09
URI currentAnchor = getAnchor (bucket);
registerAnchor (currentAnchor, bucket);
resolveAnchor (currentAnchor, bucket);
// only 2019-09
URI recursiveAnchor = getRecursiveAnchor (bucket);
registerDynamicAnchor (recursiveAnchor, bucket);
resolveDynamicAnchor (recursiveAnchor, bucket);
// since 2020-12
URI dynamicAnchor = getDynamicAnchor (bucket);
registerDynamicAnchor (dynamicAnchor, bucket);
resolveDynamicAnchor (dynamicAnchor, bucket);
Scope scope = bucket.getScope ();
JsonPointer location = bucket.getLocation ();
SchemaVersion version = scope.getVersion ();
bucket.forEach ((name, value) -> {
JsonPointer propLocation = location.append (name);
Keyword keyword = version.getKeyword (name);
boolean navigable = keyword != null && keyword.isNavigable ();
if (navigable && keyword.isSchema () && Types.isObject (value)) {
walkSchema (scope, value, propLocation);
} else if (navigable && keyword.isSchemaArray () && Types.isArray (value)) {
walkSchemaArray (scope, value, propLocation);
} else if (navigable && keyword.isSchemaMap ()) {
walkSchemaMap (scope, value, propLocation);
} /* else if (keyword == null && isObject (value)) {
walkSchema (scope, value, propLocation);
} else if (keyword == null && isArray (value)) {
walkSchemaArray (scope, value, propLocation);
} */
});
}
private void walkSchema (Scope currentScope, Object value, JsonPointer location) {
Scope scope = currentScope.move (value);
Bucket bucket = Bucket.createBucket(scope, value, location);
if (bucket == null) {
return; // todo error
}
walkBucket (bucket);
}
private void walkSchemaArray (Scope currentScope, Object value, JsonPointer location) {
Collection