fix: omit empty service source fields#8937
Conversation
📋 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
This PR fixes YAML serialization of azure.yaml so that resource-only service entries (e.g. host: azure.ai.project) no longer emit empty project and language fields. This matters because schema v1.0 marks the project field as false (disallowed) for resource-only AI hosts, so previously writing project: "" produced schema-invalid output. The change adds omitempty to the corresponding ServiceConfig fields and adds regression coverage.
Changes:
- Add
omitemptytoServiceConfig.RelativePath(project) andServiceConfig.Language(language) YAML tags. - Add
Test_Save_OmitsEmptyServiceSourceFieldsverifying a resource-only service serializeshost/endpointbut omits emptyproject/language.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| cli/azd/pkg/project/service_config.go | Adds omitempty to the project and language YAML tags so empty values are not written for resource-only services. |
| cli/azd/pkg/project/project_test.go | Adds a regression test asserting empty project/language are omitted while host and inline properties are preserved. |
jongio
left a comment
There was a problem hiding this comment.
Adding omitempty to the project and language struct tags is the correct fix. Both fields are string-typed (with ServiceLanguageNone = ""), so omitempty omits exactly and only the zero value. At deserialization time a missing key and an empty string both unmarshal to the same zero value, so round-tripping is safe. The regression test covers the scenario well, and the existing Test_Save already confirms populated services still serialize correctly.
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
|
/check-enforcer override |
Fixes #8938
Problem
Services that use a code-less resource host such as
host: azure.ai.projectare written toazure.yamlwith emptyproject: ""andlanguage: ""fields:These fields are invalid/meaningless for this host:
azure.yamlschema explicitly disablesprojectforazure.ai.project("project": falseinschemas/v1.0/azure.yaml.json), soproject: ""is schema-invalid and the YAML language server flags it.azure.ai.project.jsononly definesendpoint,deployments, andnetwork— it never hadprojectorlanguage.Root cause
In
cli/azd/pkg/project/service_config.go, these two fields are tagged withoutomitempty:Almost every other optional field on
ServiceConfig(resourceGroup,image,dist, ...) already usesomitempty.azure.yamlis serialized with a plainyaml.Marshalinproject.Save()(no custom marshaler), so any service with no source path/language emits the empty keys. This affects every code-less resource host (azure.ai.project,azure.ai.connection,microsoft.foundry, ...). The missingomitemptypredates code-less resource hosts, when every service had a source path + language.Change
omitemptyto theprojectandlanguageYAML tags onServiceConfig.host: azure.ai.projectservice whilehost,deployments, andendpointare preserved.Impact
Low. Only serialization of empty values changes:
project: src/api,language: python) serialize exactly as before.RelativePath == "",ServiceLanguageNone), andServiceLanguageNoneis already registered as the no-op framework service.SetConfigValue/SetConfigSection/UnsetConfig) re-save through the same path, so they no longer reintroduceproject: "".Tests
go test ./pkg/project -run Test_Savego test ./pkg/projectgo test ./internal/grpcserver -run "Save|Config|ProjectService"