| 178 | } |
| 179 | |
| 180 | std::string SarifReport::serialize(std::string productName) const |
| 181 | { |
| 182 | const auto nameAndVersion = Settings::getNameAndVersion(productName); |
| 183 | productName = nameAndVersion.first.empty() ? "Cppcheck" : nameAndVersion.first; |
| 184 | std::string version = nameAndVersion.first.empty() ? CppCheck::version() : nameAndVersion.second; |
| 185 | if (version.find(' ') != std::string::npos) |
| 186 | version.erase(version.find(' '), std::string::npos); |
| 187 | |
| 188 | picojson::object doc; |
| 189 | doc["$schema"] = picojson::value(sarifSchema); |
| 190 | doc["runs"] = serializeRuns(productName, version); |
| 191 | |
| 192 | // Insert "version" property at the start. |
| 193 | // From SARIF specification (https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141790730): |
| 194 | // Although the order in which properties appear in a JSON object value is not semantically significant, the version property SHOULD appear first. |
| 195 | |
| 196 | return "{\n \"version\": \"" + std::string(sarifVersion) + "\"," + picojson::value(doc).serialize(true).substr(1); |
| 197 | } |
| 198 | |
| 199 | std::string SarifReport::sarifSeverity(const ErrorMessage& errmsg) |
| 200 | { |