File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 2525#include < set>
2626#include < sstream>
2727
28+ static const char sarifVersion[] = " 2.1.0" ;
29+ static const char sarifSchema[] = " https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json" ;
30+
2831void SarifReport::addFinding (ErrorMessage msg)
2932{
3033 mFindings .push_back (std::move (msg));
@@ -180,11 +183,14 @@ std::string SarifReport::serialize(std::string productName) const
180183 version.erase (version.find (' ' ), std::string::npos);
181184
182185 picojson::object doc;
183- doc[" version" ] = picojson::value (" 2.1.0" );
184- doc[" $schema" ] = picojson::value (" https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json" );
186+ doc[" $schema" ] = picojson::value (sarifSchema);
185187 doc[" runs" ] = serializeRuns (productName, version);
186188
187- return picojson::value (doc).serialize (true );
189+ // Insert "version" property at the start.
190+ // From SARIF specification (https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141790730):
191+ // Although the order in which properties appear in a JSON object value is not semantically significant, the version property SHOULD appear first.
192+
193+ return " {\n \" version\" : \" " + std::string (sarifVersion) + " \" ," + picojson::value (doc).serialize (true ).substr (1 );
188194}
189195
190196std::string SarifReport::sarifSeverity (const ErrorMessage& errmsg)
Original file line number Diff line number Diff line change @@ -98,6 +98,10 @@ class TestSarifReport : public TestFixture
9898 ASSERT_EQUALS (" 2.1.0" , root.at (" version" ).get <std::string>());
9999 ASSERT (root.at (" $schema" ).get <std::string>().find (" sarif-schema-2.1.0" ) != std::string::npos);
100100
101+ // From SARIF specification (https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141790730):
102+ // Although the order in which properties appear in a JSON object value is not semantically significant, the version property SHOULD appear first.
103+ ASSERT_EQUALS (" {\n \" version\" : \" 2.1.0\" " , sarif.substr (0 ,22 ));
104+
101105 const picojson::array& runs = root.at (" runs" ).get <picojson::array>();
102106 ASSERT_EQUALS (1U , runs.size ());
103107
You can’t perform that action at this time.
0 commit comments