-
Notifications
You must be signed in to change notification settings - Fork 142
Made sure the Description and Validated retain optional; fixes #503 #508
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
Summary of ChangesHello @liuzicheng1987, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where the JSON schema generation logic failed to correctly identify optional types when they were nested within Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly extends the is_optional
function to recursively check for optional types within Description
and Validated
wrappers. This ensures that fields using these wrappers with an optional underlying type are not incorrectly marked as 'required' in the generated JSON schema. The new test case test_json_schema5
effectively validates this fix.
The implementation is clean and uses if constexpr
for compile-time branching, which is efficient. I have one minor suggestion to improve the code.
On a related note, I observed that the schema generated for the age
field in the new test, which is a Validator
over an std::optional
, does not seem to include null
as a possible type. This might be a separate issue worth investigating to ensure the generated schema fully reflects the optionality of validated fields.
return _t.variant_.visit([&](const auto& _v) -> bool { | ||
using T = std::remove_cvref_t<decltype(_v)>; | ||
return std::is_same<T, parsing::schema::Type::Optional>(); | ||
}; | ||
return rfl::visit(handle, _t.variant_); | ||
if constexpr (std::is_same_v<T, parsing::schema::Type::Description>) { | ||
return is_optional(*_v.type_); | ||
|
||
} else if constexpr (std::is_same_v<T, parsing::schema::Type::Validated>) { | ||
return is_optional(*_v.type_); | ||
|
||
} else { | ||
return std::is_same_v<T, parsing::schema::Type::Optional>; | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lambda capture [&]
is not necessary here as the lambda body does not access any variables from the enclosing scope. The recursive call to is_optional
is a call to a free function and does not require a capture. It's good practice to use a non-capturing lambda []
when no captures are needed as it can sometimes lead to better compiler optimizations.
return _t.variant_.visit([&](const auto& _v) -> bool { | |
using T = std::remove_cvref_t<decltype(_v)>; | |
return std::is_same<T, parsing::schema::Type::Optional>(); | |
}; | |
return rfl::visit(handle, _t.variant_); | |
if constexpr (std::is_same_v<T, parsing::schema::Type::Description>) { | |
return is_optional(*_v.type_); | |
} else if constexpr (std::is_same_v<T, parsing::schema::Type::Validated>) { | |
return is_optional(*_v.type_); | |
} else { | |
return std::is_same_v<T, parsing::schema::Type::Optional>; | |
} | |
}); | |
return _t.variant_.visit([](const auto& _v) -> bool { | |
using T = std::remove_cvref_t<decltype(_v)>; | |
if constexpr (std::is_same_v<T, parsing::schema::Type::Description>) { | |
return is_optional(*_v.type_); | |
} else if constexpr (std::is_same_v<T, parsing::schema::Type::Validated>) { | |
return is_optional(*_v.type_); | |
} else { | |
return std::is_same_v<T, parsing::schema::Type::Optional>; | |
} | |
}); |
No description provided.