-
Notifications
You must be signed in to change notification settings - Fork 3.3k
TypeSpec ready serialization #31729
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
TypeSpec ready serialization #31729
Conversation
|
Validation for Azure CLI Full Test Starting...
Thanks for your contribution! |
|
Validation for Breaking Change Starting...
Thanks for your contribution! |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
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.
Pull Request Overview
This PR adds support for serializing TypeSpec-generated SDK models in the todict utility by detecting generated models and converting their attributes.
- Introduces a new
if azure.core.serialization.is_generated_model(obj)branch to handle TypeSpec models. - Builds a camel-cased dictionary from model attributes via
as_attribute_list. - Applies an optional
post_processorto the serialized result.
Comments suppressed due to low confidence (1)
src/azure-cli-core/azure/cli/core/util.py:647
- There are no existing tests covering the new
is_generated_modelbranch. Please add unit tests to verify that TypeSpec-generated models are correctly serialized through this path.
if azure.core.serialization.is_generated_model(obj):
| result = {to_camel_case(k): todict(getattr(obj, k), post_processor) for k in azure.core.serialization.as_attribute_list(obj)} | ||
| return post_processor(obj, result) if post_processor else result # This is the only difference with knack.util.todict because for typespec generated SDKs |
Copilot
AI
Jun 26, 2025
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.
This dict comprehension is quite long and the inline comment on the next line makes it harder to read. Consider breaking it into multiple lines or moving the comment above the return statement to improve readability according to the 856 guideline.
| result = {to_camel_case(k): todict(getattr(obj, k), post_processor) for k in azure.core.serialization.as_attribute_list(obj)} | |
| return post_processor(obj, result) if post_processor else result # This is the only difference with knack.util.todict because for typespec generated SDKs | |
| result = { | |
| to_camel_case(k): todict(getattr(obj, k), post_processor) | |
| for k in azure.core.serialization.as_attribute_list(obj) | |
| } | |
| # This is the only difference with knack.util.todict because for typespec generated SDKs | |
| return post_processor(obj, result) if post_processor else result |
|
dup with #31775 |
Current email thread with @evelyn-ys , DO NOT MERGE