Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow using custom markers on pkg level #95

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
czeslavo marked this conversation as resolved.
Show resolved Hide resolved
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
Loading