mod fix_ref_uris;
mod inject_lintel;
mod linkify_descriptions;
mod reorder_schema_keys;
use fix_ref_uris::fix_ref_uris;
use inject_lintel::inject_lintel;
use linkify_descriptions::linkify_descriptions;
use reorder_schema_keys::reorder_schema_keys;
use lintel_schema_cache::SchemaCache;
use schema_catalog::FileFormat;
pub struct PostprocessContext<'a> {
pub cache: &'a SchemaCache,
pub source_url: Option<String>,
pub lintel_source: Option<(String, String)>,
pub file_match: Vec<String>,
pub parsers: Vec<FileFormat>,
}
pub fn postprocess_schema(ctx: &PostprocessContext<'_>, value: &mut serde_json::Value) {
fix_ref_uris(value);
inject_lintel(ctx, value);
reorder_schema_keys(value);
linkify_descriptions(value);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn reorders_and_linkifies() {
let cache = lintel_schema_cache::SchemaCache::memory();
let ctx = PostprocessContext {
cache: &cache,
source_url: None,
lintel_source: None,
file_match: Vec::new(),
parsers: Vec::new(),
};
let mut schema = serde_json::json!({
"type": "object",
"description": "See https://example.com",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Test"
});
postprocess_schema(&ctx, &mut schema);
let keys: Vec<&String> = schema
.as_object()
.expect("test value is an object")
.keys()
.collect();
assert_eq!(keys, &["$schema", "title", "description", "type"]);
assert_eq!(schema["description"], "See <https://example.com>");
}
}