fix: add omitempty to yaml tags to prevent empty strings in azure.yaml#8873
fix: add omitempty to yaml tags to prevent empty strings in azure.yaml#8873trangevi wants to merge 2 commits into
Conversation
Fields like host, language, project (service path), and pipeline options were serialized as empty strings when not set. Adding omitempty ensures these fields are omitted from azure.yaml when they have zero values. Fixes #8862 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
📋 Prioritization NoteThanks for the contribution! The linked issue isn't in the current milestone yet. |
There was a problem hiding this comment.
Pull request overview
Reduces azure.yaml churn by omitting zero-value fields during YAML serialization, aligning ServiceConfig and PipelineOptions with existing optional-field tagging patterns.
Changes:
- Add
omitemptytoServiceConfigYAML tags forproject,host, andlanguageto avoid writing empty strings. - Add
omitemptytoPipelineOptionsYAML tags forprovider,variables, andsecretsto avoid writing empty strings/arrays.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cli/azd/pkg/project/service_config.go | Adds omitempty to service fields to prevent empty-string emission when saving azure.yaml. |
| cli/azd/pkg/project/project_config.go | Adds omitempty to pipeline options to prevent empty-string/empty-array emission when saving azure.yaml. |
jongio
left a comment
There was a problem hiding this comment.
The JSON schema at schemas/v1.0/azure.yaml.json declares host as required for services (required: ["host"]). With omitempty, services serialized with an empty host will now omit the field instead of writing host: "". This changes yaml-language-server validation behavior in editors: previously a silent empty string, now a "missing required field" warning. Both cases indicate an incomplete service config, so this is likely fine (and arguably clearer). Worth confirming the schema interaction is intentional, or if the schema should also be updated to remove host from required.
Address PR review feedback: - Revert omitempty on host tag since it is a required field that must always be present (runtime validation and JSON schema both enforce it) - Add regression tests verifying ServiceConfig and PipelineOptions marshal behavior: empty optional fields are omitted, host is preserved Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jongio
left a comment
There was a problem hiding this comment.
The host revert aligns the struct tag with both the JSON schema constraint and parseServiceHost validation. The regression tests now make this contract explicit, which will guard against accidental re-introduction of omitempty on required fields.
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
When
azdserializes project configuration back toazure.yaml, fields with zero values (empty strings, nil slices) were being written as empty strings or empty arrays. This produces noisy, confusing output -- particularly for fields likehost,language, andprojecton services, andprovider/variables/secretson pipeline options.Approach
Added
omitemptyto the yaml struct tags on the affected fields so they are omitted from the serialized output when empty:ServiceConfig(service_config.go):project,host,languagePipelineOptions(project_config.go):provider,variables,secretsThis is consistent with how all other optional fields in these structs are already tagged.
Fixes: #8862