Skip to content

Commit 9a5aaf0

Browse files
committed
fix: compontent level generation of required fields
1 parent 9a3bd93 commit 9a5aaf0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sensinum/astro-strapi-loader",
3-
"version": "1.0.9-beta.1",
3+
"version": "1.0.9-beta.2",
44
"description": "Astro loader for Strapi CMS",
55
"keywords": [
66
"astro",

src/utils/schema.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ export class StrapiSchemaGenerator {
148148
schema = z.any();
149149
break;
150150
}
151-
if (attribute.conditions) {
152-
schema = schema.nullable();
151+
if (attribute.conditions && (attribute.type !== "media")) {
152+
schema = schema.nullable().optional();
153153
}
154154
return schema;
155155
}
@@ -169,7 +169,7 @@ export class StrapiSchemaGenerator {
169169
return {
170170
...acc,
171171
[key]:
172-
ref.strict && attribute.required
172+
ref.strict && attribute.required && !attribute.conditions
173173
? schema
174174
: schema.nullable().optional(),
175175
};
@@ -195,7 +195,7 @@ export class StrapiSchemaGenerator {
195195
const ref = this;
196196
const shape: Record<string, z.ZodTypeAny> = Object.entries(componentSchema.attributes).reduce((acc, [key, attribute]) => {
197197
const schema = ref.generateAttributeSchema(attribute);
198-
return { ...acc, [key]: schema };
198+
return { ...acc, [key]: ref.strict && attribute.required && !attribute.conditions ? schema : schema?.nullable().optional() };
199199
}, {});
200200

201201
return z.object(shape);

0 commit comments

Comments
 (0)