Skip to content

🐛 [Bug]: Asset type does not reflect API response (is_private and Cloudinary fields missing / not optional) #488

@Michael-Janke

Description

@Michael-Janke

Package

storyblok (CLI)

Bug Description

Link to type definition

https://github.com/storyblok/monoblok/blame/main/packages/cli/src/types/storyblok.ts#L15

Description

The generated TypeScript type for Storyblok image assets does not fully match the shape returned by the API.

In particular, some properties appear conditionally in the API response, but the type definition assumes a stricter structure.

For example, the field is_private sometimes appears in the asset response and sometimes does not.

Example responses from the same space:

Example 1:

{
  "backgroundImage": {
    "id": 1,
    "alt": "",
    "name": "",
    "focus": "",
    "title": "",
    "source": "",
    "filename": "https://a.storyblok.com/f/...",
    "copyright": "",
    "fieldtype": "asset",
    "meta_data": {},
    "is_external_url": false
  }
}

Example 2:

{
  "id": 2,
  "alt": "",
  "name": "",
  "focus": "",
  "title": "",
  "source": "",
  "filename": "https://a.storyblok.com/f/...",
  "copyright": "",
  "fieldtype": "asset",
  "meta_data": {},
  "is_private": false,
  "is_external_url": false
}

is_private is sometimes included and sometimes omitted.

Additionally, fields related to Cloudinary integrations can also appear in asset responses depending on configuration.

Expected behavior

The generated asset type should mark these fields as optional:

  • is_private
  • Cloudinary-related properties (when present)
  • Any other conditionally returned asset properties

Example adjustment:

type StoryblokAsset = {
  id: number
  alt?: string
  name?: string
  focus?: string
  title?: string
  source?: string
  filename: string
  copyright?: string
  fieldtype: "asset"
  meta_data?: Record<string, unknown>

  is_external_url?: boolean
  is_private?: boolean

  // Cloudinary integration fields (optional)
  width?: number
  height?: number
...
}

Why this matters

The current type definitions can cause TypeScript errors or incorrect assumptions about the API response structure when consuming assets in generated types.

Making these fields optional would better reflect the actual API responses.

Steps to Reproduce

Initialize a project using Storyblok and generate types using the monoblok CLI.

Use an asset field in a component schema.

Fetch content that contains that asset.

Inspect the API response.

Notice that some responses contain is_private while others do not.

Expected Behavior

The generated asset type should reflect the actual API response structure.

Conditionally returned properties such as:

is_private

Cloudinary-related properties

should be optional in the generated type.

Actual Behavior

The generated type assumes a fixed structure for assets, but the API returns slightly different shapes depending on configuration and asset state.

This can cause incorrect TypeScript assumptions when consuming the generated types.

Code Sample

Environment

-

Error Logs

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions