Skip to content

Commit

Permalink
feat: allow using custom markers on pkg level
Browse files Browse the repository at this point in the history
  • Loading branch information
czeslavo committed Oct 17, 2024
1 parent 0ad85c5 commit 80ec94a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ render:
#### Custom Markers
You can add custom markers to your CRD types to provide additional information in the generated documentation.
You can add custom markers to your CRD types to provide additional information in the generated documentation.
For example, you can add a `hidefromdoc` marker to indicate that a type is hide from the documentation.

```yaml
Expand All @@ -108,7 +108,9 @@ render:
link: https://gateway-api.sigs.k8s.io/references/spec/#gateway.networking.k8s.io/v1beta1.SecretObjectReference
```

You can then add the `hidefromdoc` marker to the field you want to hidden from the documentation.
You can then add the `hidefromdoc` marker to the field you want to hidden from the documentation. Markers can be added
to fields, types and packages. The `target` field in the configuration specifies the target of the marker (it can be either
`field`, `type` or `package`).

```go
type Embedded1 struct {
Expand Down
12 changes: 7 additions & 5 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ var ignoredCommentRegex = regexp.MustCompile(`\s*^(?i:\+|copyright)`)
type groupVersionInfo struct {
schema.GroupVersion
*loader.Package
doc string
kinds map[string]struct{}
types types.TypeMap
doc string
kinds map[string]struct{}
types types.TypeMap
markers markers.MarkerValues
}

func Process(config *config.Config) ([]types.GroupVersionDetails, error) {
Expand Down Expand Up @@ -106,7 +107,7 @@ func Process(config *config.Config) ([]types.GroupVersionDetails, error) {
zap.S().Fatalw("Type not loaded", "type", key)
}
}

details.Markers = gvi.markers
gvDetails = append(gvDetails, details)
}

Expand Down Expand Up @@ -247,8 +248,9 @@ func (p *processor) extractGroupVersionIfExists(collector *markers.Collector, pk
Group: groupName.(string),
Version: version,
},
doc: p.extractPkgDocumentation(pkg),
Package: pkg,
doc: p.extractPkgDocumentation(pkg),
markers: markerValues,
}

return gvInfo
Expand Down
1 change: 1 addition & 0 deletions test/api/common/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@

// Package common contains common API Schema definitions
// +groupName=webapp.test.k8s.elastic.co
// +special
package common
2 changes: 2 additions & 0 deletions test/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ processor:
customMarkers:
- name: "hidefromdoc"
target: field
- name: "special"
target: package

render:
kubernetesVersion: 1.25
Expand Down
1 change: 1 addition & 0 deletions test/hide.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

Package common contains common API Schema definitions

*Important: This package is special and should be treated differently.*


#### CommonString
Expand Down
4 changes: 4 additions & 0 deletions test/templates/markdown/gv_details.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

{{ $gv.Doc }}

{{- if index $gv.Markers "special" }}
*Important: This package is special and should be treated differently.*
{{- end }}

{{- if $gv.Kinds }}
### Resource Types
{{- range $gv.SortedKinds }}
Expand Down
7 changes: 4 additions & 3 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,10 @@ func Identifier(t *Type) string {
// GroupVersionDetails encapsulates details about a discovered API group.
type GroupVersionDetails struct {
schema.GroupVersion
Doc string
Kinds []string
Types TypeMap
Doc string
Kinds []string
Types TypeMap
Markers markers.MarkerValues
}

func (gvd GroupVersionDetails) GroupVersionString() string {
Expand Down

0 comments on commit 80ec94a

Please sign in to comment.