json-schema-catalog-rs: init at 0.1.1 (#409475)

This commit is contained in:
Aleksana
2025-05-23 15:30:55 +08:00
committed by GitHub
2 changed files with 102 additions and 0 deletions
@@ -0,0 +1,48 @@
{
callPackage,
fetchFromGitHub,
lib,
nix-update-script,
rustPlatform,
versionCheckHook,
}:
rustPlatform.buildRustPackage (finalAttrs: {
pname = "json-schema-catalog-rs";
version = "0.1.1";
src = fetchFromGitHub {
owner = "roberth";
repo = "json-schema-catalog-rs";
tag = finalAttrs.version;
hash = "sha256-BbEPpolv2aoKFlfZ6A+CmUlr5sySGIqRlv3rLgf1VkA=";
};
cargoHash = "sha256-YI2LN2DBzC1B5wCZOrGAZi/hkKHoAm6xLkdJ+8DDFo8=";
doInstallCheck = true;
nativeInstallCheckInputs = [ versionCheckHook ];
versionCheckProgram = "${placeholder "out"}/bin/json-schema-catalog";
versionCheckProgramArg = "--version";
passthru = {
tests = {
run = callPackage ./test-run.nix { json-schema-catalog-rs = finalAttrs.finalPackage; };
};
updateScript = nix-update-script { };
};
meta = {
description = "CLI for working with JSON Schema Catalogs";
longDescription = ''
A JSON Schema Catalog file provides a mapping from schema URIs to schema locations.
By constructing and using a catalog, you can avoid the need to download and parse schemas from the internet.
This is particularly useful when working with large schemas or when you need to work, test or build offline.
'';
homepage = "https://github.com/roberth/json-schema-catalog-rs";
license = lib.licenses.asl20;
maintainers = [ lib.maintainers.roberth ];
mainProgram = "json-schema-catalog";
};
})
@@ -0,0 +1,54 @@
{
json-schema-catalog-rs,
runCommand,
}:
let
sample = builtins.toFile "example-schema.json" (
builtins.toJSON {
"$schema" = "http://json-schema.org/draft-07/schema#";
"$id" = "https://example.com/example-2.9.json";
"title" = "Example Schema";
}
);
in
runCommand "json-schema-catalog-rs-test-run"
{
nativeBuildInputs = [
json-schema-catalog-rs
];
inherit sample;
expectedOutput = ''
{
"groups": [
{
"baseLocation": "/nix/store",
"name": "Example Schema",
"schemas": [
{
"id": "https://example.com/example-2.9.json",
"location": "${baseNameOf sample}"
}
]
}
],
"name": "Catalog"
}
'';
passAsFile = [
"expectedOutput"
];
}
''
set -u
# Test version
json-schema-catalog --version | grep ${json-schema-catalog-rs.version}
# Test a simple command
json-schema-catalog new "$sample" > out.json
diff -U3 "$expectedOutputPath" out.json
touch $out
''