Skip to content

Commit e91e724

Browse files
committed
Add functionality to selectively suppress key warnings
For unknown keys. { "dont_warn_unused_keys": [ "key1", "key3" ], "key1": 5, "key2": { "dont_warn_unused_keys": [ "key1" ], "key1": 5, "key2": 6 }, "key3": { "dont_warn_unused_keys": [ "key1" ], "key1": 5, "key2": 6 } } Will yield the warning: [Series] The following parts of the global JSON config remains unused: { "key2": { "dont_warn_unused_keys": [ "key1" ], "key1": 5, "key2": 6 }, "key3": { "key2": 6 } } TODO: Better errors when parsing, documentation
1 parent 1bd63c7 commit e91e724

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

include/openPMD/auxiliary/JSON_internal.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ namespace json
162162
nlohmann::json *positionInShadow,
163163
SupportedLanguages originallySpecifiedAs,
164164
bool trace);
165+
166+
void init();
167+
static void init(nlohmann::json &original, nlohmann::json &shadow);
165168
};
166169

167170
template <typename Key>

src/auxiliary/JSON.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ TracingJSON::TracingJSON(
5353
, m_shadow(std::make_shared<nlohmann::json>())
5454
, m_positionInOriginal(&*m_originalJSON)
5555
, m_positionInShadow(&*m_shadow)
56-
{}
56+
{
57+
init();
58+
}
5759

5860
TracingJSON::TracingJSON(ParsedConfig parsedConfig)
5961
: TracingJSON{
@@ -158,7 +160,31 @@ TracingJSON::TracingJSON(
158160
, m_positionInOriginal(positionInOriginal)
159161
, m_positionInShadow(positionInShadow)
160162
, m_trace(trace)
161-
{}
163+
{
164+
init();
165+
}
166+
167+
void TracingJSON::init()
168+
{
169+
if (m_originalJSON)
170+
{
171+
init(*m_originalJSON, *m_shadow);
172+
}
173+
}
174+
175+
void TracingJSON::init(nlohmann::json &original, nlohmann::json &shadow)
176+
{
177+
if (original.is_object() && original.contains("dont_warn_unused_keys"))
178+
{
179+
auto suppress_warnings_for_these = original.at("dont_warn_unused_keys")
180+
.get<std::vector<std::string>>();
181+
for (auto const &key : suppress_warnings_for_these)
182+
{
183+
init(original[key], shadow[key]);
184+
}
185+
shadow["dont_warn_unused_keys"] = nlohmann::json();
186+
}
187+
}
162188

163189
namespace
164190
{

0 commit comments

Comments
 (0)