Use the json schema as input for templating #2542
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The template functionality today uses the go struct fields from the
syft/format/syftjson/model
directory as input, which means that in order to write a template you need to read the syft source code. For instance:Artifacts
approximates toartifacts
in the json schemaName
approximates toname
in the json schemaVersion
approximates toversion
in the json schemaFoundBy
approximates tofoundBy
in the json schemaThis change adapts the template input to require the same fields as what you will find in the JSON output of syft (exactly what's in the json schema):
Caveats are that struct helpers cannot be used on maps, which is what ultimately is used for templating. This means that some alterations will need to be made, for example replacing
hasField
forindex
:Since this will impact all templates a new
SYFT_FORMAT_TEMPLATE_LEGACY
/format.template.legacy
option has been provided that, when enabled, will use the original struct-approach.