From 265ddf11ae6cf3172a5ae44e7377102ee80879dc Mon Sep 17 00:00:00 2001 From: Francesco Bertolaccini Date: Fri, 26 Jul 2024 15:23:43 +0200 Subject: [PATCH] sarif: remove nested structs --- sarif/include/gap/sarif/definitions.hpp | 192 ++---------------------- sarif/src/definitions.cpp | 192 ++---------------------- 2 files changed, 32 insertions(+), 352 deletions(-) diff --git a/sarif/include/gap/sarif/definitions.hpp b/sarif/include/gap/sarif/definitions.hpp index 42775ad..3de70dd 100644 --- a/sarif/include/gap/sarif/definitions.hpp +++ b/sarif/include/gap/sarif/definitions.hpp @@ -308,16 +308,6 @@ namespace gap::sarif void to_json(json &, const artifact_content &); void from_json(const json &, artifact_content &); - // - // A dictionary, each of whose keys is the name of a hash function and each of whose values is the hashed value of the artifact produced by the specified hash function. - // - struct artifact_hashes { - std::unordered_map< std::string, std::string > additional_properties; - }; - - void to_json(json &, const artifact_hashes &); - void from_json(const json &, artifact_hashes &); - // // A single artifact. In some cases, this artifact might be nested within another artifact. // @@ -375,7 +365,7 @@ namespace gap::sarif // // A dictionary, each of whose keys is the name of a hash function and each of whose values is the hashed value of the artifact produced by the specified hash function. // - std::optional< artifact_hashes > hashes = std::nullopt; + std::optional< std::unordered_map< std::string, std::string > > hashes = std::nullopt; // // The Coordinated Universal Time (UTC) date and time at which the artifact was most recently modified. See "Date/time properties" in the SARIF spec for the required format. @@ -604,16 +594,6 @@ namespace gap::sarif void to_json(json &, const configuration_override &); void from_json(const json &, configuration_override &); - - // - // A dictionary, each of whose keys is a resource identifier and each of whose values is a multiformatMessageString object, which holds message strings in plain text and (optionally) Markdown format. The strings can include placeholders, which can be used to construct a message in combination with an arbitrary number of additional string arguments. - // - struct tool_component_global_message_strings { - std::unordered_map< std::string, multiformat_message_string > additional_properties; - }; - - void to_json(json &, const tool_component_global_message_strings &); - void from_json(const json &, tool_component_global_message_strings &); struct reporting_descriptor; enum class contents { @@ -746,7 +726,7 @@ namespace gap::sarif // // A dictionary, each of whose keys is a resource identifier and each of whose values is a multiformatMessageString object, which holds message strings in plain text and (optionally) Markdown format. The strings can include placeholders, which can be used to construct a message in combination with an arbitrary number of additional string arguments. // - std::optional< tool_component_global_message_strings > globalMessageStrings = std::nullopt; + std::optional< std::unordered_map< std::string, multiformat_message_string > > globalMessageStrings = std::nullopt; // // An array of reportingDescriptor objects relevant to the notifications related to the configuration and runtime execution of the tool component. @@ -841,16 +821,6 @@ namespace gap::sarif void from_json(const json &, tool &); struct notification; - // - // The environment variables associated with the analysis tool process, expressed as key/value pairs. - // - struct invocation_environment_variables { - std::unordered_map< std::string, std::string > additional_properties; - }; - - void to_json(json &, const invocation_environment_variables &); - void from_json(const json &, invocation_environment_variables &); - // // The runtime environment of the analysis tool run. // @@ -958,7 +928,7 @@ namespace gap::sarif // // The environment variables associated with the analysis tool process, expressed as key/value pairs. // - std::optional< invocation_environment_variables > environmentVariables = std::nullopt; + std::optional< std::unordered_map< std::string, std::string > > environmentVariables = std::nullopt; // // A file containing the standard input stream to the process that was invoked. @@ -1050,16 +1020,6 @@ namespace gap::sarif void to_json(json &, const edge &); void from_json(const json &, edge &); - // - // The values of relevant expressions after the edge has been traversed. - // - struct edge_traversal_final_state { - std::unordered_map< std::string, multiformat_message_string > additional_properties; - }; - - void to_json(json &, const edge_traversal_final_state &); - void from_json(const json &, edge_traversal_final_state &); - // // Represents the traversal of a single edge during a graph traversal. // @@ -1077,7 +1037,7 @@ namespace gap::sarif // // The values of relevant expressions after the edge has been traversed. // - std::optional< edge_traversal_final_state > finalState = std::nullopt; + std::optional< std::unordered_map< std::string, multiformat_message_string > > finalState = std::nullopt; // // The number of edge traversals necessary to return from a nested graph. @@ -1443,26 +1403,6 @@ namespace gap::sarif void to_json(json &, const graph &); void from_json(const json &, graph &); - // - // Values of relevant expressions at the start of the graph traversal that may change during graph traversal. - // - struct graph_traversal_initial_state { - std::unordered_map< std::string, multiformat_message_string > additional_properties; - }; - - void to_json(json &, const graph_traversal_initial_state &); - void from_json(const json &, graph_traversal_initial_state &); - - // - // Values of relevant expressions at the start of the graph traversal that remain constant for the graph traversal. - // - struct graph_traversal_immutable_state { - std::unordered_map< std::string, multiformat_message_string > additional_properties; - }; - - void to_json(json &, const graph_traversal_immutable_state &); - void from_json(const json &, graph_traversal_immutable_state &); - // // Represents a path through a graph. // @@ -1485,12 +1425,12 @@ namespace gap::sarif // // Values of relevant expressions at the start of the graph traversal that may change during graph traversal. // - std::optional< graph_traversal_initial_state > initialState = std::nullopt; + std::optional< std::unordered_map< std::string, multiformat_message_string > > initialState = std::nullopt; // // Values of relevant expressions at the start of the graph traversal that remain constant for the graph traversal. // - std::optional< graph_traversal_immutable_state > immutableState = std::nullopt; + std::optional< std::unordered_map< std::string, multiformat_message_string > > immutableState = std::nullopt; // // The sequences of edges traversed by this graph traversal. @@ -1868,16 +1808,6 @@ namespace gap::sarif void to_json(json &, const replacement &); void from_json(const json &, replacement &); - - // - // A set of name/value pairs with arbitrary names. Each value is a multiformatMessageString object, which holds message strings in plain text and (optionally) Markdown format. The strings can include placeholders, which can be used to construct a message in combination with an arbitrary number of additional string arguments. - // - struct reporting_descriptor_message_strings { - std::unordered_map< std::string, multiformat_message_string > additional_properties; - }; - - void to_json(json &, const reporting_descriptor_message_strings &); - void from_json(const json &, reporting_descriptor_message_strings &); struct reporting_descriptor_relationship; // @@ -1927,7 +1857,7 @@ namespace gap::sarif // // A set of name/value pairs with arbitrary names. Each value is a multiformatMessageString object, which holds message strings in plain text and (optionally) Markdown format. The strings can include placeholders, which can be used to construct a message in combination with an arbitrary number of additional string arguments. // - std::optional< reporting_descriptor_message_strings > messageStrings = std::nullopt; + std::optional< std::unordered_map< std::string, multiformat_message_string > > messageStrings = std::nullopt; // // Default reporting configuration information. @@ -2003,26 +1933,6 @@ namespace gap::sarif { kind::kOpen, "open" }, { kind::kInformational, "informational" }, }) - - // - // A set of strings that contribute to the stable, unique identity of the result. - // - struct result_partial_fingerprints { - std::unordered_map< std::string, std::string > additional_properties; - }; - - void to_json(json &, const result_partial_fingerprints &); - void from_json(const json &, result_partial_fingerprints &); - - // - // A set of strings each of which individually defines a stable, unique identity for the result. - // - struct result_fingerprints { - std::unordered_map< std::string, std::string > additional_properties; - }; - - void to_json(json &, const result_fingerprints &); - void from_json(const json &, result_fingerprints &); struct suppression; enum class baseline_state { @@ -2082,26 +1992,6 @@ namespace gap::sarif void to_json(json &, const result_provenance &); void from_json(const json &, result_provenance &); - // - // The request headers. - // - struct web_request_headers { - std::unordered_map< std::string, std::string > additional_properties; - }; - - void to_json(json &, const web_request_headers &); - void from_json(const json &, web_request_headers &); - - // - // The request parameters. - // - struct web_request_parameters { - std::unordered_map< std::string, std::string > additional_properties; - }; - - void to_json(json &, const web_request_parameters &); - void from_json(const json &, web_request_parameters &); - // // Describes an HTTP request. // @@ -2134,12 +2024,12 @@ namespace gap::sarif // // The request headers. // - std::optional< web_request_headers > headers = std::nullopt; + std::optional< std::unordered_map< std::string, std::string > > headers = std::nullopt; // // The request parameters. // - std::optional< web_request_parameters > parameters = std::nullopt; + std::optional< std::unordered_map< std::string, std::string > > parameters = std::nullopt; // // The body of the request. @@ -2155,16 +2045,6 @@ namespace gap::sarif void to_json(json &, const web_request &); void from_json(const json &, web_request &); - // - // The response headers. - // - struct web_response_headers { - std::unordered_map< std::string, std::string > additional_properties; - }; - - void to_json(json &, const web_response_headers &); - void from_json(const json &, web_response_headers &); - // // Describes the response to an HTTP request. // @@ -2197,7 +2077,7 @@ namespace gap::sarif // // The response headers. // - std::optional< web_response_headers > headers = std::nullopt; + std::optional< std::unordered_map< std::string, std::string > > headers = std::nullopt; // // The body of the response. @@ -2280,12 +2160,12 @@ namespace gap::sarif // // A set of strings that contribute to the stable, unique identity of the result. // - std::optional< result_partial_fingerprints > partialFingerprints = std::nullopt; + std::optional< std::unordered_map< std::string, std::string > > partialFingerprints = std::nullopt; // // A set of strings each of which individually defines a stable, unique identity for the result. // - std::optional< result_fingerprints > fingerprints = std::nullopt; + std::optional< std::unordered_map< std::string, std::string > > fingerprints = std::nullopt; // // An array of 'stack' objects relevant to the result. @@ -2377,16 +2257,6 @@ namespace gap::sarif void from_json(const json &, result &); struct version_control_details; - // - // The artifact location specified by each uriBaseId symbol on the machine where the tool originally ran. - // - struct run_original_uri_base_ids { - std::unordered_map< std::string, artifact_location > additional_properties; - }; - - void to_json(json &, const run_original_uri_base_ids &); - void from_json(const json &, run_original_uri_base_ids &); - // // Information that describes a run's identity and role within an engineering system process. // @@ -2480,7 +2350,7 @@ namespace gap::sarif // // The artifact location specified by each uriBaseId symbol on the machine where the tool originally ran. // - std::optional< run_original_uri_base_ids > originalUriBaseIds = std::nullopt; + std::optional< std::unordered_map< std::string, artifact_location > > originalUriBaseIds = std::nullopt; // // An array of artifact objects relevant to the run. @@ -2679,26 +2549,6 @@ namespace gap::sarif void to_json(json &, const suppression &); void from_json(const json &, suppression &); - // - // Values of relevant expressions at the start of the thread flow that may change during thread flow execution. - // - struct thread_flow_initial_state { - std::unordered_map< std::string, multiformat_message_string > additional_properties; - }; - - void to_json(json &, const thread_flow_initial_state &); - void from_json(const json &, thread_flow_initial_state &); - - // - // Values of relevant expressions at the start of the thread flow that remain constant. - // - struct thread_flow_immutable_state { - std::unordered_map< std::string, multiformat_message_string > additional_properties; - }; - - void to_json(json &, const thread_flow_immutable_state &); - void from_json(const json &, thread_flow_immutable_state &); - // // Describes a sequence of code locations that specify a path through a single thread of execution such as an operating system or fiber. // @@ -2716,12 +2566,12 @@ namespace gap::sarif // // Values of relevant expressions at the start of the thread flow that may change during thread flow execution. // - std::optional< thread_flow_initial_state > initialState = std::nullopt; + std::optional< std::unordered_map< std::string, multiformat_message_string > > initialState = std::nullopt; // // Values of relevant expressions at the start of the thread flow that remain constant. // - std::optional< thread_flow_immutable_state > immutableState = std::nullopt; + std::optional< std::unordered_map< std::string, multiformat_message_string > > immutableState = std::nullopt; // // A temporally ordered array of 'threadFlowLocation' objects, each of which describes a location visited by the tool while producing the result. @@ -2737,16 +2587,6 @@ namespace gap::sarif void to_json(json &, const thread_flow &); void from_json(const json &, thread_flow &); - // - // A dictionary, each of whose keys specifies a variable or expression, the associated value of which represents the variable or expression value. For an annotation of kind 'continuation', for example, this dictionary might hold the current assumed values of a set of global variables. - // - struct thread_flow_location_state { - std::unordered_map< std::string, multiformat_message_string > additional_properties; - }; - - void to_json(json &, const thread_flow_location_state &); - void from_json(const json &, thread_flow_location_state &); - enum class importance { kImportant, kEssential, @@ -2796,7 +2636,7 @@ namespace gap::sarif // // A dictionary, each of whose keys specifies a variable or expression, the associated value of which represents the variable or expression value. For an annotation of kind 'continuation', for example, this dictionary might hold the current assumed values of a set of global variables. // - std::optional< thread_flow_location_state > state = std::nullopt; + std::optional< std::unordered_map< std::string, multiformat_message_string > > state = std::nullopt; // // An integer representing a containment hierarchy within the thread flow. diff --git a/sarif/src/definitions.cpp b/sarif/src/definitions.cpp index 0eab467..a225853 100644 --- a/sarif/src/definitions.cpp +++ b/sarif/src/definitions.cpp @@ -325,16 +325,6 @@ namespace gap::sarif { j["properties"] = *o.properties; } } - void from_json(const json &j, artifact_hashes &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const artifact_hashes &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } void from_json(const json &j, artifact &o) { for( auto &[key, val] : j.items() ) { if ( key == "description" ) { @@ -398,7 +388,7 @@ namespace gap::sarif { continue; } if ( key == "hashes" ) { - artifact_hashes field; + std::unordered_map< std::string, std::string > field; val.get_to(field); o.hashes = field; continue; @@ -728,16 +718,6 @@ namespace gap::sarif { j["properties"] = *o.properties; } } - void from_json(const json &j, tool_component_global_message_strings &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const tool_component_global_message_strings &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } void from_json(const json &j, translation_metadata &o) { for( auto &[key, val] : j.items() ) { if ( key == "name" ) { @@ -888,7 +868,7 @@ namespace gap::sarif { continue; } if ( key == "globalMessageStrings" ) { - tool_component_global_message_strings field; + std::unordered_map< std::string, multiformat_message_string > field; val.get_to(field); o.globalMessageStrings = field; continue; @@ -1086,16 +1066,6 @@ namespace gap::sarif { j["properties"] = *o.properties; } } - void from_json(const json &j, invocation_environment_variables &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const invocation_environment_variables &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } void from_json(const json &j, invocation &o) { for( auto &[key, val] : j.items() ) { if ( key == "commandLine" ) { @@ -1217,7 +1187,7 @@ namespace gap::sarif { continue; } if ( key == "environmentVariables" ) { - invocation_environment_variables field; + std::unordered_map< std::string, std::string > field; val.get_to(field); o.environmentVariables = field; continue; @@ -1409,16 +1379,6 @@ namespace gap::sarif { j["properties"] = *o.properties; } } - void from_json(const json &j, edge_traversal_final_state &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const edge_traversal_final_state &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } void from_json(const json &j, edge_traversal &o) { for( auto &[key, val] : j.items() ) { if ( key == "edgeId" ) { @@ -1432,7 +1392,7 @@ namespace gap::sarif { continue; } if ( key == "finalState" ) { - edge_traversal_final_state field; + std::unordered_map< std::string, multiformat_message_string > field; val.get_to(field); o.finalState = field; continue; @@ -2013,26 +1973,6 @@ namespace gap::sarif { j["properties"] = *o.properties; } } - void from_json(const json &j, graph_traversal_initial_state &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const graph_traversal_initial_state &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } - void from_json(const json &j, graph_traversal_immutable_state &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const graph_traversal_immutable_state &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } void from_json(const json &j, graph_traversal &o) { for( auto &[key, val] : j.items() ) { if ( key == "runGraphIndex" ) { @@ -2054,13 +1994,13 @@ namespace gap::sarif { continue; } if ( key == "initialState" ) { - graph_traversal_initial_state field; + std::unordered_map< std::string, multiformat_message_string > field; val.get_to(field); o.initialState = field; continue; } if ( key == "immutableState" ) { - graph_traversal_immutable_state field; + std::unordered_map< std::string, multiformat_message_string > field; val.get_to(field); o.immutableState = field; continue; @@ -2662,16 +2602,6 @@ namespace gap::sarif { j["properties"] = *o.properties; } } - void from_json(const json &j, reporting_descriptor_message_strings &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const reporting_descriptor_message_strings &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } void from_json(const json &j, reporting_descriptor &o) { for( auto &[key, val] : j.items() ) { if ( key == "id" ) { @@ -2721,7 +2651,7 @@ namespace gap::sarif { continue; } if ( key == "messageStrings" ) { - reporting_descriptor_message_strings field; + std::unordered_map< std::string, multiformat_message_string > field; val.get_to(field); o.messageStrings = field; continue; @@ -2838,26 +2768,6 @@ namespace gap::sarif { j["properties"] = *o.properties; } } - void from_json(const json &j, result_partial_fingerprints &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const result_partial_fingerprints &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } - void from_json(const json &j, result_fingerprints &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const result_fingerprints &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } void from_json(const json &j, result_provenance &o) { for( auto &[key, val] : j.items() ) { if ( key == "firstDetectionTimeUtc" ) { @@ -2927,26 +2837,6 @@ namespace gap::sarif { j["properties"] = *o.properties; } } - void from_json(const json &j, web_request_headers &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const web_request_headers &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } - void from_json(const json &j, web_request_parameters &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const web_request_parameters &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } void from_json(const json &j, web_request &o) { for( auto &[key, val] : j.items() ) { if ( key == "index" ) { @@ -2980,13 +2870,13 @@ namespace gap::sarif { continue; } if ( key == "headers" ) { - web_request_headers field; + std::unordered_map< std::string, std::string > field; val.get_to(field); o.headers = field; continue; } if ( key == "parameters" ) { - web_request_parameters field; + std::unordered_map< std::string, std::string > field; val.get_to(field); o.parameters = field; continue; @@ -3034,16 +2924,6 @@ namespace gap::sarif { j["properties"] = *o.properties; } } - void from_json(const json &j, web_response_headers &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const web_response_headers &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } void from_json(const json &j, web_response &o) { for( auto &[key, val] : j.items() ) { if ( key == "index" ) { @@ -3077,7 +2957,7 @@ namespace gap::sarif { continue; } if ( key == "headers" ) { - web_response_headers field; + std::unordered_map< std::string, std::string > field; val.get_to(field); o.headers = field; continue; @@ -3198,13 +3078,13 @@ namespace gap::sarif { continue; } if ( key == "partialFingerprints" ) { - result_partial_fingerprints field; + std::unordered_map< std::string, std::string > field; val.get_to(field); o.partialFingerprints = field; continue; } if ( key == "fingerprints" ) { - result_fingerprints field; + std::unordered_map< std::string, std::string > field; val.get_to(field); o.fingerprints = field; continue; @@ -3403,16 +3283,6 @@ namespace gap::sarif { j["properties"] = *o.properties; } } - void from_json(const json &j, run_original_uri_base_ids &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const run_original_uri_base_ids &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } void from_json(const json &j, run_automation_details &o) { for( auto &[key, val] : j.items() ) { if ( key == "description" ) { @@ -3519,7 +3389,7 @@ namespace gap::sarif { continue; } if ( key == "originalUriBaseIds" ) { - run_original_uri_base_ids field; + std::unordered_map< std::string, artifact_location > field; val.get_to(field); o.originalUriBaseIds = field; continue; @@ -3849,26 +3719,6 @@ namespace gap::sarif { j["properties"] = *o.properties; } } - void from_json(const json &j, thread_flow_initial_state &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const thread_flow_initial_state &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } - void from_json(const json &j, thread_flow_immutable_state &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const thread_flow_immutable_state &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } void from_json(const json &j, thread_flow &o) { for( auto &[key, val] : j.items() ) { if ( key == "id" ) { @@ -3884,13 +3734,13 @@ namespace gap::sarif { continue; } if ( key == "initialState" ) { - thread_flow_initial_state field; + std::unordered_map< std::string, multiformat_message_string > field; val.get_to(field); o.initialState = field; continue; } if ( key == "immutableState" ) { - thread_flow_immutable_state field; + std::unordered_map< std::string, multiformat_message_string > field; val.get_to(field); o.immutableState = field; continue; @@ -3925,16 +3775,6 @@ namespace gap::sarif { j["properties"] = *o.properties; } } - void from_json(const json &j, thread_flow_location_state &o) { - for( auto &[key, val] : j.items() ) { - val.get_to(o.additional_properties[key]); - } - } - void to_json(json &j, const thread_flow_location_state &o) { - for ( auto &[key, val] : o.additional_properties ) { - j[key] = val; - } - } void from_json(const json &j, thread_flow_location &o) { for( auto &[key, val] : j.items() ) { if ( key == "index" ) { @@ -3974,7 +3814,7 @@ namespace gap::sarif { continue; } if ( key == "state" ) { - thread_flow_location_state field; + std::unordered_map< std::string, multiformat_message_string > field; val.get_to(field); o.state = field; continue;