From 058b337b00b73b9db09b233c619bd88128fe95e6 Mon Sep 17 00:00:00 2001 From: RosyDev Date: Fri, 12 Apr 2024 10:05:51 +0200 Subject: [PATCH] HTTP library users will now see the generic fields in the components' properties in the correct order as submitted by the API. Fixes https://gitlab.com/kicad/code/kicad/-/issues/17584 --- common/http_lib/http_lib_connection.cpp | 16 ++++++++-------- include/http_lib/http_lib_settings.h | 3 ++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/common/http_lib/http_lib_connection.cpp b/common/http_lib/http_lib_connection.cpp index 7482747437..572bd46c6b 100644 --- a/common/http_lib/http_lib_connection.cpp +++ b/common/http_lib/http_lib_connection.cpp @@ -204,7 +204,7 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART& return false; } - nlohmann::json response = nlohmann::json::parse( res ); + nlohmann::ordered_json response = nlohmann::ordered_json::parse( res ); std::string key = ""; std::string value = ""; @@ -253,6 +253,9 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART& aFetchedPart.exclude_from_sim = boolFromString( exclude, false ); } + // remove previously loaded fields + aFetchedPart.fields.clear(); + // Extract available fields for( const auto& field : response.at( "fields" ).items() ) { @@ -274,10 +277,8 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART& } // Add field to fields list - if( key.length() ) - { - aFetchedPart.fields[key] = std::make_tuple( value, visible ); - } + aFetchedPart.fields.push_back( + std::make_pair( key, std::make_tuple( value, visible ) ) ); } } catch( const std::exception& e ) @@ -321,8 +322,6 @@ bool HTTP_LIB_CONNECTION::SelectAll( const HTTP_LIB_CATEGORY& aCategory, res = curl->GetBuffer(); nlohmann::json response = nlohmann::json::parse( res ); - std::string key = ""; - std::string value = ""; for( nlohmann::json& item : response ) { @@ -334,7 +333,8 @@ bool HTTP_LIB_CONNECTION::SelectAll( const HTTP_LIB_CATEGORY& aCategory, if( item.contains( "description" ) ) { // At this point we don't display anything so just set it to false - part.fields["description"] = std::make_tuple( item.at( "description" ), false ); + part.fields.push_back( std::make_pair( + "description", std::make_tuple( item.at( "description" ), false ) ) ); } // API might not want to return an optional name. diff --git a/include/http_lib/http_lib_settings.h b/include/http_lib/http_lib_settings.h index 2c099d0a0e..e27bf7657b 100644 --- a/include/http_lib/http_lib_settings.h +++ b/include/http_lib/http_lib_settings.h @@ -54,7 +54,8 @@ struct HTTP_LIB_PART std::time_t lastCached = 0; - std::map> fields; ///< additional generic fields + std::vector>> + fields; ///< additional generic fields };