Skip to content

Commit 023b146

Browse files
authored
Merge pull request #618 from Jougan-0/updateIntrospec
update introspec logic to check for schemaversion
2 parents 9c570ce + c4dea9f commit 023b146

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

utils/detect_pattern_file_type.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"archive/tar"
55
"bytes"
66
"compress/gzip"
7+
"encoding/json"
78
"io"
89
"regexp"
910
"strings"
@@ -31,12 +32,39 @@ func IdentifyInputType(data []byte) (string, error) {
3132

3233
// Check if the input is a Meshery design
3334
func isMesheryDesign(data []byte) bool {
34-
var mesheryPattern map[string]interface{}
35-
if err := yaml.Unmarshal(data, &mesheryPattern); err != nil {
35+
var tempMap map[string]interface{}
36+
37+
// Try unmarshaling as JSON; if it fails, try YAML
38+
if err := json.Unmarshal(data, &tempMap); err != nil {
39+
var yamlMap map[string]interface{}
40+
if yaml.Unmarshal(data, &yamlMap) != nil {
41+
return false
42+
}
43+
44+
// Convert YAML to JSON format
45+
yamlToJSON, err := json.Marshal(yamlMap)
46+
if err != nil {
47+
return false
48+
}
49+
50+
// Unmarshal JSON back into tempMap
51+
if json.Unmarshal(yamlToJSON, &tempMap) != nil {
52+
return false
53+
}
54+
}
55+
56+
// Check for schemaVersion key
57+
schemaVersion, exists := tempMap["schemaVersion"].(string)
58+
if !exists {
3659
return false
3760
}
38-
_, exists := mesheryPattern["services"]
39-
return exists
61+
62+
// Validate schemaVersion for Meshery Design
63+
if strings.HasPrefix(schemaVersion, "designs.meshery.io") {
64+
return true
65+
}
66+
67+
return false
4068
}
4169

4270
// Check if the input is a Docker Compose file

0 commit comments

Comments
 (0)