diff --git a/pkgs/by-name/js/json-schema-catalog-rs/package.nix b/pkgs/by-name/js/json-schema-catalog-rs/package.nix new file mode 100644 index 000000000000..00c40f562221 --- /dev/null +++ b/pkgs/by-name/js/json-schema-catalog-rs/package.nix @@ -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"; + }; +}) diff --git a/pkgs/by-name/js/json-schema-catalog-rs/test-run.nix b/pkgs/by-name/js/json-schema-catalog-rs/test-run.nix new file mode 100644 index 000000000000..0b2cce62e208 --- /dev/null +++ b/pkgs/by-name/js/json-schema-catalog-rs/test-run.nix @@ -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 + ''