diff --git a/mmv1/openapi_generate/parser.go b/mmv1/openapi_generate/parser.go index 6a337894c138..c58c11eb3c25 100644 --- a/mmv1/openapi_generate/parser.go +++ b/mmv1/openapi_generate/parser.go @@ -394,12 +394,17 @@ func attachStandardFunctionality(resource api.Resource) api.Resource { resource.IdFormat = resource.SelfLink resource.ImportFormat = []string{resource.SelfLink} - example := r.Examples{} - example.Name = "name_of_example_file" - example.PrimaryResourceId = "example" - example.Vars = map[string]string{"resource_name": "test-resource"} + sample := r.Sample{} + sample.Name = "name_of_sample_file" + sample.PrimaryResourceId = "example" - resource.Examples = []*r.Examples{&example} + step := r.Step{} + step.Name = "name_of_sample_file" + step.Vars = map[string]string{"resource_name": "test-resource"} + + sample.Steps = []*r.Step{&step} + + resource.Samples = []*r.Sample{&sample} resourceNameBytes := []byte(resource.Name) // Write the status as an encoded string to flag when a YAML file has been diff --git a/mmv1/openapi_generate/parser_test.go b/mmv1/openapi_generate/parser_test.go index 5660430fb66d..a42f43a88533 100644 --- a/mmv1/openapi_generate/parser_test.go +++ b/mmv1/openapi_generate/parser_test.go @@ -169,3 +169,42 @@ func TestReadOnlyPropagation(t *testing.T) { } } } + +func TestAttachStandardFunctionality(t *testing.T) { + resource := api.Resource{ + Name: "TestResource", + SelfLink: "test/self/link", + } + + result := attachStandardFunctionality(resource) + + if len(result.Examples) != 0 { + t.Errorf("Expected result.Examples to be empty, got: %d examples", len(result.Examples)) + } + + if len(result.Samples) != 1 { + t.Fatalf("Expected result.Samples to have length 1, got: %d", len(result.Samples)) + } + + sample := result.Samples[0] + if sample.Name != "name_of_sample_file" { + t.Errorf("Expected sample.Name to be 'name_of_sample_file', got: %q", sample.Name) + } + + if sample.PrimaryResourceId != "example" { + t.Errorf("Expected sample.PrimaryResourceId to be 'example', got: %q", sample.PrimaryResourceId) + } + + if len(sample.Steps) != 1 { + t.Fatalf("Expected sample.Steps to have length 1, got: %d", len(sample.Steps)) + } + + step := sample.Steps[0] + if step.Name != "name_of_sample_file" { + t.Errorf("Expected step.Name to be 'name_of_sample_file', got: %q", step.Name) + } + + if val, ok := step.Vars["resource_name"]; !ok || val != "test-resource" { + t.Errorf("Expected step.Vars['resource_name'] to be 'test-resource', got: %q (present=%t)", val, ok) + } +}