Fix: throw error for undefined enum for both small and large enum in C++ by HavardNJ-Laerdal · Pull Request #2846 · glideapps/quicktype

Current version throws for an unknown enum if the enum is considered small and handled with if-else

    inline void from_json(const json & j, Extrasystole & x) {
        if (j == "coupled_pvc") x = Extrasystole::CoupledPvc;
         ...
        else { throw std::runtime_error("Input JSON does not conform to schema!"); }

For a large enum implemented with map, the throw is missing

    inline void from_json(const json & j, BasicRhythm & x) {
        static std::unordered_map<std::string, BasicRhythm> enumValues {
            {"sinus", BasicRhythm::Sinus},
            ...
        };
        auto iter = enumValues.find(j.get<std::string>());
        if (iter != enumValues.end()) {
            x = iter->second;
        }
}

resulting in the property being a valid value which is inconsistent with the json.

This change adds the throw at the end of the large enum.

        ....
        if (iter != enumValues.end()) {
            x = iter->second;
        }
        else { throw std::runtime_error("Input JSON does not conform to schema!"); }