Package io.apicurio.datamodels.refs
Interface IReferenceResolver
-
- All Known Implementing Classes:
LocalReferenceResolver,ReferenceResolverChain
public interface IReferenceResolverUsed to resolve references ($ref or operationRef) to a JSON object. Users of the apicurio-data-models library can provide zero or more custom implementations of this interface in order to provide a way to resolve reference URI formats that are not supported by default. Internal references are supported by default. When providing custom reference resolvers, those custom resolvers will be used before any default/built-in resolvers.- Author:
- eric.wittmann@gmail.com
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ResolvedReferenceresolveRef(String reference, Node from)Resolves a reference to aResolvedReference.
-
-
-
Method Detail
-
resolveRef
ResolvedReference resolveRef(String reference, Node from)
Resolves 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);
- Parameters:
reference- 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
-
-