Skip to content

Commit

Permalink
Refactor OpenAPIV3Schema parsing to a func
Browse files Browse the repository at this point in the history
  • Loading branch information
Kavinraja-G committed Apr 21, 2024
1 parent 41c6eeb commit 069c0e2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ func GenMarkdownDocs(cmd *cobra.Command, searchPath string) error {
return err
}

// now iterate all discovered XRDs and build XRD output map with XRName as Key
// 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 := extv1.JSONSchemaProps{}
err = json.Unmarshal(xrd.Spec.Versions[0].Schema.OpenAPIV3Schema.Raw, &openAPIV3Schema)
openAPIV3Schema, err := getOpenAPIV3Schema(xrd.Spec.Versions[0].Schema.OpenAPIV3Schema.Raw)
if err != nil {
return err
}
Expand Down Expand Up @@ -81,6 +80,17 @@ func GenMarkdownDocs(cmd *cobra.Command, searchPath string) error {
return nil
}

// getOpenAPIV3Schema parses the XRDs raw API schema as JSONSchemaProps
func getOpenAPIV3Schema(rawSchemaData []byte) (extv1.JSONSchemaProps, error) {
openAPIV3Schema := extv1.JSONSchemaProps{}
err := json.Unmarshal(rawSchemaData, &openAPIV3Schema)
if err != nil {
return openAPIV3Schema, err
}

return openAPIV3Schema, nil
}

// getXRDSpecData returns the specifications for the given XRD API
func getXRDSpecData(schema extv1.JSONSchemaProps, xrcOutputData *[]XRDSpecData, schemaPath []string, requiredFields []string) {
for propName, propValue := range schema.Properties {
Expand Down

0 comments on commit 069c0e2

Please sign in to comment.