Skip to content

Commit

Permalink
feat: Support multiple XRD versions and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kavinraja-G committed Apr 21, 2024
1 parent 9878780 commit 15e083c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
24 changes: 16 additions & 8 deletions pkg/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,27 @@ func GenMarkdownDocs(cmd *cobra.Command, searchPath string) error {
// now iterate all discovered XRDs and build XRD output map with XR & API spec details
xrdOutputs := make(map[string]CompResourceDefinitionData)
for _, xrd := range discoveredXRDs {
openAPIV3Schema, err := getOpenAPIV3Schema(xrd.Spec.Versions[0].Schema.OpenAPIV3Schema.Raw)
if err != nil {
return err
var xrdVersions []XRDVersion
for _, version := range xrd.Spec.Versions {
openAPIV3Schema, err := getOpenAPIV3Schema(version.Schema.OpenAPIV3Schema.Raw)
if err != nil {
return err
}

var xrdOutputData []XRDSpecData
getXRDSpecData(openAPIV3Schema, &xrdOutputData, []string{}, []string{})

xrdVersions = append(xrdVersions, XRDVersion{
Version: version.Name,
XRDSpec: xrdOutputData,
})
}

var xrdOutputData []XRDSpecData
getXRDSpecData(openAPIV3Schema, &xrdOutputData, []string{}, []string{})

xrdOutputs[xrd.Spec.Names.Kind] = CompResourceDefinitionData{
Name: xrd.Name,
CompositeResourceKind: xrd.Spec.Names.Kind,
ClaimNameKind: xrd.Spec.ClaimNames.Kind,
XRDSpec: xrdOutputData,
Versions: xrdVersions,
}
}

Expand All @@ -68,7 +76,7 @@ func GenMarkdownDocs(cmd *cobra.Command, searchPath string) error {
XRAPIVersion: comp.Spec.CompositeTypeRef.APIVersion,
XRKind: comp.Spec.CompositeTypeRef.Kind,
Resources: resources,
LinkedXRDData: xrdOutputs[comp.Spec.CompositeTypeRef.Kind],
LinkedXRD: xrdOutputs[comp.Spec.CompositeTypeRef.Kind],
})
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ var markdownGenericTemplate = `
#### XRD
| Name | Claim |
|------|-------|
| {{ .LinkedXRDData.Name }} | {{ .LinkedXRDData.ClaimNameKind }} |
| {{ .LinkedXRD.Name }} | {{ .LinkedXRD.ClaimNameKind }} |
#### XRD Spec
{{- range .LinkedXRD.Versions }}
##### Version: {{ .Version }}
| Field | Path | Type | Description | Required |
|------|-------|------|-------|-------|
{{- range .LinkedXRDData.XRDSpec }}
{{- range .XRDSpec }}
| {{ .FieldName }} | {{ .Path }} | {{ .Type }} | {{ .Description }} | {{ .Required }} |
{{- end }}
{{- end }}
#### Resources
| Name | Kind | API Version |
|------|------|-------------|
Expand Down
24 changes: 16 additions & 8 deletions pkg/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ type CompResourceData struct {
APIVersion string
}

type CompResourceDefinitionData struct {
Name string
CompositeResourceKind string
ClaimNameKind string
XRDSpec []XRDSpecData
}

// XRDSpecData struct for API specs in the output
type XRDSpecData struct {
FieldName string
Path string
Expand All @@ -21,11 +15,25 @@ type XRDSpecData struct {
Required bool
}

// XRDVersion used for representing individual API versions
type XRDVersion struct {
Version string
XRDSpec []XRDSpecData
}

// CompResourceDefinitionData defines the XRD data and its XR, XRC details if any
type CompResourceDefinitionData struct {
Name string
CompositeResourceKind string
ClaimNameKind string
Versions []XRDVersion
}

// MarkdownOutputData output data struct used by markdown generator
type MarkdownOutputData struct {
CompositionName string
XRAPIVersion string
XRKind string
Resources []CompResourceData
LinkedXRDData CompResourceDefinitionData
LinkedXRD CompResourceDefinitionData
}
1 change: 1 addition & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
|------|-------|
| xjetpostgresqls.database.wk | JetPostgreSQL |
#### XRD Spec
##### Version: v1alpha1
| Field | Path | Type | Description | Required |
|------|-------|------|-------|-------|
| spec | | object | Required spec field for your API | false |
Expand Down

0 comments on commit 15e083c

Please sign in to comment.