Astro Info
Astro v6.2.2
Node v22.22.0
System Linux (x64)
Package Manager unknown
Output static
Adapter none
Integrations @astrojs/mdx
@astrojs/sitemap
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
This is a follow-up to #13536.
I have tested again after upgrading Astro to v6.2.2 (from v5.5.6). The build passes cleanly.
The issue still exists: the file() loader with an object schema still generates an incorrect JSON schema when the source JSON is an array.
Reproduction summary:
src/data/dogs.json: an array of objects, each with {id, name}
[
{
"id": 1,
"name": "lab"
},
{
"id": 2,
"name": "yorkie"
}
]
src/content.config.ts: uses file() loader with schema z.object({ id: z.number(), name: z.string() })
import { file } from 'astro/loaders';
import { defineCollection, z } from 'astro:content';
const dogsCollection = defineCollection({
loader: file('src/data/dogs.json'),
schema: z.object({
id: z.number(),
name: z.string(),
}),
});
export const collections = { dogs: dogsCollection };
- Running
npm run sync produces .astro/collections/dogs.schema.json like below:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"$schema": {
"type": "string"
}
},
"additionalProperties": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"name": {
"type": "string"
}
},
"required": [
"id",
"name"
]
}
}
Expected: Since dogs.json is an array, the generated schema should be type: "array" (with items), not an object with additionalProperties. The current schema causes VS Code JSON validation to flag the file as invalid, since the schema reports an object but the file is actually an array.
What's the expected result?
When file() loader is given a top-level array JSON file, Astro should output a schema with type: array (not object), so that VS Code's JSON/YAML validation works without having to change content shape to object-map.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-wuk59bem-jrik786q?file=.vscode%2Fsettings.json
Participation
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
This is a follow-up to #13536.
I have tested again after upgrading Astro to v6.2.2 (from v5.5.6). The build passes cleanly.
The issue still exists: the file() loader with an object schema still generates an incorrect JSON schema when the source JSON is an array.
Reproduction summary:
src/data/dogs.json: an array of objects, each with{id, name}[ { "id": 1, "name": "lab" }, { "id": 2, "name": "yorkie" } ]src/content.config.ts: usesfile()loader with schemaz.object({ id: z.number(), name: z.string() })npm run syncproduces.astro/collections/dogs.schema.jsonlike below:{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "$schema": { "type": "string" } }, "additionalProperties": { "type": "object", "properties": { "id": { "type": "number" }, "name": { "type": "string" } }, "required": [ "id", "name" ] } }Expected: Since
dogs.jsonis an array, the generated schema should betype: "array"(withitems), not an object withadditionalProperties. The current schema causes VS Code JSON validation to flag the file as invalid, since the schema reports an object but the file is actually an array.What's the expected result?
When file() loader is given a top-level array JSON file, Astro should output a schema with type: array (not object), so that VS Code's JSON/YAML validation works without having to change content shape to object-map.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-wuk59bem-jrik786q?file=.vscode%2Fsettings.json
Participation