diff --git a/pkg/markdown.go b/pkg/markdown.go index f91fd97..2dcf40d 100644 --- a/pkg/markdown.go +++ b/pkg/markdown.go @@ -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, } } @@ -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], }) } diff --git a/pkg/templates.go b/pkg/templates.go index ea04f76..ff5d2b2 100644 --- a/pkg/templates.go +++ b/pkg/templates.go @@ -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 | |------|------|-------------| diff --git a/pkg/types.go b/pkg/types.go index 6969e45..279cd01 100644 --- a/pkg/types.go +++ b/pkg/types.go @@ -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 @@ -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 } diff --git a/samples/README.md b/samples/README.md index 01e7913..e3f0ab2 100644 --- a/samples/README.md +++ b/samples/README.md @@ -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 |