dohomi / storyblok-generate-ts

Generates TypeScript interface types based on Storyblok component file
MIT License
102 stars 33 forks source link

Multilink fieldtype can contain a story object when used with internal links #30

Closed schaschjan closed 1 year ago

schaschjan commented 1 year ago

API Response: { id: '105f42b4-3f71-4d7d-b5cc-c3d2971b1b57', url: '', linktype: 'story', fieldtype: 'multilink', cached_url: 'en/imprint', story: { name: 'Imprint', id: 156921521, uuid: '505f42b4-7f71-5d7d-a5ef-b3d2121b1b57', slug: 'imprint', url: 'en/imprint', full_slug: 'en/imprint', _stopResolving: true } }

Missing in MultilinkStoryblok type: `{ id?: string; cached_url?: string; anchor?: string; linktype?: "story";

}`

markus-gx commented 1 year ago

I mean it depends on the usage of the resolve_link parameter. When using resolve_links=url the output of the story object would be:

{
            "name": "abc",
            "id": 254692026,
            "uuid": "eb2c7a68-0cbd-4d94-bffa-448b27f7f8f0",
            "slug": "abc",
            "url": "abc",
            "full_slug": "abc"
        }

but when you resolve for the whole story - you receive the whole story object.

{
            "name": "abc",
            "created_at": "2023-01-31T05:52:25.967Z",
            "published_at": "2023-01-31T06:16:43.472Z",
            "id": 254692026,
            "uuid": "eb2c7a68-0cbd-4d94-bffa-448b27f7f8f0",
            "content": {
                "_uid": "d23b8035-ed5d-4129-a96e-0645979d5445",
                "name": "abc",
                "type": "loving-cat",
                "image": {
                    "id": 7045583,
                    "alt": "",
                    "name": "",
                    "focus": "",
                    "title": "",
                    "filename": "https://a.storyblok.com/f/194364/3024x4032/d7a2b2b9fc/img_4937.jpeg",
                    "copyright": "",
                    "fieldtype": "asset",
                    "is_external_url": false
                },
                "component": "cat",
                "_editable": "<!--#storyblok#{\"name\": \"cat\", \"space\": \"194364\", \"uid\": \"d23b8035-ed5d-4129-a96e-0645979d5445\", \"id\": \"254692026\"}-->"
            },
            "slug": "abc",
            "full_slug": "abc",
            "sort_by_date": null,
            "position": 0,
            "tag_list": [],
            "is_startpage": false,
            "parent_id": null,
            "meta_data": null,
            "group_id": "99edff7f-7816-46be-9969-00a0e9d1b8de",
            "first_published_at": "2023-01-31T05:54:15.602Z",
            "release_id": null,
            "lang": "default",
            "path": null,
            "alternates": [],
            "default_full_slug": null,
            "translated_slugs": null
        }

I guess we need to support both :P Just writing this down to ensure as soon as somebody or probably me is improving this functionality this will not be forgotten.