Repository navigation
todict: Include additional properties of TypeSpec-generated models in command output - #34492
Бат-Орших (orshih6) wants to merge 1 commit into
Conversation
…in command output Signed-off-by: Бат-Орших <34618353+orshih6@users.noreply.github.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Thank you for your contribution Бат-Орших (@orshih6)! We will review the pull request and get back to you soon. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the change preserving additional SDK model properties in CLI output.
No open issues 🎉
What changed in this PR
Fixes #34482 by preserving additional properties from TypeSpec-generated SDK models in CLI output, including deployment-stack configuration previously rendered as {}.
Changes:
- Extends
todictto recursively convert undeclared model keys while preserving their names and declared-field precedence. - Adds SDK-dependent tests for record-style models and nested additional properties, including post-processing.
| File | Description |
|---|---|
src/azure-cli-core/azure/cli/core/util.py |
Includes additional model properties before final post-processing. |
src/azure-cli-core/azure/cli/core/tests/test_util.py |
Adds regression tests using deployment-stacks models; skips when the SDK is unavailable. |
Review effort: Balanced
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
@microsoft-github-policy-service agree |
|
Бат-Орших (@orshih6) Could you please fix the CI failure first? |
|
@x-engineering-agent[bot] The description now follows the PR template, with History Notes and the reasons for the two suppressions. I couldn't run the build check here, but azure-cli-core tests show no new failures from this change, so I think the build failed because of the format check. The title also needs the component prefix: "[Core] |
Related command
az stack group create/az stack sub create/az stack mg create(and any command whose output contains TypeSpec-generated models with additional properties)Description
The TypeSpec-model branch of
todictbuilds its output only fromattribute_list(obj), which covers declared fields only. TypeSpec models keep their data in a mapping keyed by REST name. Keys without a declared field are additional properties, and they were silently dropped. The typical case is a model defined asmodel X is Record<T>, which has no declared fields. For example,DeploymentExtensionConfigin azure-mgmt-resource-deploymentstacks always rendered as{}inaz stack group createoutput. An inlineRecord<T>property is not affected, because it deserializes to a plain dict.After converting the declared attributes,
todictnow also walks the model's keys. Any key that is not the REST name of a declared field gets added to the result, with its value converted recursively bytodict. These keys are kept as they are, the same as dict keys, and no camel-case conversion is applied. Declared fields are unchanged, so existing output doesn't change.Notes on the two suppressions:
# pylint: disable=protected-accessonobj._attr_to_rest_field: generated TypeSpec models expose no public API for the set of declared REST names. The_is_modelcheck right above already relies on the same private generator contract.self.skipTest(...)inTestTodictTypeSpecModel: the tests use real generated models fromazure-mgmt-resource-deploymentstacks. That package is installed with azure-cli but not with standalone azure-cli-core, so the tests skip when it's missing.Testing Guide
New unit tests in
src/azure-cli-core/azure/cli/core/tests/test_util.py(TestTodictTypeSpecModel):Record<T>model (DeploymentExtensionConfig) now serializes to its entries instead of{}.remove_additional_prop_layerpost-processor.History Notes
[Core] Include additional properties of TypeSpec-generated models in command output
This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.
Fixes #34482
This change was prepared with an AI coding agent (Claude) and opened automatically after an automated review, so no person has read it yet. I'm happy to make any changes you'd like.