1
0
mirror of https://github.com/rancher/steve.git synced 2025-08-02 07:12:36 +00:00

Merge pull request #200 from ericpromislow/fix-steve-readme-CollectionFormatter-duplication

Fix the sample formatter code.
This commit is contained in:
Eric Promislow 2024-04-24 15:46:14 -07:00 committed by GitHub
commit 43fc03f64b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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"
}
}
}