Commit b8815f18 authored by Robert Hensing's avatar Robert Hensing Committed by github-actions[bot]
Browse files

json-schema-catalog-rs: init at 0.1.1

(cherry picked from commit c598c6d5)
parent e4b8c79e
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
{
  callPackage,
  fetchFromGitHub,
  lib,
  nix-update-script,
  rustPlatform,
}:

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=";

  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";
  };
})
+54 −0
Original line number Diff line number Diff line
{
  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
  ''