I tried to add the { additionalProperties : false} to one of my typebox schema
schema.ts
export const numericString = (options: { default: string }) =>
Type.String({
...options,
pattern: '^[0-9]+$'
});
export const commonQueryParamsWithPagination = Type.Object({
sort: Type.Optional(Type.String()),
page: numericString({ default: '1' }),
size: numericString({ default: '100' })
});
export const getUserRequestQuerySchema = Type.Intersect(
[
Type.Object({
status: Type.String()
}),
commonQueryParamsWithPagination
]
);
export const getUserRequestSchema = Type.Object({
query: getAllOrganizationRequestQuerySchema,
body: Type.Any(),
headers : Type.Any(),
params: Type.Any()
} , { additionalProperties: false });
This works if any other property is passed to the the top level,
In case we need to add this property to the query schema along with request schema
Option 1:
[
Type.Object({
status: Type.String()
}),
commonQueryParamsWithPagination
],
{ additionalProperties: false }
);
This approach make the all the property as additional property and is not allowed at all
In order make it work we need to make the query schema without Type.Intersect
and commonQueryParamsWithPagination
export const getUserRequestQuerySchema = Type.Object({
status: Type.String(),
sort: Type.Optional(Type.String()),
page: numericString({ default: '1' }),
size: numericString({ default: '100' })
}),
As there can be multiple conditions where I have reuse the existing schema so how would I make it work for { additionalProperties : false }
for neseted schema whihc need to reuse the existing schema ?