diff --git a/cli/azd/pkg/project/project_test.go b/cli/azd/pkg/project/project_test.go index a801b49b717..c1b4e69c70b 100644 --- a/cli/azd/pkg/project/project_test.go +++ b/cli/azd/pkg/project/project_test.go @@ -1232,6 +1232,35 @@ func Test_Save(t *testing.T) { assert.Equal(t, dir, prjConfig.Path) } +func Test_Save_OmitsEmptyServiceSourceFields(t *testing.T) { + dir := t.TempDir() + filePath := filepath.Join(dir, "azure.yaml") + + prjConfig := &ProjectConfig{ + Name: "test-save", + Services: map[string]*ServiceConfig{ + "foundry": { + Host: ServiceTargetKind("azure.ai.project"), + AdditionalProperties: map[string]any{ + "endpoint": "https://account.services.ai.azure.com/api/projects/project", + }, + }, + }, + } + + err := Save(t.Context(), prjConfig, filePath) + require.NoError(t, err) + + data, err := os.ReadFile(filePath) + require.NoError(t, err) + + content := string(data) + assert.Contains(t, content, "host: azure.ai.project") + assert.Contains(t, content, "endpoint: https://account.services.ai.azure.com/api/projects/project") + assert.NotContains(t, content, "project: \"\"") + assert.NotContains(t, content, "language: \"\"") +} + func Test_Save_CustomSchemaVersion(t *testing.T) { dir := t.TempDir() filePath := filepath.Join(dir, "azure.yaml") diff --git a/cli/azd/pkg/project/service_config.go b/cli/azd/pkg/project/service_config.go index 15287519157..6672f8cdfed 100644 --- a/cli/azd/pkg/project/service_config.go +++ b/cli/azd/pkg/project/service_config.go @@ -35,11 +35,11 @@ type ServiceConfig struct { // The ARM api version to use for the service. If not specified, the latest version is used. ApiVersion string `yaml:"apiVersion,omitempty"` // The relative path to the project folder from the project root - RelativePath string `yaml:"project"` + RelativePath string `yaml:"project,omitempty"` // The azure hosting model to use, ex) appservice, function, containerapp Host ServiceTargetKind `yaml:"host"` // The programming language of the project - Language ServiceLanguageKind `yaml:"language"` + Language ServiceLanguageKind `yaml:"language,omitempty"` // The output path for build artifacts OutputPath string `yaml:"dist,omitempty"` // The source image to use for container based applications