Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON: Selectively suppress unknown key warnings #1700

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/openPMD/auxiliary/JSON_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ namespace json
nlohmann::json *positionInShadow,
SupportedLanguages originallySpecifiedAs,
bool trace);

void init();
static void init(nlohmann::json &original, nlohmann::json &shadow);
};

template <typename Key>
Expand Down
30 changes: 28 additions & 2 deletions src/auxiliary/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ TracingJSON::TracingJSON(
, m_shadow(std::make_shared<nlohmann::json>())
, m_positionInOriginal(&*m_originalJSON)
, m_positionInShadow(&*m_shadow)
{}
{
init();
}

TracingJSON::TracingJSON(ParsedConfig parsedConfig)
: TracingJSON{
Expand Down Expand Up @@ -158,7 +160,31 @@ TracingJSON::TracingJSON(
, m_positionInOriginal(positionInOriginal)
, m_positionInShadow(positionInShadow)
, m_trace(trace)
{}
{
init();
}

void TracingJSON::init()
{
if (m_originalJSON)
{
init(*m_originalJSON, *m_shadow);
}
}

void TracingJSON::init(nlohmann::json &original, nlohmann::json &shadow)
{
if (original.is_object() && original.contains("dont_warn_unused_keys"))
{
auto suppress_warnings_for_these = original.at("dont_warn_unused_keys")
.get<std::vector<std::string>>();
for (auto const &key : suppress_warnings_for_these)
{
init(original[key], shadow[key]);
}
shadow["dont_warn_unused_keys"] = nlohmann::json();
}
}

namespace
{
Expand Down
Loading