From ac744e8443c6e8f60af7bc58e75f5d67f5ab37d6 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Fri, 5 Jun 2026 16:05:18 -0500 Subject: [PATCH] Fix generated draft lex types --- api/bsky/draftdefs.go | 68 ++++++++++++++++--------------- lexicons/app/bsky/draft/defs.json | 22 ++++++++-- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/api/bsky/draftdefs.go b/api/bsky/draftdefs.go index 42bd5c9a..9e0f8cc8 100644 --- a/api/bsky/draftdefs.go +++ b/api/bsky/draftdefs.go @@ -41,6 +41,38 @@ type DraftDefs_DraftEmbedExternal struct { Uri string `json:"uri" cborgen:"uri"` } +// DraftDefs_DraftEmbedGallery is a "draftEmbedGallery" in the app.bsky.draft.defs schema. +type DraftDefs_DraftEmbedGallery struct { + Items []DraftDefs_DraftEmbedGalleryItems_Elem `json:"items" cborgen:"items"` +} + +type DraftDefs_DraftEmbedGalleryItems_Elem struct { + DraftDefs_DraftEmbedImage *DraftDefs_DraftEmbedImage +} + +func (t *DraftDefs_DraftEmbedGalleryItems_Elem) MarshalJSON() ([]byte, error) { + if t.DraftDefs_DraftEmbedImage != nil { + t.DraftDefs_DraftEmbedImage.LexiconTypeID = "app.bsky.draft.defs#draftEmbedImage" + return json.Marshal(t.DraftDefs_DraftEmbedImage) + } + return nil, fmt.Errorf("can not marshal empty union as JSON") +} + +func (t *DraftDefs_DraftEmbedGalleryItems_Elem) UnmarshalJSON(b []byte) error { + typ, err := lexutil.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "app.bsky.draft.defs#draftEmbedImage": + t.DraftDefs_DraftEmbedImage = new(DraftDefs_DraftEmbedImage) + return json.Unmarshal(b, t.DraftDefs_DraftEmbedImage) + default: + return nil + } +} + // DraftDefs_DraftEmbedImage is a "draftEmbedImage" in the app.bsky.draft.defs schema. type DraftDefs_DraftEmbedImage struct { LexiconTypeID string `json:"$type" cborgen:"$type,const=app.bsky.draft.defs#draftEmbedImage"` @@ -71,44 +103,16 @@ type DraftDefs_DraftEmbedVideo struct { // One of the posts that compose a draft. type DraftDefs_DraftPost struct { EmbedExternals []*DraftDefs_DraftEmbedExternal `json:"embedExternals,omitempty" cborgen:"embedExternals,omitempty"` - // embedGallery: The schema-level maxLength of 20 is a future-proof ceiling. Clients should currently enforce a soft limit of 10 items in authoring UIs. - EmbedGallery []*DraftDefs_DraftPost_EmbedGallery_Elem `json:"embedGallery,omitempty" cborgen:"embedGallery,omitempty"` - EmbedImages []*DraftDefs_DraftEmbedImage `json:"embedImages,omitempty" cborgen:"embedImages,omitempty"` - EmbedRecords []*DraftDefs_DraftEmbedRecord `json:"embedRecords,omitempty" cborgen:"embedRecords,omitempty"` - EmbedVideos []*DraftDefs_DraftEmbedVideo `json:"embedVideos,omitempty" cborgen:"embedVideos,omitempty"` + EmbedGallery *DraftDefs_DraftEmbedGallery `json:"embedGallery,omitempty" cborgen:"embedGallery,omitempty"` + EmbedImages []*DraftDefs_DraftEmbedImage `json:"embedImages,omitempty" cborgen:"embedImages,omitempty"` + EmbedRecords []*DraftDefs_DraftEmbedRecord `json:"embedRecords,omitempty" cborgen:"embedRecords,omitempty"` + EmbedVideos []*DraftDefs_DraftEmbedVideo `json:"embedVideos,omitempty" cborgen:"embedVideos,omitempty"` // labels: Self-label values for this post. Effectively content warnings. Labels *DraftDefs_DraftPost_Labels `json:"labels,omitempty" cborgen:"labels,omitempty"` // text: The primary post content. It has a higher limit than post contents to allow storing a larger text that can later be refined into smaller posts. Text string `json:"text" cborgen:"text"` } -type DraftDefs_DraftPost_EmbedGallery_Elem struct { - DraftDefs_DraftEmbedImage *DraftDefs_DraftEmbedImage -} - -func (t *DraftDefs_DraftPost_EmbedGallery_Elem) MarshalJSON() ([]byte, error) { - if t.DraftDefs_DraftEmbedImage != nil { - t.DraftDefs_DraftEmbedImage.LexiconTypeID = "app.bsky.draft.defs#draftEmbedImage" - return json.Marshal(t.DraftDefs_DraftEmbedImage) - } - return nil, fmt.Errorf("can not marshal empty union as JSON") -} - -func (t *DraftDefs_DraftPost_EmbedGallery_Elem) UnmarshalJSON(b []byte) error { - typ, err := lexutil.TypeExtract(b) - if err != nil { - return err - } - - switch typ { - case "app.bsky.draft.defs#draftEmbedImage": - t.DraftDefs_DraftEmbedImage = new(DraftDefs_DraftEmbedImage) - return json.Unmarshal(b, t.DraftDefs_DraftEmbedImage) - default: - return nil - } -} - // Self-label values for this post. Effectively content warnings. type DraftDefs_DraftPost_Labels struct { LabelDefs_SelfLabels *comatproto.LabelDefs_SelfLabels diff --git a/lexicons/app/bsky/draft/defs.json b/lexicons/app/bsky/draft/defs.json index 85278e7b..4c6e20c5 100644 --- a/lexicons/app/bsky/draft/defs.json +++ b/lexicons/app/bsky/draft/defs.json @@ -96,10 +96,8 @@ "maxLength": 4 }, "embedGallery": { - "type": "array", - "items": { "type": "union", "refs": ["#draftEmbedImage"] }, - "maxLength": 20, - "description": "The schema-level maxLength of 20 is a future-proof ceiling. Clients should currently enforce a soft limit of 10 items in authoring UIs." + "type": "ref", + "ref": "#draftEmbedGallery" }, "embedVideos": { "type": "array", @@ -173,6 +171,22 @@ } }, + "draftEmbedGallery": { + "type": "object", + "required": ["items"], + "properties": { + "items": { + "type": "ref", + "ref": "#draftEmbedGalleryItems" + } + } + }, + "draftEmbedGalleryItems": { + "type": "array", + "items": { "type": "union", "refs": ["#draftEmbedImage"] }, + "maxLength": 20, + "description": "The schema-level maxLength of 20 is a future-proof ceiling. Clients should currently enforce a soft limit of 10 items in authoring UIs." + }, "draftEmbedImage": { "type": "object", "required": ["localRef"], -- 2.51.2