Skip to content

[BUG] generateCollections throws an error on arrays of media files. #9

@codesxt

Description

@codesxt

🐛 Bug Description

generateCollections throws an error on arrays of media files.

I have a content type called "Creations" with a 'mediaGallery' field that contains multiple media. When I call generateCollections and indicate which fields I want to populate, it works properly until I try to populate that field and I get this error:

[InvalidContentEntryDataError] creations → bl3kfrnc4xffigfb72974zsm data does not match collection schema.

  mediaGallery**: **mediaGallery: Expected type `"object"`, received `"array"`

  Hint:
    See https://docs.astro.build/en/guides/content-collections/ for more information on content schemas.
  Error reference:
    https://docs.astro.build/en/reference/errors/invalid-content-entry-data-error/
  Location:
    /home/bruno/Desarrollo/direccioncreacion/webrepositorio/node_modules/astro/dist/content/utils.js:157:26
  Stack trace:
    at getEntryDataAndImages (file:///home/bruno/Desarrollo/direccioncreacion/webrepositorio/node_modules/astro/dist/content/utils.js:157:26)
    at async parseData (file:///home/bruno/Desarrollo/direccioncreacion/webrepositorio/node_modules/astro/dist/content/content-layer.js:204:40)
    at async Promise.all (index 0)
    at async Promise.all (index 0)
    at async file:///home/bruno/Desarrollo/direccioncreacion/webrepositorio/node_modules/p-queue/dist/index.js:230:36

🔍 Steps to Reproduce

  1. Create a content type in strapi with a field with multiple media
  2. Call generateCollections in the content.config.ts file and populate the field with multiple media.
  3. Get the error.

💡 Expected Behavior

I would expect that field to be parsed properly as an array of media files.

💻 Environment

  • Astro Version: 5.14.1
  • Node Version: 20.13.0
  • OS: Linux

📝 Additional Context

This is how I'm generating the collection and it works:

strapiCollections = await generateCollections({
    url: import.meta.env.STRAPI_URL,
    token: import.meta.env.STRAPI_TOKEN,
  },
  [
    {
      name: "creations",
      query: {
        populate: [
          'featuredImage'
        ]
      },
    }, 
  ]
);

But if I add the mediaGallery to the populate array it gives the error.

I tried to use the generateStrapiSchema function but I could not understand very well how to use it since it is not documented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions