Skip to content

Commit

Permalink
Merge pull request #328 from MUzairS15/comp-schema
Browse files Browse the repository at this point in the history
Update spec path
  • Loading branch information
leecalcote committed Jul 19, 2023
2 parents e232aec + 7155857 commit 2f2de37
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions utils/component/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var DefaultPathConfig = CuePathConfig{
VersionPath: "spec.versions[0].name",
GroupPath: "spec.group",
ScopePath: "spec.scope",
SpecPath: "spec.versions[0].schema.openAPIV3Schema.properties.spec",
SpecPath: "spec.versions[0].schema.openAPIV3Schema",
PropertiesPath: "properties",
}

Expand All @@ -41,7 +41,7 @@ var DefaultPathConfig2 = CuePathConfig{
VersionPath: "spec.versions[0].name",
GroupPath: "spec.group",
ScopePath: "spec.scope",
SpecPath: "spec.validation.openAPIV3Schema.properties.spec",
SpecPath: "spec.validation.openAPIV3Schema",
}

var Configs = []CuePathConfig{DefaultPathConfig, DefaultPathConfig2}
Expand Down
18 changes: 18 additions & 0 deletions utils/component/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"github.com/layer5io/meshkit/utils/manifests"
)

// Remove the fields which is either not required by end user (like status) or is prefilled by system (like apiVersion, kind and metadata)
var fieldsToDelete = [4]string{"apiVersion", "kind", "status", "metadata"}

// extracts the JSONSCHEMA of the CRD and outputs the json encoded string of the schema
func getSchema(parsedCrd cue.Value, pathConf CuePathConfig) (string, error) {
schema := map[string]interface{}{}
Expand Down Expand Up @@ -35,6 +38,7 @@ func getSchema(parsedCrd cue.Value, pathConf CuePathConfig) (string, error) {
}

schema = updatedProps
DeleteFields(schema)

(schema)["title"] = manifests.FormatToReadableString(resourceId)
var output []byte
Expand All @@ -56,3 +60,17 @@ func extractCueValueFromPath(crd cue.Value, pathConf string) (string, error) {
}
return res, nil
}

// function to remove fields that are not required or prefilled
func DeleteFields(m map[string]interface{}) {
key := "properties"
if m[key] == nil {
return
}
if prop, ok := m[key].(map[string]interface{}); ok && prop != nil {
for _, f := range fieldsToDelete {
delete(prop, f)
}
m[key] = prop
}
}

0 comments on commit 2f2de37

Please sign in to comment.