Skip to content

Commit

Permalink
Merge pull request #200 from ericpromislow/fix-steve-readme-Collectio…
Browse files Browse the repository at this point in the history
…nFormatter-duplication

Fix the sample formatter code.
  • Loading branch information
ericpromislow authored Apr 24, 2024
2 parents b3bd0b8 + 18ff2eb commit 43fc03f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,19 +436,17 @@ 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:

```go
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"
}
}
}
Expand Down

0 comments on commit 43fc03f

Please sign in to comment.