sarif.go raw

   1  package sarif
   2  
   3  const Version = "2.1.0"
   4  const Schema = "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json"
   5  
   6  type Log struct {
   7  	Version string `json:"version"`
   8  	Schema  string `json:"$schema"`
   9  	Runs    []Run  `json:"runs"`
  10  }
  11  
  12  type Run struct {
  13  	Tool        Tool         `json:"tool"`
  14  	Results     []Result     `json:"results,omitempty"`
  15  	Invocations []Invocation `json:"invocations,omitempty"`
  16  	Artifacts   []Artifact   `json:"artifacts,omitempty"`
  17  }
  18  
  19  type Artifact struct {
  20  	Location       ArtifactLocation `json:"location"`
  21  	Length         int              `json:"length"`
  22  	SourceLanguage string           `json:"sourceLanguage"`
  23  	Roles          []string         `json:"roles"`
  24  	Encoding       string           `json:"encoding"`
  25  }
  26  
  27  const (
  28  	AnalysisTarget = "analysisTarget"
  29  	UTF8           = "UTF-8"
  30  	Fail           = "fail"
  31  	Warning        = "warning"
  32  	Error          = "error"
  33  	Note           = "note"
  34  	None           = "none"
  35  )
  36  
  37  type Hash struct {
  38  	Sha256 string `json:"sha-256"`
  39  }
  40  
  41  type Tool struct {
  42  	Driver ToolComponent `json:"driver"`
  43  }
  44  
  45  type Invocation struct {
  46  	CommandLine         string           `json:"commandLine,omitempty"`
  47  	Arguments           []string         `json:"arguments,omitempty"`
  48  	WorkingDirectory    ArtifactLocation `json:"workingDirectory,omitempty"`
  49  	ExecutionSuccessful bool             `json:"executionSuccessful"`
  50  }
  51  
  52  type ToolComponent struct {
  53  	Name            string                `json:"name,omitempty"`
  54  	Version         string                `json:"version,omitempty"`
  55  	SemanticVersion string                `json:"semanticVersion,omitempty"`
  56  	InformationURI  string                `json:"informationUri,omitempty"`
  57  	Rules           []ReportingDescriptor `json:"rules,omitempty"`
  58  }
  59  
  60  type ReportingDescriptor struct {
  61  	ID               string  `json:"id"`
  62  	ShortDescription Message `json:"shortDescription"`
  63  	// FullDescription  Message `json:"fullDescription"`
  64  	Help                 Message                `json:"help"`
  65  	HelpURI              string                 `json:"helpUri,omitempty"`
  66  	DefaultConfiguration ReportingConfiguration `json:"defaultConfiguration"`
  67  }
  68  
  69  type ReportingConfiguration struct {
  70  	Enabled    bool                   `json:"enabled"`
  71  	Level      string                 `json:"level,omitempty"`
  72  	Parameters map[string]interface{} `json:"parameters,omitempty"`
  73  }
  74  
  75  type Result struct {
  76  	RuleID string `json:"ruleId"`
  77  	// RuleIndex        int        `json:"ruleIndex"`
  78  	Kind             string        `json:"kind"`
  79  	Level            string        `json:"level,omitempty"`
  80  	Message          Message       `json:"message"`
  81  	Locations        []Location    `json:"locations,omitempty"`
  82  	RelatedLocations []Location    `json:"relatedLocations,omitempty"`
  83  	Fixes            []Fix         `json:"fixes,omitempty"`
  84  	Suppressions     []Suppression `json:"suppressions"`
  85  }
  86  
  87  type Suppression struct {
  88  	Kind          string `json:"kind"`
  89  	Justification string `json:"justification"`
  90  }
  91  
  92  type Fix struct {
  93  	Description     Message          `json:"description"`
  94  	ArtifactChanges []ArtifactChange `json:"artifactChanges"`
  95  }
  96  
  97  type ArtifactChange struct {
  98  	ArtifactLocation ArtifactLocation `json:"artifactLocation"`
  99  	Replacements     []Replacement    `json:"replacements"`
 100  }
 101  
 102  type Replacement struct {
 103  	DeletedRegion   Region          `json:"deletedRegion"`
 104  	InsertedContent ArtifactContent `json:"insertedContent"`
 105  }
 106  
 107  type ArtifactContent struct {
 108  	Text string `json:"text"`
 109  }
 110  
 111  type Message struct {
 112  	Text     string `json:"text,omitempty"`
 113  	Markdown string `json:"markdown,omitempty"`
 114  }
 115  
 116  type Location struct {
 117  	ID               int              `json:"id,omitempty"`
 118  	Message          *Message         `json:"message,omitempty"`
 119  	PhysicalLocation PhysicalLocation `json:"physicalLocation"`
 120  }
 121  
 122  type PhysicalLocation struct {
 123  	ArtifactLocation ArtifactLocation `json:"artifactLocation"`
 124  	Region           Region           `json:"region"`
 125  }
 126  
 127  type ArtifactLocation struct {
 128  	URI       string `json:"uri,omitempty"`
 129  	Index     int    `json:"index,omitempty"`
 130  	URIBaseID string `json:"uriBaseId,omitempty"`
 131  }
 132  
 133  type Region struct {
 134  	StartLine   int `json:"startLine"`
 135  	StartColumn int `json:"startColumn"`
 136  	EndLine     int `json:"endLine,omitempty"`
 137  	EndColumn   int `json:"endColumn,omitempty"`
 138  }
 139