Skip to content

Commit

Permalink
chore: schema bump 7.0.0 license refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
Signed-off-by: Avi Deitcher <avi@deitcher.net>
  • Loading branch information
spiffcs authored and deitch committed Feb 23, 2023
1 parent 4bb96ca commit 595701c
Show file tree
Hide file tree
Showing 38 changed files with 1,855 additions and 253 deletions.
2 changes: 1 addition & 1 deletion internal/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ const (

// JSONSchemaVersion is the current schema version output by the JSON encoder
// This is roughly following the "SchemaVer" guidelines for versioning the JSON schema. Please see schema/json/README.md for details on how to increment.
JSONSchemaVersion = "7.0.0"
JSONSchemaVersion = "7.0.1"
)
28 changes: 27 additions & 1 deletion internal/logicalstrings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package internal
import (
"fmt"
"strings"

"github.com/invopop/jsonschema"
)

type Joiner string
Expand Down Expand Up @@ -47,6 +49,20 @@ func (l LogicalStrings) String() string {
return strings.Join(parts, fmt.Sprintf(" %s ", joiner))
}

func (l LogicalStrings) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%s"`, l.String())), nil
}

func (l *LogicalStrings) UnmarshalJSON(data []byte) error {
raw := strings.Trim(string(data), `"`)
ls, err := ParseLogicalStrings(raw)
if err != nil {
return err
}
*l = ls
return nil
}

// Process processes each simple element inside the LogicalStrings through a provided function,
// returning a new LogicalStrings with the fields replaced.
func (l LogicalStrings) Process(f func(string) string) LogicalStrings {
Expand All @@ -70,6 +86,14 @@ func (l LogicalStrings) Elements() []string {
return elements
}

func (l LogicalStrings) JSONSchema() *jsonschema.Schema {
return &jsonschema.Schema{
Type: "string",
Title: "Logical Strings",
Description: "strings with simple or complex logical combinations",
}
}

// ParseLogicalStrings parse strings joined by AND or OR, as well as compounded by ( and ), into a LogicalStrings struct
func ParseLogicalStrings(s string) (LogicalStrings, error) {
var (
Expand Down Expand Up @@ -105,7 +129,9 @@ func ParseLogicalStrings(s string) (LogicalStrings, error) {
}
if currentExpression != "" {
simple, joiner := parseSimpleExpression(currentExpression)
currentLS.Simple = append(currentLS.Simple, simple...)
if len(simple) > 0 {
currentLS.Simple = append(currentLS.Simple, simple...)
}
currentLS.Joiner = joiner
}
return currentLS, nil
Expand Down
57 changes: 16 additions & 41 deletions schema/json/schema-7.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,21 @@
},
"BinaryMetadata": {
"properties": {
"matches": {
"items": {
"$ref": "#/$defs/ClassifierMatch"
},
"type": "array"
"classifier": {
"type": "string"
},
"realPath": {
"type": "string"
},
"virtualPath": {
"type": "string"
}
},
"type": "object",
"required": [
"matches"
"classifier",
"realPath",
"virtualPath"
]
},
"CargoPackageMetadata": {
Expand Down Expand Up @@ -244,21 +249,6 @@
"dependencies"
]
},
"ClassifierMatch": {
"properties": {
"classifier": {
"type": "string"
},
"location": {
"$ref": "#/$defs/Location"
}
},
"type": "object",
"required": [
"classifier",
"location"
]
},
"CocoapodsMetadata": {
"properties": {
"checksum": {
Expand Down Expand Up @@ -803,22 +793,10 @@
},
"type": "object"
},
"Location": {
"properties": {
"path": {
"type": "string"
},
"layerID": {
"type": "string"
},
"virtualPath": {
"type": "string"
}
},
"type": "object",
"required": [
"path"
]
"LogicalStrings": {
"type": "string",
"title": "Logical Strings",
"description": "strings with simple or complex logical combinations"
},
"MixLockMetadata": {
"properties": {
Expand Down Expand Up @@ -930,10 +908,7 @@
"type": "array"
},
"licenses": {
"items": {
"type": "string"
},
"type": "array"
"$ref": "#/$defs/LogicalStrings"
},
"language": {
"type": "string"
Expand Down
Loading

0 comments on commit 595701c

Please sign in to comment.