MCPcopy
hub / github.com/superplanehq/superplane / validateExampleEnvelope

Function validateExampleEnvelope

pkg/lint/examplepayloads/checker.go:1012–1072  ·  view source on GitHub ↗
(example exampleRecord)

Source from the content-addressed store, hash-verified

1010}
1011
1012func validateExampleEnvelope(example exampleRecord) []Issue {
1013 var issues []Issue
1014
1015 if example.Payload == nil || len(example.Payload) == 0 {
1016 return []Issue{{
1017 Name: example.Name,
1018 Kind: example.Kind,
1019 Message: "example payload is empty",
1020 }}
1021 }
1022
1023 requiredKeys := []string{"data", "timestamp", "type"}
1024 for _, key := range requiredKeys {
1025 if _, ok := example.Payload[key]; !ok {
1026 issues = append(issues, Issue{
1027 Name: example.Name,
1028 Kind: example.Kind,
1029 Message: fmt.Sprintf("example payload must include top-level %q", key),
1030 })
1031 }
1032 }
1033
1034 rawType, ok := example.Payload["type"]
1035 if !ok {
1036 return issues
1037 }
1038
1039 payloadType, ok := rawType.(string)
1040 if !ok || strings.TrimSpace(payloadType) == "" {
1041 issues = append(issues, Issue{
1042 Name: example.Name,
1043 Kind: example.Kind,
1044 Message: "example payload type must be a non-empty string",
1045 })
1046 }
1047
1048 rawTimestamp, ok := example.Payload["timestamp"]
1049 if !ok {
1050 return issues
1051 }
1052
1053 timestamp, ok := rawTimestamp.(string)
1054 if !ok || strings.TrimSpace(timestamp) == "" {
1055 issues = append(issues, Issue{
1056 Name: example.Name,
1057 Kind: example.Kind,
1058 Message: "example payload timestamp must be a non-empty string",
1059 })
1060 return issues
1061 }
1062
1063 if _, err := time.Parse(time.RFC3339Nano, timestamp); err != nil {
1064 issues = append(issues, Issue{
1065 Name: example.Name,
1066 Kind: example.Kind,
1067 Message: fmt.Sprintf("example payload timestamp must be RFC3339/RFC3339Nano: %v", err),
1068 })
1069 }

Callers 1

RunFunction · 0.85

Calls 1

ParseMethod · 0.80

Tested by

no test coverage detected