pub struct GtsStore { /* private fields */ }Implementations§
Source§impl GtsStore
impl GtsStore
pub fn new(reader: Option<Box<dyn GtsReader>>) -> Self
Sourcepub fn register(&mut self, entity: GtsEntity) -> Result<(), StoreError>
pub fn register(&mut self, entity: GtsEntity) -> Result<(), StoreError>
Registers an entity in the store.
§Errors
Returns StoreError::InvalidEntity if the entity has no effective ID.
Sourcepub fn register_schema(
&mut self,
type_id: &str,
schema: &Value,
) -> Result<(), StoreError>
pub fn register_schema( &mut self, type_id: &str, schema: &Value, ) -> Result<(), StoreError>
Registers a schema in the store.
§Errors
Returns StoreError::InvalidSchemaId if the type_id doesn’t end with ‘~’.
pub fn get(&mut self, entity_id: &str) -> Option<&GtsEntity>
Sourcepub fn get_schema_content(&mut self, type_id: &str) -> Result<Value, StoreError>
pub fn get_schema_content(&mut self, type_id: &str) -> Result<Value, StoreError>
Gets the content of a schema by its type ID.
§Errors
Returns StoreError::SchemaNotFound if the schema is not found.
pub fn items(&self) -> impl Iterator<Item = (&String, &GtsEntity)>
Sourcepub fn resolve_schema_refs(&self, schema: &Value) -> Value
pub fn resolve_schema_refs(&self, schema: &Value) -> Value
Resolve all $ref references in a JSON Schema by inlining the referenced schemas.
This method recursively traverses the schema, finds all $ref references,
and replaces them with the actual schema content from the store. The result
is a fully inlined schema with no external references.
§Arguments
schema- The JSON Schema value that may contain$refreferences
§Returns
A new serde_json::Value with all $ref references resolved and inlined.
§Example
use gts::GtsStore;
let store = GtsStore::new();
// Add schemas to store
store.add_schema_json("parent.v1~", parent_schema)?;
store.add_schema_json("child.v1~", child_schema_with_ref)?;
// Resolve references
let inlined = store.resolve_schema_refs(&child_schema_with_ref);
assert!(!inlined.to_string().contains("$ref"));Sourcepub fn validate_schema(&mut self, gts_id: &str) -> Result<(), StoreError>
pub fn validate_schema(&mut self, gts_id: &str) -> Result<(), StoreError>
Validates a schema against JSON Schema meta-schema and x-gts-ref constraints.
§Errors
Returns StoreError if validation fails.