From 18ff2ebb7a461531570e47f1dba13b439351a396 Mon Sep 17 00:00:00 2001 From: Eric Promislow Date: Mon, 22 Apr 2024 10:26:00 -0700 Subject: [PATCH] Fix the sample formatter code. --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6505400f..c91bcf98 100644 --- a/README.md +++ b/README.md @@ -436,7 +436,7 @@ then add the template to the schema factory: schemaFactory.AddTemplate(template) ``` -As another example, if you wanted to add custom field to all objects in a +As another example, if you wanted to add a custom field to all objects in a collection response, you can add a schema template with a collection formatter to omit the ID or the group and kind: @@ -444,11 +444,9 @@ to omit the ID or the group and kind: template := schema.Template{ Customize: func(schema *types.APISchema) { schema.CollectionFormatter = func(apiOp *types.APIRequest, collection *types.GenericCollection) { - schema.CollectionFormatter = func(apiOp *types.APIRequest, collection *types.GenericCollection) { - for _, d := range collection.Data { - obj := d.APIObject.Object.(*unstructured.Unstructured) - obj.Object["tag"] = "custom" - } + for _, d := range collection.Data { + obj := d.APIObject.Object.(*unstructured.Unstructured) + obj.Object["tag"] = "custom" } } }