-
Notifications
You must be signed in to change notification settings - Fork 0
Wrap optional fields in std::optional<> to match documentation #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…rser code Co-authored-by: Royna2544 <69458352+Royna2544@users.noreply.github.com>
|
@copilot #12 2.225 /usr/src/tgbot-cpp/src/TgTypeParser.cpp: In function 'nlohmann::json_abi_v3_11_3::json TgBot::put(const T&) [with T = std::shared_ptr; nlohmann::json_abi_v3_11_3::json = nlohmann::json_abi_v3_11_3::basic_json<>]': |
…rectly Co-authored-by: Royna2544 <69458352+Royna2544@users.noreply.github.com>
Fixed in d02168a. The issue was that the serialization code was calling the global |
Fix Optional Field Wrapping Issues ✅
This PR addresses fields that have "Optional" in their documentation comments but were not wrapped in
std::optional<>.Summary
Found and fixed 5 fields where comments indicated they were optional but were not properly wrapped in
std::optional<>type. These fields excluded Ptr types, which are already implicitly optional by nature (can be null).Changes Made
Header Files Modified:
std::vector<std::string> allowedUpdates→std::optional<std::vector<std::string>> allowedUpdatesstd::string inlineMessageId→std::optional<std::string> inlineMessageId(added#include <optional>)std::vector<std::string> keywords→std::optional<std::vector<std::string>> keywords(added#include <optional>)std::vector<std::int32_t> suggestedTipAmounts→std::optional<std::vector<std::int32_t>> suggestedTipAmountsstd::string caption→std::optional<std::string> captionParser Code Updates (TgTypeParser.cpp):
WebhookInfoparser to conditionally parseallowedUpdateswhen presentInputStickerparser to conditionally parsekeywordswhen presentInputInvoiceMessageContentparser to conditionally parsesuggestedTipAmountswhen presentjson.put("key", put(optional_field))tojson.put("key", optional_field)to use JsonWrapper's built-in optional supportCallbackQuery::inlineMessageIdandMessage::captionuse the existingparse()function which already handles optional types automaticallyTechnical Implementation
The changes follow the existing patterns in the codebase:
Simple optional fields (strings, primitives): The existing
parse()template function (TgTypeParser.cpp:85-100) automatically detects and handlesstd::optional<>types through SFINAE andis_optional_vtype trait.Optional vector fields: Added explicit conditional parsing with
data.contains()checks before callingparsePrimitiveArray(), as this function returns a non-optional vector.Serialization: JsonWrapper already has
put()overloads forstd::optional<T>(both primitives and vectors at lines 44-57). The fix was to pass optional fields directly tojson.put()instead of wrapping them in the globalput()function.Validation
Files Changed
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.