Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion cmd/grype/cli/commands/internal/jsonschema/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import (
"golang.org/x/tools/go/packages"

"github.com/anchore/grype/cmd/grype/cli/commands/internal/dbsearch"
"github.com/anchore/grype/grype/presenter/models"
)

func main() {
func generateDBSearch() {
pkgPatterns := []string{"../dbsearch", "../../../../../../grype/db/v6"}

comments := parseCommentsFromPackages(pkgPatterns)
Expand All @@ -28,6 +29,20 @@ func main() {
compose(dbsearch.Vulnerabilities{}, "db-search-vuln", dbsearch.VulnerabilitiesSchemaVersion, comments)
}

func generateDocument() {
pkgPatterns := []string{"../../../../../../grype/presenter/models"}

comments := parseCommentsFromPackages(pkgPatterns)
fmt.Printf("Extracted field comments from %d structs\n", len(comments))

compose(models.Document{}, "document", models.DocumentSchemaVersion, comments)
}

func main() {
generateDocument()
generateDBSearch()
}

func compose(document any, component, version string, comments map[string]map[string]string) {
write(encode(build(document, component, version, comments)), component, version)
}
Expand Down
4 changes: 4 additions & 0 deletions grype/presenter/models/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"github.com/anchore/grype/grype/vulnerability"
)

const (
DocumentSchemaVersion = "1.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should definitely not be 1.0

Copy link
Author

@axel7083 axel7083 Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this seems for the other json-schemas to be unrelated to the version of grype, and seems to increase when the schema changes, what would be the expected initial value?

E.g. version for the dbsearch schema

MatchesSchemaVersion = "1.1.3"

"$id": "anchore.io/schema/grype/db-search/json/1.1.3/matches",

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I started typing something else up and got sidetracked... we are definitely going to be iterating on this model as we work towards 1.0. We will probably what we did with Syft and have a legacy schema for pre-1.0 Grype, essentially the one that we have today. It's a great question what that number should be! I would think 0.9 indicates it's close to 1.0, but I think it is going to change significantly (e.g. possibly have matches only with references to packages and vulns). Maybe a 0.5 is something that indicates "significantly before 1.0". I'll bring this question to the team...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the details, keep me updated so I can update the PR!

)

// Document represents the JSON document to be presented
type Document struct {
Matches []Match `json:"matches"`
Expand Down
Loading
Loading