Skip to content

Instantly share code, notes, and snippets.

@parsiya
Last active November 1, 2022 08:16
Show Gist options
  • Save parsiya/f005bcd5e692b3086dbfd60cb67dc943 to your computer and use it in GitHub Desktop.
Save parsiya/f005bcd5e692b3086dbfd60cb67dc943 to your computer and use it in GitHub Desktop.
Adventures in Converting Semgrep Output JSON Schema to Go Structs

Draft 2020-12

Located at https://github.com/returntocorp/semgrep-interfaces/blob/main/semgrep_output_v0.jsonschema.

This draft is too advanced so most libraries cannot parse it.

atombender/go-jsonschema CAN get something IF we use the master branch (and not the latest tagged version).

The lastest tagged version gets this error

$ go install github.com/atombender/go-jsonschema/cmd/gojsonschema@mlatest

$ gojsonschema -p main -o semgrep-result.go --verbose semgrep_output_v0.jsonschema
gojsonschema: Loading semgrep_output_v0.jsonschema
gojsonschema: Failed: error parsing from file semgrep_output_v0.jsonschema: json: cannot unmarshal bool into Go struct field Type.definitions.oneOf.items of type schemas.Type

But the latest commit from master does more:

$ go install github.com/atombender/go-jsonschema/cmd/gojsonschema@master

$ gojsonschema -p main -o semgrep_result.go --verbose semgrep_output_v0.jsonschema
gojsonschema: Loading semgrep_output_v0.jsonschema
gojsonschema: Warning: Property has multiple types; will be represented as interface{} with no validation
gojsonschema: Warning: Property has multiple types; will be represented as interface{} with no validation
gojsonschema: Warning: Property has multiple types; will be represented as interface{} with no validation
gojsonschema: Warning: Multiple types map to the name "CliMatchExtra"; declaring duplicate as "CliMatchExtra_1" instead
gojsonschema: Warning: Cycle detected; must wrap type MatchingExplanation in pointer
gojsonschema: Warning: Multiple types map to the name "CoreMatchExtra"; declaring duplicate as "CoreMatchExtra_1" instead
gojsonschema: Writing semgrep_result.go

See go-jsonschema_semgrep_result.go file below. See how problematic stuff like CoreErrorKind are handwaved as interface{} (line 229).

Everything else returns a similar error. Apparently, it's because they might not support the draft 2020-12 versions.

For example, a-h/generate. Getting this to install is tricky, because the instructions use go get which has been deprecated for quite some time.

$ git clone https://github.com/a-h/generate --depth=1
$ cd generate
# the mod name is not important, you can use whatever you want
$ go mod init github.com/a-h/generate
$ go mod tidy
$ go get github.com/a-h/generate
$ make

Now, we have the schema-generate executable here.

$ ./schema-generate -p main -o ../generate.go ../semgrep_output_v0.jsonschema
the JSON type 'bool' cannot be converted into the Go 'Schema' type on struct 'Schema', field 'Definitions.OneOf.Items'. See input file ../semgrep_output_v0.jsonschema line 128, character 26

Seems like our issue is about implementing OneOf.Items. One of the pull requests mention fixing it and it didn't work either.

$ git clone https://github.com/lustefaniak/generate/ generate-oneoff --depth=1 -b optional-one-off
$ cd generate-oneoff
# the mod name is not important, you can use whatever you want
$ go mod init github.com/lustefaniak/generate
$ go mod tidy
$ make

https://git.sr.ht/~emersion/go-jsonschema supposedly supports Draft 2020-12 but just generates this useless struct (for both versions):

package main

type Root map[string]interface{}

Draft-07

Martin kindly provided a version of the JSONSchema in the Draft-07 version: https://github.com/returntocorp/semgrep-interfaces/blob/mj-jsonschema-2019/semgrep_output_v0.jsonschema-draft-07

I could get it to work was in https://app.quicktype.io/. It omitted some structs.

You can see the result in the semgrep_results_quicktype-io.go file below.

Everything else still had issues (even the master version of gojsonschema that worked with the 2020-12 version above.

$ ./schema-generate -p main -o ../generate_3.go ../semgrep_output_v0.jsonschema-draft-07
the JSON type 'array' cannot be converted into the Go 'Schema' type on struct 'Schema', field 'Definitions.OneOf.Items'. See input file ../semgrep_output_v0.jsonschema-draft-07 line 130, character 1

Which is:

    "core_error_kind": {
      "oneOf": [
        { "const": "Lexical error" },
        { "const": "Syntax error" },
        { "const": "Other syntax error" },
        { "const": "AST builder error" },
        { "const": "Rule parse error" },
        {
          "type": "array",
          "minItems": 2,
          "additionalItems": false,
          "items": [ // <--- HERE
            { "const": "Pattern parse error" },
            { "type": "array", "items": { "type": "string" } }
          ]

Anyways, this is where I rage quit. I think I have enough structs to do what I want because I don't care about the errors at this point.

// Code generated by github.com/atombender/go-jsonschema, DO NOT EDIT.
// $ go install github.com/atombender/go-jsonschema/cmd/gojsonschema@master
// $ gojsonschema -p main -o semgrep_result.go --verbose semgrep_output_v0.jsonschema
package main
import "fmt"
import "encoding/json"
type ApiScansFindings struct {
// CaiIds corresponds to the JSON schema field "cai_ids".
CaiIds []string `json:"cai_ids" yaml:"cai_ids"`
// Findings corresponds to the JSON schema field "findings".
Findings []Finding `json:"findings" yaml:"findings"`
// GitlabToken corresponds to the JSON schema field "gitlab_token".
GitlabToken interface{} `json:"gitlab_token" yaml:"gitlab_token"`
// RuleIds corresponds to the JSON schema field "rule_ids".
RuleIds []string `json:"rule_ids" yaml:"rule_ids"`
// SearchedPaths corresponds to the JSON schema field "searched_paths".
SearchedPaths []string `json:"searched_paths" yaml:"searched_paths"`
// Token corresponds to the JSON schema field "token".
Token interface{} `json:"token" yaml:"token"`
}
type CliError struct {
// Code corresponds to the JSON schema field "code".
Code int `json:"code" yaml:"code"`
// Help corresponds to the JSON schema field "help".
Help *string `json:"help,omitempty" yaml:"help,omitempty"`
// Level corresponds to the JSON schema field "level".
Level string `json:"level" yaml:"level"`
// LongMsg corresponds to the JSON schema field "long_msg".
LongMsg *string `json:"long_msg,omitempty" yaml:"long_msg,omitempty"`
// Message corresponds to the JSON schema field "message".
Message *string `json:"message,omitempty" yaml:"message,omitempty"`
// Path corresponds to the JSON schema field "path".
Path *string `json:"path,omitempty" yaml:"path,omitempty"`
// RuleId corresponds to the JSON schema field "rule_id".
RuleId *RuleId `json:"rule_id,omitempty" yaml:"rule_id,omitempty"`
// ShortMsg corresponds to the JSON schema field "short_msg".
ShortMsg *string `json:"short_msg,omitempty" yaml:"short_msg,omitempty"`
// Spans corresponds to the JSON schema field "spans".
Spans []ErrorSpan `json:"spans,omitempty" yaml:"spans,omitempty"`
// Type corresponds to the JSON schema field "type".
Type string `json:"type" yaml:"type"`
}
type CliMatch struct {
// CheckId corresponds to the JSON schema field "check_id".
CheckId RuleId `json:"check_id" yaml:"check_id"`
// End corresponds to the JSON schema field "end".
End Position `json:"end" yaml:"end"`
// Extra corresponds to the JSON schema field "extra".
Extra CliMatchExtra_1 `json:"extra" yaml:"extra"`
// Path corresponds to the JSON schema field "path".
Path string `json:"path" yaml:"path"`
// Start corresponds to the JSON schema field "start".
Start Position `json:"start" yaml:"start"`
}
type CliMatchDataflowTrace struct {
// IntermediateVars corresponds to the JSON schema field "intermediate_vars".
IntermediateVars []CliMatchIntermediateVar `json:"intermediate_vars,omitempty" yaml:"intermediate_vars,omitempty"`
// TaintSource corresponds to the JSON schema field "taint_source".
TaintSource *CliMatchTaintSource `json:"taint_source,omitempty" yaml:"taint_source,omitempty"`
}
type CliMatchExtraMetadata interface{}
type CliMatchExtra_1 struct {
// DataflowTrace corresponds to the JSON schema field "dataflow_trace".
DataflowTrace *CliMatchDataflowTrace `json:"dataflow_trace,omitempty" yaml:"dataflow_trace,omitempty"`
// Fingerprint corresponds to the JSON schema field "fingerprint".
Fingerprint string `json:"fingerprint" yaml:"fingerprint"`
// Fix corresponds to the JSON schema field "fix".
Fix *string `json:"fix,omitempty" yaml:"fix,omitempty"`
// FixRegex corresponds to the JSON schema field "fix_regex".
FixRegex *FixRegex `json:"fix_regex,omitempty" yaml:"fix_regex,omitempty"`
// FixedLines corresponds to the JSON schema field "fixed_lines".
FixedLines []string `json:"fixed_lines,omitempty" yaml:"fixed_lines,omitempty"`
// IsIgnored corresponds to the JSON schema field "is_ignored".
IsIgnored *bool `json:"is_ignored,omitempty" yaml:"is_ignored,omitempty"`
// Lines corresponds to the JSON schema field "lines".
Lines string `json:"lines" yaml:"lines"`
// Message corresponds to the JSON schema field "message".
Message string `json:"message" yaml:"message"`
// Metadata corresponds to the JSON schema field "metadata".
Metadata CliMatchExtraMetadata `json:"metadata" yaml:"metadata"`
// Metavars corresponds to the JSON schema field "metavars".
Metavars Metavars `json:"metavars,omitempty" yaml:"metavars,omitempty"`
// ScaInfo corresponds to the JSON schema field "sca_info".
ScaInfo *ScaInfo `json:"sca_info,omitempty" yaml:"sca_info,omitempty"`
// Severity corresponds to the JSON schema field "severity".
Severity string `json:"severity" yaml:"severity"`
}
type CliMatchIntermediateVar struct {
// Content corresponds to the JSON schema field "content".
Content string `json:"content" yaml:"content"`
// Location corresponds to the JSON schema field "location".
Location Location `json:"location" yaml:"location"`
}
type CliMatchTaintSource struct {
// Content corresponds to the JSON schema field "content".
Content string `json:"content" yaml:"content"`
// Location corresponds to the JSON schema field "location".
Location Location `json:"location" yaml:"location"`
}
type CliOutputExtra struct {
// Explanations corresponds to the JSON schema field "explanations".
Explanations []MatchingExplanation `json:"explanations,omitempty" yaml:"explanations,omitempty"`
// Paths corresponds to the JSON schema field "paths".
Paths CliPaths `json:"paths" yaml:"paths"`
// Time corresponds to the JSON schema field "time".
Time *CliTiming `json:"time,omitempty" yaml:"time,omitempty"`
}
type CliPaths struct {
// Comment corresponds to the JSON schema field "_comment".
Comment *string `json:"_comment,omitempty" yaml:"_comment,omitempty"`
// Scanned corresponds to the JSON schema field "scanned".
Scanned []string `json:"scanned" yaml:"scanned"`
// Skipped corresponds to the JSON schema field "skipped".
Skipped []CliSkippedTarget `json:"skipped,omitempty" yaml:"skipped,omitempty"`
}
type CliSkippedTarget struct {
// Path corresponds to the JSON schema field "path".
Path string `json:"path" yaml:"path"`
// Reason corresponds to the JSON schema field "reason".
Reason string `json:"reason" yaml:"reason"`
}
type CliTargetTimes struct {
// MatchTimes corresponds to the JSON schema field "match_times".
MatchTimes []float64 `json:"match_times" yaml:"match_times"`
// NumBytes corresponds to the JSON schema field "num_bytes".
NumBytes int `json:"num_bytes" yaml:"num_bytes"`
// ParseTimes corresponds to the JSON schema field "parse_times".
ParseTimes []float64 `json:"parse_times" yaml:"parse_times"`
// Path corresponds to the JSON schema field "path".
Path string `json:"path" yaml:"path"`
// RunTime corresponds to the JSON schema field "run_time".
RunTime float64 `json:"run_time" yaml:"run_time"`
}
type CliTiming struct {
// ProfilingTimes corresponds to the JSON schema field "profiling_times".
ProfilingTimes CliTimingProfilingTimes `json:"profiling_times" yaml:"profiling_times"`
// Rules corresponds to the JSON schema field "rules".
Rules []RuleIdDict `json:"rules" yaml:"rules"`
// RulesParseTime corresponds to the JSON schema field "rules_parse_time".
RulesParseTime float64 `json:"rules_parse_time" yaml:"rules_parse_time"`
// Targets corresponds to the JSON schema field "targets".
Targets []CliTargetTimes `json:"targets" yaml:"targets"`
// TotalBytes corresponds to the JSON schema field "total_bytes".
TotalBytes int `json:"total_bytes" yaml:"total_bytes"`
}
type CliTimingProfilingTimes map[string]float64
type CoreError struct {
// Details corresponds to the JSON schema field "details".
Details *string `json:"details,omitempty" yaml:"details,omitempty"`
// ErrorType corresponds to the JSON schema field "error_type".
ErrorType CoreErrorErrorType `json:"error_type" yaml:"error_type"`
// Location corresponds to the JSON schema field "location".
Location Location `json:"location" yaml:"location"`
// Message corresponds to the JSON schema field "message".
Message string `json:"message" yaml:"message"`
// RuleId corresponds to the JSON schema field "rule_id".
RuleId *RuleId `json:"rule_id,omitempty" yaml:"rule_id,omitempty"`
// Severity corresponds to the JSON schema field "severity".
Severity CoreErrorSeverity `json:"severity" yaml:"severity"`
}
type CoreErrorErrorType interface{}
type CoreErrorKind interface{}
type CoreErrorSeverity interface{}
type CoreMatch struct {
// Extra corresponds to the JSON schema field "extra".
Extra CoreMatchExtra_1 `json:"extra" yaml:"extra"`
// Location corresponds to the JSON schema field "location".
Location Location `json:"location" yaml:"location"`
// RuleId corresponds to the JSON schema field "rule_id".
RuleId RuleId `json:"rule_id" yaml:"rule_id"`
}
type CoreMatchDataflowTrace struct {
// IntermediateVars corresponds to the JSON schema field "intermediate_vars".
IntermediateVars []CoreMatchIntermediateVar `json:"intermediate_vars,omitempty" yaml:"intermediate_vars,omitempty"`
// TaintSource corresponds to the JSON schema field "taint_source".
TaintSource *Location `json:"taint_source,omitempty" yaml:"taint_source,omitempty"`
}
type CoreMatchExtra_1 struct {
// DataflowTrace corresponds to the JSON schema field "dataflow_trace".
DataflowTrace *CoreMatchDataflowTrace `json:"dataflow_trace,omitempty" yaml:"dataflow_trace,omitempty"`
// Message corresponds to the JSON schema field "message".
Message *string `json:"message,omitempty" yaml:"message,omitempty"`
// Metavars corresponds to the JSON schema field "metavars".
Metavars Metavars `json:"metavars" yaml:"metavars"`
// RenderedFix corresponds to the JSON schema field "rendered_fix".
RenderedFix *string `json:"rendered_fix,omitempty" yaml:"rendered_fix,omitempty"`
}
type CoreMatchIntermediateVar struct {
// Location corresponds to the JSON schema field "location".
Location Location `json:"location" yaml:"location"`
}
type CoreMatchResults struct {
// Errors corresponds to the JSON schema field "errors".
Errors []CoreError `json:"errors" yaml:"errors"`
// Explanations corresponds to the JSON schema field "explanations".
Explanations []MatchingExplanation `json:"explanations,omitempty" yaml:"explanations,omitempty"`
// Matches corresponds to the JSON schema field "matches".
Matches []CoreMatch `json:"matches" yaml:"matches"`
// Skipped corresponds to the JSON schema field "skipped".
Skipped []SkippedTarget `json:"skipped,omitempty" yaml:"skipped,omitempty"`
// SkippedRules corresponds to the JSON schema field "skipped_rules".
SkippedRules []SkippedRule `json:"skipped_rules,omitempty" yaml:"skipped_rules,omitempty"`
// Stats corresponds to the JSON schema field "stats".
Stats CoreStats `json:"stats" yaml:"stats"`
// Time corresponds to the JSON schema field "time".
Time *CoreTiming `json:"time,omitempty" yaml:"time,omitempty"`
}
type CoreSeverity interface{}
type CoreStats struct {
// Errorfiles corresponds to the JSON schema field "errorfiles".
Errorfiles int `json:"errorfiles" yaml:"errorfiles"`
// Okfiles corresponds to the JSON schema field "okfiles".
Okfiles int `json:"okfiles" yaml:"okfiles"`
}
type CoreTiming struct {
// Rules corresponds to the JSON schema field "rules".
Rules []RuleId `json:"rules" yaml:"rules"`
// RulesParseTime corresponds to the JSON schema field "rules_parse_time".
RulesParseTime *float64 `json:"rules_parse_time,omitempty" yaml:"rules_parse_time,omitempty"`
// Targets corresponds to the JSON schema field "targets".
Targets []TargetTime `json:"targets" yaml:"targets"`
}
type CveResult struct {
// Filename corresponds to the JSON schema field "filename".
Filename string `json:"filename" yaml:"filename"`
// Funcnames corresponds to the JSON schema field "funcnames".
Funcnames []string `json:"funcnames" yaml:"funcnames"`
// Url corresponds to the JSON schema field "url".
Url string `json:"url" yaml:"url"`
}
type CveResults []CveResult
type DependencyMatch struct {
// DependencyPattern corresponds to the JSON schema field "dependency_pattern".
DependencyPattern DependencyPattern `json:"dependency_pattern" yaml:"dependency_pattern"`
// FoundDependency corresponds to the JSON schema field "found_dependency".
FoundDependency FoundDependency `json:"found_dependency" yaml:"found_dependency"`
// Lockfile corresponds to the JSON schema field "lockfile".
Lockfile string `json:"lockfile" yaml:"lockfile"`
}
type DependencyPattern struct {
// Ecosystem corresponds to the JSON schema field "ecosystem".
Ecosystem DependencyPatternEcosystem `json:"ecosystem" yaml:"ecosystem"`
// Package corresponds to the JSON schema field "package".
Package string `json:"package" yaml:"package"`
// SemverRange corresponds to the JSON schema field "semver_range".
SemverRange string `json:"semver_range" yaml:"semver_range"`
}
type DependencyPatternEcosystem interface{}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CliTiming) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["profiling_times"]; !ok || v == nil {
return fmt.Errorf("field profiling_times in CliTiming: required")
}
if v, ok := raw["rules"]; !ok || v == nil {
return fmt.Errorf("field rules in CliTiming: required")
}
if v, ok := raw["rules_parse_time"]; !ok || v == nil {
return fmt.Errorf("field rules_parse_time in CliTiming: required")
}
if v, ok := raw["targets"]; !ok || v == nil {
return fmt.Errorf("field targets in CliTiming: required")
}
if v, ok := raw["total_bytes"]; !ok || v == nil {
return fmt.Errorf("field total_bytes in CliTiming: required")
}
type Plain CliTiming
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CliTiming(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CliError) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["code"]; !ok || v == nil {
return fmt.Errorf("field code in CliError: required")
}
if v, ok := raw["level"]; !ok || v == nil {
return fmt.Errorf("field level in CliError: required")
}
if v, ok := raw["type"]; !ok || v == nil {
return fmt.Errorf("field type in CliError: required")
}
type Plain CliError
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CliError(plain)
return nil
}
type FixRegex struct {
// Count corresponds to the JSON schema field "count".
Count *int `json:"count,omitempty" yaml:"count,omitempty"`
// Regex corresponds to the JSON schema field "regex".
Regex string `json:"regex" yaml:"regex"`
// Replacement corresponds to the JSON schema field "replacement".
Replacement string `json:"replacement" yaml:"replacement"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *FixRegex) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["regex"]; !ok || v == nil {
return fmt.Errorf("field regex in FixRegex: required")
}
if v, ok := raw["replacement"]; !ok || v == nil {
return fmt.Errorf("field replacement in FixRegex: required")
}
type Plain FixRegex
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = FixRegex(plain)
return nil
}
type FoundDependencyEcosystem interface{}
type SvalueValue struct {
// SvalueAbstractContent corresponds to the JSON schema field
// "svalue_abstract_content".
SvalueAbstractContent string `json:"svalue_abstract_content" yaml:"svalue_abstract_content"`
// SvalueEnd corresponds to the JSON schema field "svalue_end".
SvalueEnd *Position `json:"svalue_end,omitempty" yaml:"svalue_end,omitempty"`
// SvalueStart corresponds to the JSON schema field "svalue_start".
SvalueStart *Position `json:"svalue_start,omitempty" yaml:"svalue_start,omitempty"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *SvalueValue) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["svalue_abstract_content"]; !ok || v == nil {
return fmt.Errorf("field svalue_abstract_content in SvalueValue: required")
}
type Plain SvalueValue
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = SvalueValue(plain)
return nil
}
type MetavarValue struct {
// AbstractContent corresponds to the JSON schema field "abstract_content".
AbstractContent string `json:"abstract_content" yaml:"abstract_content"`
// End corresponds to the JSON schema field "end".
End Position `json:"end" yaml:"end"`
// PropagatedValue corresponds to the JSON schema field "propagated_value".
PropagatedValue *SvalueValue `json:"propagated_value,omitempty" yaml:"propagated_value,omitempty"`
// Start corresponds to the JSON schema field "start".
Start Position `json:"start" yaml:"start"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *MetavarValue) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["abstract_content"]; !ok || v == nil {
return fmt.Errorf("field abstract_content in MetavarValue: required")
}
if v, ok := raw["end"]; !ok || v == nil {
return fmt.Errorf("field end in MetavarValue: required")
}
if v, ok := raw["start"]; !ok || v == nil {
return fmt.Errorf("field start in MetavarValue: required")
}
type Plain MetavarValue
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = MetavarValue(plain)
return nil
}
type FoundDependencyAllowedHashes map[string][]string
type Metavars map[string]MetavarValue
// UnmarshalJSON implements json.Unmarshaler.
func (j *CliMatchExtra_1) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["fingerprint"]; !ok || v == nil {
return fmt.Errorf("field fingerprint in CliMatchExtra_1: required")
}
if v, ok := raw["lines"]; !ok || v == nil {
return fmt.Errorf("field lines in CliMatchExtra_1: required")
}
if v, ok := raw["message"]; !ok || v == nil {
return fmt.Errorf("field message in CliMatchExtra_1: required")
}
if v, ok := raw["metadata"]; !ok || v == nil {
return fmt.Errorf("field metadata in CliMatchExtra_1: required")
}
if v, ok := raw["severity"]; !ok || v == nil {
return fmt.Errorf("field severity in CliMatchExtra_1: required")
}
type Plain CliMatchExtra_1
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CliMatchExtra_1(plain)
return nil
}
type FoundDependency struct {
// AllowedHashes corresponds to the JSON schema field "allowed_hashes".
AllowedHashes FoundDependencyAllowedHashes `json:"allowed_hashes" yaml:"allowed_hashes"`
// Ecosystem corresponds to the JSON schema field "ecosystem".
Ecosystem FoundDependencyEcosystem `json:"ecosystem" yaml:"ecosystem"`
// LineNumber corresponds to the JSON schema field "line_number".
LineNumber *int `json:"line_number,omitempty" yaml:"line_number,omitempty"`
// Package corresponds to the JSON schema field "package".
Package string `json:"package" yaml:"package"`
// ResolvedUrl corresponds to the JSON schema field "resolved_url".
ResolvedUrl *string `json:"resolved_url,omitempty" yaml:"resolved_url,omitempty"`
// Transitivity corresponds to the JSON schema field "transitivity".
Transitivity FoundDependencyTransitivity `json:"transitivity" yaml:"transitivity"`
// Version corresponds to the JSON schema field "version".
Version string `json:"version" yaml:"version"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CliMatch) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["check_id"]; !ok || v == nil {
return fmt.Errorf("field check_id in CliMatch: required")
}
if v, ok := raw["end"]; !ok || v == nil {
return fmt.Errorf("field end in CliMatch: required")
}
if v, ok := raw["extra"]; !ok || v == nil {
return fmt.Errorf("field extra in CliMatch: required")
}
if v, ok := raw["path"]; !ok || v == nil {
return fmt.Errorf("field path in CliMatch: required")
}
if v, ok := raw["start"]; !ok || v == nil {
return fmt.Errorf("field start in CliMatch: required")
}
type Plain CliMatch
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CliMatch(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *ErrorSpan) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["end"]; !ok || v == nil {
return fmt.Errorf("field end in ErrorSpan: required")
}
if v, ok := raw["file"]; !ok || v == nil {
return fmt.Errorf("field file in ErrorSpan: required")
}
if v, ok := raw["start"]; !ok || v == nil {
return fmt.Errorf("field start in ErrorSpan: required")
}
type Plain ErrorSpan
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = ErrorSpan(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CoreMatchIntermediateVar) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["location"]; !ok || v == nil {
return fmt.Errorf("field location in CoreMatchIntermediateVar: required")
}
type Plain CoreMatchIntermediateVar
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CoreMatchIntermediateVar(plain)
return nil
}
type ErrorSpan struct {
// ConfigEnd corresponds to the JSON schema field "config_end".
ConfigEnd *PositionBis `json:"config_end,omitempty" yaml:"config_end,omitempty"`
// ConfigPath corresponds to the JSON schema field "config_path".
ConfigPath interface{} `json:"config_path,omitempty" yaml:"config_path,omitempty"`
// ConfigStart corresponds to the JSON schema field "config_start".
ConfigStart *PositionBis `json:"config_start,omitempty" yaml:"config_start,omitempty"`
// ContextEnd corresponds to the JSON schema field "context_end".
ContextEnd *PositionBis `json:"context_end,omitempty" yaml:"context_end,omitempty"`
// ContextStart corresponds to the JSON schema field "context_start".
ContextStart *PositionBis `json:"context_start,omitempty" yaml:"context_start,omitempty"`
// End corresponds to the JSON schema field "end".
End PositionBis `json:"end" yaml:"end"`
// File corresponds to the JSON schema field "file".
File string `json:"file" yaml:"file"`
// SourceHash corresponds to the JSON schema field "source_hash".
SourceHash *string `json:"source_hash,omitempty" yaml:"source_hash,omitempty"`
// Start corresponds to the JSON schema field "start".
Start PositionBis `json:"start" yaml:"start"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *PositionBis) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["col"]; !ok || v == nil {
return fmt.Errorf("field col in PositionBis: required")
}
if v, ok := raw["line"]; !ok || v == nil {
return fmt.Errorf("field line in PositionBis: required")
}
type Plain PositionBis
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = PositionBis(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CoreMatchExtra_1) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["metavars"]; !ok || v == nil {
return fmt.Errorf("field metavars in CoreMatchExtra_1: required")
}
type Plain CoreMatchExtra_1
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CoreMatchExtra_1(plain)
return nil
}
type Position struct {
// Col corresponds to the JSON schema field "col".
Col int `json:"col" yaml:"col"`
// Line corresponds to the JSON schema field "line".
Line int `json:"line" yaml:"line"`
// Offset corresponds to the JSON schema field "offset".
Offset int `json:"offset" yaml:"offset"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CoreMatch) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["extra"]; !ok || v == nil {
return fmt.Errorf("field extra in CoreMatch: required")
}
if v, ok := raw["location"]; !ok || v == nil {
return fmt.Errorf("field location in CoreMatch: required")
}
if v, ok := raw["rule_id"]; !ok || v == nil {
return fmt.Errorf("field rule_id in CoreMatch: required")
}
type Plain CoreMatch
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CoreMatch(plain)
return nil
}
type MatchingExplanationOp interface{}
type MatchingExplanation struct {
// Children corresponds to the JSON schema field "children".
Children []*MatchingExplanation `json:"children" yaml:"children"`
// Loc corresponds to the JSON schema field "loc".
Loc Location `json:"loc" yaml:"loc"`
// Matches corresponds to the JSON schema field "matches".
Matches []CoreMatch `json:"matches" yaml:"matches"`
// Op corresponds to the JSON schema field "op".
Op MatchingExplanationOp `json:"op" yaml:"op"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *MatchingExplanation) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["children"]; !ok || v == nil {
return fmt.Errorf("field children in MatchingExplanation: required")
}
if v, ok := raw["loc"]; !ok || v == nil {
return fmt.Errorf("field loc in MatchingExplanation: required")
}
if v, ok := raw["matches"]; !ok || v == nil {
return fmt.Errorf("field matches in MatchingExplanation: required")
}
if v, ok := raw["op"]; !ok || v == nil {
return fmt.Errorf("field op in MatchingExplanation: required")
}
type Plain MatchingExplanation
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = MatchingExplanation(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *DependencyPattern) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["ecosystem"]; !ok || v == nil {
return fmt.Errorf("field ecosystem in DependencyPattern: required")
}
if v, ok := raw["package"]; !ok || v == nil {
return fmt.Errorf("field package in DependencyPattern: required")
}
if v, ok := raw["semver_range"]; !ok || v == nil {
return fmt.Errorf("field semver_range in DependencyPattern: required")
}
type Plain DependencyPattern
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = DependencyPattern(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CliSkippedTarget) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["path"]; !ok || v == nil {
return fmt.Errorf("field path in CliSkippedTarget: required")
}
if v, ok := raw["reason"]; !ok || v == nil {
return fmt.Errorf("field reason in CliSkippedTarget: required")
}
type Plain CliSkippedTarget
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CliSkippedTarget(plain)
return nil
}
type FindingMetadata interface{}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CliPaths) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["scanned"]; !ok || v == nil {
return fmt.Errorf("field scanned in CliPaths: required")
}
type Plain CliPaths
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CliPaths(plain)
return nil
}
type PositionBis struct {
// Col corresponds to the JSON schema field "col".
Col int `json:"col" yaml:"col"`
// Line corresponds to the JSON schema field "line".
Line int `json:"line" yaml:"line"`
}
type RuleIdDict struct {
// Id corresponds to the JSON schema field "id".
Id RuleId `json:"id" yaml:"id"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *RuleIdDict) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["id"]; !ok || v == nil {
return fmt.Errorf("field id in RuleIdDict: required")
}
type Plain RuleIdDict
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = RuleIdDict(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *ApiScansFindings) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["cai_ids"]; !ok || v == nil {
return fmt.Errorf("field cai_ids in ApiScansFindings: required")
}
if v, ok := raw["findings"]; !ok || v == nil {
return fmt.Errorf("field findings in ApiScansFindings: required")
}
if v, ok := raw["gitlab_token"]; !ok || v == nil {
return fmt.Errorf("field gitlab_token in ApiScansFindings: required")
}
if v, ok := raw["rule_ids"]; !ok || v == nil {
return fmt.Errorf("field rule_ids in ApiScansFindings: required")
}
if v, ok := raw["searched_paths"]; !ok || v == nil {
return fmt.Errorf("field searched_paths in ApiScansFindings: required")
}
if v, ok := raw["token"]; !ok || v == nil {
return fmt.Errorf("field token in ApiScansFindings: required")
}
type Plain ApiScansFindings
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = ApiScansFindings(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CliTargetTimes) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["match_times"]; !ok || v == nil {
return fmt.Errorf("field match_times in CliTargetTimes: required")
}
if v, ok := raw["num_bytes"]; !ok || v == nil {
return fmt.Errorf("field num_bytes in CliTargetTimes: required")
}
if v, ok := raw["parse_times"]; !ok || v == nil {
return fmt.Errorf("field parse_times in CliTargetTimes: required")
}
if v, ok := raw["path"]; !ok || v == nil {
return fmt.Errorf("field path in CliTargetTimes: required")
}
if v, ok := raw["run_time"]; !ok || v == nil {
return fmt.Errorf("field run_time in CliTargetTimes: required")
}
type Plain CliTargetTimes
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CliTargetTimes(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CliMatchTaintSource) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["content"]; !ok || v == nil {
return fmt.Errorf("field content in CliMatchTaintSource: required")
}
if v, ok := raw["location"]; !ok || v == nil {
return fmt.Errorf("field location in CliMatchTaintSource: required")
}
type Plain CliMatchTaintSource
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CliMatchTaintSource(plain)
return nil
}
type FoundDependencyTransitivity interface{}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CliMatchIntermediateVar) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["content"]; !ok || v == nil {
return fmt.Errorf("field content in CliMatchIntermediateVar: required")
}
if v, ok := raw["location"]; !ok || v == nil {
return fmt.Errorf("field location in CliMatchIntermediateVar: required")
}
type Plain CliMatchIntermediateVar
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CliMatchIntermediateVar(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CliOutputExtra) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["paths"]; !ok || v == nil {
return fmt.Errorf("field paths in CliOutputExtra: required")
}
type Plain CliOutputExtra
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CliOutputExtra(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *Location) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["end"]; !ok || v == nil {
return fmt.Errorf("field end in Location: required")
}
if v, ok := raw["path"]; !ok || v == nil {
return fmt.Errorf("field path in Location: required")
}
if v, ok := raw["start"]; !ok || v == nil {
return fmt.Errorf("field start in Location: required")
}
type Plain Location
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = Location(plain)
return nil
}
type Location struct {
// End corresponds to the JSON schema field "end".
End Position `json:"end" yaml:"end"`
// Path corresponds to the JSON schema field "path".
Path string `json:"path" yaml:"path"`
// Start corresponds to the JSON schema field "start".
Start Position `json:"start" yaml:"start"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *Position) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["col"]; !ok || v == nil {
return fmt.Errorf("field col in Position: required")
}
if v, ok := raw["line"]; !ok || v == nil {
return fmt.Errorf("field line in Position: required")
}
if v, ok := raw["offset"]; !ok || v == nil {
return fmt.Errorf("field offset in Position: required")
}
type Plain Position
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = Position(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CoreError) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["error_type"]; !ok || v == nil {
return fmt.Errorf("field error_type in CoreError: required")
}
if v, ok := raw["location"]; !ok || v == nil {
return fmt.Errorf("field location in CoreError: required")
}
if v, ok := raw["message"]; !ok || v == nil {
return fmt.Errorf("field message in CoreError: required")
}
if v, ok := raw["severity"]; !ok || v == nil {
return fmt.Errorf("field severity in CoreError: required")
}
type Plain CoreError
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CoreError(plain)
return nil
}
type RuleId string
type SkippedTargetReason interface{}
type SkippedTarget struct {
// Details corresponds to the JSON schema field "details".
Details string `json:"details" yaml:"details"`
// Path corresponds to the JSON schema field "path".
Path string `json:"path" yaml:"path"`
// Reason corresponds to the JSON schema field "reason".
Reason SkippedTargetReason `json:"reason" yaml:"reason"`
// RuleId corresponds to the JSON schema field "rule_id".
RuleId *RuleId `json:"rule_id,omitempty" yaml:"rule_id,omitempty"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *SkippedTarget) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["details"]; !ok || v == nil {
return fmt.Errorf("field details in SkippedTarget: required")
}
if v, ok := raw["path"]; !ok || v == nil {
return fmt.Errorf("field path in SkippedTarget: required")
}
if v, ok := raw["reason"]; !ok || v == nil {
return fmt.Errorf("field reason in SkippedTarget: required")
}
type Plain SkippedTarget
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = SkippedTarget(plain)
return nil
}
type SkippedRule struct {
// Details corresponds to the JSON schema field "details".
Details string `json:"details" yaml:"details"`
// Position corresponds to the JSON schema field "position".
Position Position `json:"position" yaml:"position"`
// RuleId corresponds to the JSON schema field "rule_id".
RuleId RuleId `json:"rule_id" yaml:"rule_id"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *SkippedRule) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["details"]; !ok || v == nil {
return fmt.Errorf("field details in SkippedRule: required")
}
if v, ok := raw["position"]; !ok || v == nil {
return fmt.Errorf("field position in SkippedRule: required")
}
if v, ok := raw["rule_id"]; !ok || v == nil {
return fmt.Errorf("field rule_id in SkippedRule: required")
}
type Plain SkippedRule
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = SkippedRule(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *FoundDependency) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["allowed_hashes"]; !ok || v == nil {
return fmt.Errorf("field allowed_hashes in FoundDependency: required")
}
if v, ok := raw["ecosystem"]; !ok || v == nil {
return fmt.Errorf("field ecosystem in FoundDependency: required")
}
if v, ok := raw["package"]; !ok || v == nil {
return fmt.Errorf("field package in FoundDependency: required")
}
if v, ok := raw["transitivity"]; !ok || v == nil {
return fmt.Errorf("field transitivity in FoundDependency: required")
}
if v, ok := raw["version"]; !ok || v == nil {
return fmt.Errorf("field version in FoundDependency: required")
}
type Plain FoundDependency
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = FoundDependency(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CoreStats) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["errorfiles"]; !ok || v == nil {
return fmt.Errorf("field errorfiles in CoreStats: required")
}
if v, ok := raw["okfiles"]; !ok || v == nil {
return fmt.Errorf("field okfiles in CoreStats: required")
}
type Plain CoreStats
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CoreStats(plain)
return nil
}
type RuleTimes struct {
// MatchTime corresponds to the JSON schema field "match_time".
MatchTime float64 `json:"match_time" yaml:"match_time"`
// ParseTime corresponds to the JSON schema field "parse_time".
ParseTime float64 `json:"parse_time" yaml:"parse_time"`
// RuleId corresponds to the JSON schema field "rule_id".
RuleId RuleId `json:"rule_id" yaml:"rule_id"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *RuleTimes) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["match_time"]; !ok || v == nil {
return fmt.Errorf("field match_time in RuleTimes: required")
}
if v, ok := raw["parse_time"]; !ok || v == nil {
return fmt.Errorf("field parse_time in RuleTimes: required")
}
if v, ok := raw["rule_id"]; !ok || v == nil {
return fmt.Errorf("field rule_id in RuleTimes: required")
}
type Plain RuleTimes
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = RuleTimes(plain)
return nil
}
type TargetTime struct {
// Path corresponds to the JSON schema field "path".
Path string `json:"path" yaml:"path"`
// RuleTimes corresponds to the JSON schema field "rule_times".
RuleTimes []RuleTimes `json:"rule_times" yaml:"rule_times"`
// RunTime corresponds to the JSON schema field "run_time".
RunTime float64 `json:"run_time" yaml:"run_time"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *TargetTime) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["path"]; !ok || v == nil {
return fmt.Errorf("field path in TargetTime: required")
}
if v, ok := raw["rule_times"]; !ok || v == nil {
return fmt.Errorf("field rule_times in TargetTime: required")
}
if v, ok := raw["run_time"]; !ok || v == nil {
return fmt.Errorf("field run_time in TargetTime: required")
}
type Plain TargetTime
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = TargetTime(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *Finding) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["check_id"]; !ok || v == nil {
return fmt.Errorf("field check_id in Finding: required")
}
if v, ok := raw["column"]; !ok || v == nil {
return fmt.Errorf("field column in Finding: required")
}
if v, ok := raw["commit_date"]; !ok || v == nil {
return fmt.Errorf("field commit_date in Finding: required")
}
if v, ok := raw["end_column"]; !ok || v == nil {
return fmt.Errorf("field end_column in Finding: required")
}
if v, ok := raw["end_line"]; !ok || v == nil {
return fmt.Errorf("field end_line in Finding: required")
}
if v, ok := raw["index"]; !ok || v == nil {
return fmt.Errorf("field index in Finding: required")
}
if v, ok := raw["is_blocking"]; !ok || v == nil {
return fmt.Errorf("field is_blocking in Finding: required")
}
if v, ok := raw["line"]; !ok || v == nil {
return fmt.Errorf("field line in Finding: required")
}
if v, ok := raw["message"]; !ok || v == nil {
return fmt.Errorf("field message in Finding: required")
}
if v, ok := raw["metadata"]; !ok || v == nil {
return fmt.Errorf("field metadata in Finding: required")
}
if v, ok := raw["path"]; !ok || v == nil {
return fmt.Errorf("field path in Finding: required")
}
if v, ok := raw["severity"]; !ok || v == nil {
return fmt.Errorf("field severity in Finding: required")
}
if v, ok := raw["syntactic_id"]; !ok || v == nil {
return fmt.Errorf("field syntactic_id in Finding: required")
}
type Plain Finding
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = Finding(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CoreTiming) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["rules"]; !ok || v == nil {
return fmt.Errorf("field rules in CoreTiming: required")
}
if v, ok := raw["targets"]; !ok || v == nil {
return fmt.Errorf("field targets in CoreTiming: required")
}
type Plain CoreTiming
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CoreTiming(plain)
return nil
}
type Finding struct {
// CheckId corresponds to the JSON schema field "check_id".
CheckId RuleId `json:"check_id" yaml:"check_id"`
// Column corresponds to the JSON schema field "column".
Column int `json:"column" yaml:"column"`
// CommitDate corresponds to the JSON schema field "commit_date".
CommitDate string `json:"commit_date" yaml:"commit_date"`
// DataflowTrace corresponds to the JSON schema field "dataflow_trace".
DataflowTrace *CliMatchDataflowTrace `json:"dataflow_trace,omitempty" yaml:"dataflow_trace,omitempty"`
// EndColumn corresponds to the JSON schema field "end_column".
EndColumn int `json:"end_column" yaml:"end_column"`
// EndLine corresponds to the JSON schema field "end_line".
EndLine int `json:"end_line" yaml:"end_line"`
// FixedLines corresponds to the JSON schema field "fixed_lines".
FixedLines []string `json:"fixed_lines,omitempty" yaml:"fixed_lines,omitempty"`
// Index corresponds to the JSON schema field "index".
Index int `json:"index" yaml:"index"`
// IsBlocking corresponds to the JSON schema field "is_blocking".
IsBlocking bool `json:"is_blocking" yaml:"is_blocking"`
// Line corresponds to the JSON schema field "line".
Line int `json:"line" yaml:"line"`
// MatchBasedId corresponds to the JSON schema field "match_based_id".
MatchBasedId *string `json:"match_based_id,omitempty" yaml:"match_based_id,omitempty"`
// Message corresponds to the JSON schema field "message".
Message string `json:"message" yaml:"message"`
// Metadata corresponds to the JSON schema field "metadata".
Metadata FindingMetadata `json:"metadata" yaml:"metadata"`
// Path corresponds to the JSON schema field "path".
Path string `json:"path" yaml:"path"`
// ScaInfo corresponds to the JSON schema field "sca_info".
ScaInfo *ScaInfo `json:"sca_info,omitempty" yaml:"sca_info,omitempty"`
// Severity corresponds to the JSON schema field "severity".
Severity int `json:"severity" yaml:"severity"`
// SyntacticId corresponds to the JSON schema field "syntactic_id".
SyntacticId string `json:"syntactic_id" yaml:"syntactic_id"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CoreMatchResults) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["errors"]; !ok || v == nil {
return fmt.Errorf("field errors in CoreMatchResults: required")
}
if v, ok := raw["matches"]; !ok || v == nil {
return fmt.Errorf("field matches in CoreMatchResults: required")
}
if v, ok := raw["stats"]; !ok || v == nil {
return fmt.Errorf("field stats in CoreMatchResults: required")
}
type Plain CoreMatchResults
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CoreMatchResults(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *ScaInfo) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["dependency_match"]; !ok || v == nil {
return fmt.Errorf("field dependency_match in ScaInfo: required")
}
if v, ok := raw["reachability_rule"]; !ok || v == nil {
return fmt.Errorf("field reachability_rule in ScaInfo: required")
}
if v, ok := raw["reachable"]; !ok || v == nil {
return fmt.Errorf("field reachable in ScaInfo: required")
}
if v, ok := raw["sca_finding_schema"]; !ok || v == nil {
return fmt.Errorf("field sca_finding_schema in ScaInfo: required")
}
type Plain ScaInfo
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = ScaInfo(plain)
return nil
}
type ScaInfo struct {
// DependencyMatch corresponds to the JSON schema field "dependency_match".
DependencyMatch DependencyMatch `json:"dependency_match" yaml:"dependency_match"`
// ReachabilityRule corresponds to the JSON schema field "reachability_rule".
ReachabilityRule bool `json:"reachability_rule" yaml:"reachability_rule"`
// Reachable corresponds to the JSON schema field "reachable".
Reachable bool `json:"reachable" yaml:"reachable"`
// ScaFindingSchema corresponds to the JSON schema field "sca_finding_schema".
ScaFindingSchema int `json:"sca_finding_schema" yaml:"sca_finding_schema"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *CveResult) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["filename"]; !ok || v == nil {
return fmt.Errorf("field filename in CveResult: required")
}
if v, ok := raw["funcnames"]; !ok || v == nil {
return fmt.Errorf("field funcnames in CveResult: required")
}
if v, ok := raw["url"]; !ok || v == nil {
return fmt.Errorf("field url in CveResult: required")
}
type Plain CveResult
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = CveResult(plain)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *DependencyMatch) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["dependency_pattern"]; !ok || v == nil {
return fmt.Errorf("field dependency_pattern in DependencyMatch: required")
}
if v, ok := raw["found_dependency"]; !ok || v == nil {
return fmt.Errorf("field found_dependency in DependencyMatch: required")
}
if v, ok := raw["lockfile"]; !ok || v == nil {
return fmt.Errorf("field lockfile in DependencyMatch: required")
}
type Plain DependencyMatch
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = DependencyMatch(plain)
return nil
}
type Ecosystem interface{}
type MatchingOperation interface{}
type RawJson interface{}
type Semver string
type SkipReason interface{}
type Transitivity interface{}
// Translated by atdcat from 'semgrep_output_v0.atd'.
type SemgrepOutputV0Jsonschema struct {
// Errors corresponds to the JSON schema field "errors".
Errors []CliError `json:"errors" yaml:"errors"`
// Explanations corresponds to the JSON schema field "explanations".
Explanations []MatchingExplanation `json:"explanations,omitempty" yaml:"explanations,omitempty"`
// Paths corresponds to the JSON schema field "paths".
Paths CliPaths `json:"paths" yaml:"paths"`
// Results corresponds to the JSON schema field "results".
Results []CliMatch `json:"results" yaml:"results"`
// Time corresponds to the JSON schema field "time".
Time *CliTiming `json:"time,omitempty" yaml:"time,omitempty"`
// Version corresponds to the JSON schema field "version".
Version *Semver `json:"version,omitempty" yaml:"version,omitempty"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *SemgrepOutputV0Jsonschema) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if v, ok := raw["errors"]; !ok || v == nil {
return fmt.Errorf("field errors in SemgrepOutputV0Jsonschema: required")
}
if v, ok := raw["paths"]; !ok || v == nil {
return fmt.Errorf("field paths in SemgrepOutputV0Jsonschema: required")
}
if v, ok := raw["results"]; !ok || v == nil {
return fmt.Errorf("field results in SemgrepOutputV0Jsonschema: required")
}
type Plain SemgrepOutputV0Jsonschema
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = SemgrepOutputV0Jsonschema(plain)
return nil
}
// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse and unparse this JSON data, add this code to your project and do:
//
// coordinate, err := UnmarshalCoordinate(bytes)
// bytes, err = coordinate.Marshal()
package main
import "encoding/json"
func UnmarshalCoordinate(data []byte) (Coordinate, error) {
var r Coordinate
err := json.Unmarshal(data, &r)
return r, err
}
func (r *Coordinate) Marshal() ([]byte, error) {
return json.Marshal(r)
}
// Translated by atdcat from 'semgrep_output_v0.atd'.
type Coordinate struct {
Errors []CLIError `json:"errors"`
Explanations []MatchingExplanation `json:"explanations,omitempty"`
Paths CLIPaths `json:"paths"`
Results []CLIMatch `json:"results"`
Time *CLITiming `json:"time,omitempty"`
Version *string `json:"version,omitempty"`
}
type CLIError struct {
Code int64 `json:"code"`
Help *string `json:"help,omitempty"`
Level string `json:"level"`
LongMsg *string `json:"long_msg,omitempty"`
Message *string `json:"message,omitempty"`
Path *string `json:"path,omitempty"`
RuleID *string `json:"rule_id,omitempty"`
ShortMsg *string `json:"short_msg,omitempty"`
Spans []ErrorSpan `json:"spans,omitempty"`
Type string `json:"type"`
}
type ErrorSpan struct {
ConfigEnd *PositionBis `json:"config_end,omitempty"`
ConfigPath []string `json:"config_path"`
ConfigStart *PositionBis `json:"config_start,omitempty"`
ContextEnd *PositionBis `json:"context_end,omitempty"`
ContextStart *PositionBis `json:"context_start,omitempty"`
End PositionBis `json:"end"`
File string `json:"file"`
SourceHash *string `json:"source_hash,omitempty"`
Start PositionBis `json:"start"`
}
type PositionBis struct {
Col int64 `json:"col"`
Line int64 `json:"line"`
}
type MatchingExplanation struct {
Children []MatchingExplanation `json:"children"`
LOC Location `json:"loc"`
Matches []CoreMatch `json:"matches"`
Op interface{} `json:"op"`
}
type Location struct {
End Position `json:"end"`
Path string `json:"path"`
Start Position `json:"start"`
}
type Position struct {
Col int64 `json:"col"`
Line int64 `json:"line"`
Offset int64 `json:"offset"`
}
type CoreMatch struct {
Extra CoreMatchExtra `json:"extra"`
Location Location `json:"location"`
RuleID string `json:"rule_id"`
}
type CoreMatchExtra struct {
DataflowTrace *CoreMatchDataflowTrace `json:"dataflow_trace,omitempty"`
Message *string `json:"message,omitempty"`
Metavars map[string]MetavarValue `json:"metavars"`
RenderedFix *string `json:"rendered_fix,omitempty"`
}
type CoreMatchDataflowTrace struct {
IntermediateVars []CoreMatchIntermediateVar `json:"intermediate_vars,omitempty"`
TaintSource *Location `json:"taint_source,omitempty"`
}
type CoreMatchIntermediateVar struct {
Location Location `json:"location"`
}
type MetavarValue struct {
AbstractContent string `json:"abstract_content"`
End Position `json:"end"`
PropagatedValue *SvalueValue `json:"propagated_value,omitempty"`
Start Position `json:"start"`
}
type SvalueValue struct {
SvalueAbstractContent string `json:"svalue_abstract_content"`
SvalueEnd *Position `json:"svalue_end,omitempty"`
SvalueStart *Position `json:"svalue_start,omitempty"`
}
type CLIPaths struct {
Comment *string `json:"_comment,omitempty"`
Scanned []string `json:"scanned"`
Skipped []CLISkippedTarget `json:"skipped,omitempty"`
}
type CLISkippedTarget struct {
Path string `json:"path"`
Reason string `json:"reason"`
}
type CLIMatch struct {
CheckID string `json:"check_id"`
End Position `json:"end"`
Extra CLIMatchExtra `json:"extra"`
Path string `json:"path"`
Start Position `json:"start"`
}
type CLIMatchExtra struct {
DataflowTrace *CLIMatchDataflowTrace `json:"dataflow_trace,omitempty"`
Fingerprint string `json:"fingerprint"`
Fix *string `json:"fix,omitempty"`
FixRegex *FixRegex `json:"fix_regex,omitempty"`
FixedLines []string `json:"fixed_lines,omitempty"`
IsIgnored *bool `json:"is_ignored,omitempty"`
Lines string `json:"lines"`
Message string `json:"message"`
Metadata interface{} `json:"metadata"`
Metavars map[string]MetavarValue `json:"metavars,omitempty"`
ScaInfo *ScaInfo `json:"sca_info,omitempty"`
Severity string `json:"severity"`
}
type CLIMatchDataflowTrace struct {
IntermediateVars []CLIMatchIntermediateVar `json:"intermediate_vars,omitempty"`
TaintSource *CLIMatchTaintSource `json:"taint_source,omitempty"`
}
type CLIMatchIntermediateVar struct {
Content string `json:"content"`
Location Location `json:"location"`
}
type CLIMatchTaintSource struct {
Content string `json:"content"`
Location Location `json:"location"`
}
type FixRegex struct {
Count *int64 `json:"count,omitempty"`
Regex string `json:"regex"`
Replacement string `json:"replacement"`
}
type ScaInfo struct {
DependencyMatch DependencyMatch `json:"dependency_match"`
ReachabilityRule bool `json:"reachability_rule"`
Reachable bool `json:"reachable"`
ScaFindingSchema int64 `json:"sca_finding_schema"`
}
type DependencyMatch struct {
DependencyPattern DependencyPattern `json:"dependency_pattern"`
FoundDependency FoundDependency `json:"found_dependency"`
Lockfile string `json:"lockfile"`
}
type DependencyPattern struct {
Ecosystem interface{} `json:"ecosystem"`
Package string `json:"package"`
SemverRange string `json:"semver_range"`
}
type FoundDependency struct {
AllowedHashes map[string][]string `json:"allowed_hashes"`
Ecosystem interface{} `json:"ecosystem"`
LineNumber *int64 `json:"line_number,omitempty"`
Package string `json:"package"`
ResolvedURL *string `json:"resolved_url,omitempty"`
Transitivity interface{} `json:"transitivity"`
Version string `json:"version"`
}
type CLITiming struct {
ProfilingTimes map[string]float64 `json:"profiling_times"`
Rules []RuleIDDict `json:"rules"`
RulesParseTime float64 `json:"rules_parse_time"`
Targets []CLITargetTimes `json:"targets"`
TotalBytes int64 `json:"total_bytes"`
}
type RuleIDDict struct {
ID string `json:"id"`
}
type CLITargetTimes struct {
MatchTimes []float64 `json:"match_times"`
NumBytes int64 `json:"num_bytes"`
ParseTimes []float64 `json:"parse_times"`
Path string `json:"path"`
RunTime float64 `json:"run_time"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment