Preserve selected collections in materialized references

This commit is contained in:
2026-11-29 17:59:01 +00:00
parent 10221b0624
commit d406aa6cd2
33 changed files with 251 additions and 2 deletions

View File

@@ -109,6 +109,7 @@ type ReferenceProducer struct {
type ReferenceItem struct {
SlotName string `json:"slot_name"`
Collections []string `json:"collections,omitempty"`
MediaType string `json:"media_type,omitempty"`
Content []byte `json:"-"`
Digest string `json:"digest,omitempty"`
@@ -122,6 +123,9 @@ type ReferenceItem struct {
func CloneReferenceItem(item ReferenceItem) ReferenceItem {
item.Content = append([]byte(nil), item.Content...)
if item.Collections != nil {
item.Collections = append([]string{}, item.Collections...)
}
item.ArtifactSchema = CloneArtifactSchema(item.ArtifactSchema)
return item
}
@@ -129,6 +133,7 @@ func CloneReferenceItem(item ReferenceItem) ReferenceItem {
func (item ReferenceItem) MarshalJSON() ([]byte, error) {
type referenceItemJSON struct {
SlotName string `json:"slot_name"`
Collections *[]string `json:"collections,omitempty"`
MediaType string `json:"media_type,omitempty"`
Digest string `json:"digest,omitempty"`
Origin ReferenceOrigin `json:"origin"`
@@ -147,6 +152,9 @@ func (item ReferenceItem) MarshalJSON() ([]byte, error) {
BindingSource: item.BindingSource,
ArtifactKind: item.ArtifactKind,
}
if item.Collections != nil {
encoded.Collections = &item.Collections
}
if item.ArtifactSchema.ID != "" || item.ArtifactSchema.Name != "" || item.ArtifactSchema.Version != "" || len(item.ArtifactSchema.JSONSchema) > 0 {
schema := CloneArtifactSchema(item.ArtifactSchema)
encoded.ArtifactSchema = &schema