Documentation
¶
Index ¶
- Constants
- type Context
- type Envelope
- type Finding
- type Graph
- func (g *Graph) AddNode(nodes ...types.Node)
- func (g Graph) MarshalJSON() ([]byte, error)
- func (g *Graph) Relate(spdxID string, from types.Node, relType core.RelationshipType, ...) *core.Relationship
- func (g *Graph) SetCreationInfo(creation *core.CreationInfo)
- func (g *Graph) UnmarshalJSON(data []byte) error
- type Parser
- type ParserOption
- type Profile
- type Renderer
Constants ¶
const ContextURL301 = "https://spdx.org/rdf/3.0.1/spdx-context.jsonld"
ContextURL301 is the JSON-LD context URL of SPDX 3.0.1, the spec version this library targets.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context holds a document's JSON-LD @context. SPDX 3 documents normally carry a single context URL string, but JSON-LD also admits array and object forms; those parse too and are preserved verbatim when rendering. The receivers are deliberately mixed: json.Unmarshaler has to take a pointer, while the accessors take values so they work on the Context field of an Envelope value, which is not addressable when the envelope is rendered.
func NewContext ¶
NewContext returns a Context referencing a single context URL, the form the SPDX serialization mandates.
func (Context) MarshalJSON ¶
func (Context) String ¶
String returns the context URL or, for the array and object forms, the raw JSON text.
func (Context) URLs ¶
URLs returns the context URLs the @context value references: the URL itself in the common string form or every string entry of the array form. Inline object contexts define their terms directly and reference none.
func (*Context) UnmarshalJSON ¶
type Envelope ¶
Envelope
func NewEnvelope ¶
func NewEnvelope() *Envelope
NewEnvelope returns an empty document bound to the context of the SPDX version this library targets, ready for elements to be added to its graph:
env := spdx3.NewEnvelope() env.Graph.AddNode(creationInfo, person, pkg)
func (*Envelope) UnmarshalJSON ¶
UnmarshalJSON reads a document in either of the two shapes the serialization allows: a @graph holding the elements, or a lone element as the document root. A single root element is read into a one-node graph, so it is rendered back inside a @graph.
type Finding ¶
type Finding struct {
// NodeID identifies the node the finding is in, by its spdxId or, for
// blank nodes, its @id.
NodeID string
// NodeType is the SPDX class of that node.
NodeType string
// Property is the JSON name of the property at fault.
Property string
// Value is the offending value.
Value string
// Message says what is wrong with it.
Message string
}
Finding is a place where a document departs from the specification.
func Validate ¶
Validate reports the values in a document that are not members of the vocabulary their property is drawn from.
A parser drops such values as it reads, so validating a document parsed the usual way finds nothing. Parse it with WithInvalidVocabularyValues to keep them, and validate that.
This checks vocabularies only. It says nothing about required properties, cardinalities or the ranges of object properties.
type Graph ¶
Graph is the list of nodes a document carries. The receivers are deliberately mixed: json.Unmarshaler has to take a pointer to grow the slice, while json.Marshaler takes a value so it is found on a Graph value.
func (Graph) MarshalJSON ¶
MarshalJSON marshals the graph to JSON. Each top-level node in the graph is serialized fully, with any nested nodes within them serialized as SPDXID reference strings.
func (*Graph) Relate ¶
func (g *Graph) Relate(spdxID string, from types.Node, relType core.RelationshipType, to ...types.Node) *core.Relationship
Relate joins elements with a relationship of relType, adds it to the graph and returns it, so that the relationships of a document can be stated where they are read rather than built one struct at a time:
env.Graph.Relate(id, doc, core.RelationshipTypeDescribes, pkg)
func (*Graph) SetCreationInfo ¶
func (g *Graph) SetCreationInfo(creation *core.CreationInfo)
SetCreationInfo gives every element of the graph that has none the creation information passed, and adds it to the graph if it is not there already. A document normally states its provenance once and shares it, so this is called after its elements are in place rather than repeated on each of them.
func (*Graph) UnmarshalJSON ¶
UnmarshalJSON unmarshalls the JSONLD graph into nodes typed to their kinds.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func NewParser ¶
func NewParser(opts ...ParserOption) *Parser
type ParserOption ¶
type ParserOption func(*Parser)
ParserOption changes how a parser reads documents.
func WithInvalidVocabularyValues ¶
func WithInvalidVocabularyValues() ParserOption
WithInvalidVocabularyValues keeps values that are not members of their vocabulary instead of dropping them, so a document is read exactly as it was written. Use it to read documents from a later version of the spec, whose vocabularies have entries this one does not know, or to inspect a nonconformant document with Validate.
Directories
¶
| Path | Synopsis |
|---|---|
|
hack
|
|
|
render
command
Command render reads SPDX documents and writes them back out through the library, producing the output that the conformance checks validate against the SPDX project's own tooling.
|
Command render reads SPDX documents and writes them back out through the library, producing the output that the conformance checks validate against the SPDX project's own tooling. |
|
profiles
|
|