Package io.apicurio.datamodels.refs
Class LocalReferenceResolver
- java.lang.Object
-
- io.apicurio.datamodels.refs.LocalReferenceResolver
-
- All Implemented Interfaces:
IReferenceResolver
public class LocalReferenceResolver extends Object implements IReferenceResolver
A class to help with resolving references. Handles recursion with loop detection.- Author:
- eric.wittmann@gmail.com
-
-
Constructor Summary
Constructors Constructor Description LocalReferenceResolver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ResolvedReferenceresolveRef(String $ref, Node from)Resolves a reference to aResolvedReference.
-
-
-
Method Detail
-
resolveRef
public ResolvedReference resolveRef(String $ref, Node from)
Description copied from interface:IReferenceResolverResolves a reference to aResolvedReference.The resolver can return three different types of content:
- Node: Use
ResolvedReference.fromNode(Node)when the resolved content is an OpenAPI or AsyncAPI document/component that has been parsed into the data model. - JsonNode: Use
ResolvedReference.fromJson(com.fasterxml.jackson.databind.JsonNode)orResolvedReference.fromJson(com.fasterxml.jackson.databind.JsonNode, String)when the resolved content is JSON or YAML that is not OpenAPI/AsyncAPI (e.g., JSON Schema, Avro JSON format). Include the media type when known. - Text: Use
ResolvedReference.fromText(String, String)when the resolved content is non-JSON text such as Protocol Buffers (.proto), GraphQL schemas, Avro text format, etc. The media type should be provided (e.g., "application/vnd.google.protobuf;version=3").
Example for a Protocol Buffers .proto file reference:
String protoContent = "syntax = \"proto3\";\n\nmessage UserEvent {\n string userId = 1;\n}\n"; return ResolvedReference.fromText(protoContent, "application/vnd.google.protobuf;version=3");Example for a JSON Schema reference:
JsonNode jsonSchema = // ... parse JSON ... return ResolvedReference.fromJson(jsonSchema, "application/schema+json");
Example for an OpenAPI component reference:
Node node = // ... parse and convert to Node ... return ResolvedReference.fromNode(node);
- Specified by:
resolveRefin interfaceIReferenceResolver- Parameters:
$ref- the reference URI to resolve (e.g., "http://example.com/schema.proto")from- the node containing the reference- Returns:
- a ResolvedReference containing the resolved content, or null if the resolver cannot resolve the reference
- Node: Use
-
-