mirror of
https://github.com/NixOS/nix.git
synced 2025-11-20 09:19:36 +01:00
Merge pull request #14309 from obsidiansystems/json-schema-content-address
` nlohmann::json` instance and JSON Schema for `ContentAddress`
This commit is contained in:
commit
0c1be3aabe
18 changed files with 242 additions and 37 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include "nix/util/args.hh"
|
||||
#include "nix/store/content-address.hh"
|
||||
#include "nix/util/split.hh"
|
||||
#include "nix/util/json-utils.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
@ -300,3 +301,36 @@ Hash ContentAddressWithReferences::getHash() const
|
|||
}
|
||||
|
||||
} // namespace nix
|
||||
|
||||
namespace nlohmann {
|
||||
|
||||
using namespace nix;
|
||||
|
||||
ContentAddressMethod adl_serializer<ContentAddressMethod>::from_json(const json & json)
|
||||
{
|
||||
return ContentAddressMethod::parse(getString(json));
|
||||
}
|
||||
|
||||
void adl_serializer<ContentAddressMethod>::to_json(json & json, const ContentAddressMethod & m)
|
||||
{
|
||||
json = m.render();
|
||||
}
|
||||
|
||||
ContentAddress adl_serializer<ContentAddress>::from_json(const json & json)
|
||||
{
|
||||
auto obj = getObject(json);
|
||||
return {
|
||||
.method = adl_serializer<ContentAddressMethod>::from_json(valueAt(obj, "method")),
|
||||
.hash = valueAt(obj, "hash"),
|
||||
};
|
||||
}
|
||||
|
||||
void adl_serializer<ContentAddress>::to_json(json & json, const ContentAddress & ca)
|
||||
{
|
||||
json = {
|
||||
{"method", ca.method},
|
||||
{"hash", ca.hash},
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace nlohmann
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "nix/store/path.hh"
|
||||
#include "nix/util/file-content-address.hh"
|
||||
#include "nix/util/variant-wrapper.hh"
|
||||
#include "nix/util/json-impls.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
@ -308,4 +309,15 @@ struct ContentAddressWithReferences
|
|||
Hash getHash() const;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct json_avoids_null<ContentAddressMethod> : std::true_type
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct json_avoids_null<ContentAddress> : std::true_type
|
||||
{};
|
||||
|
||||
} // namespace nix
|
||||
|
||||
JSON_IMPL(nix::ContentAddressMethod)
|
||||
JSON_IMPL(nix::ContentAddress)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue