Replies: 2 comments 1 reply
-
The new CLI uses extension setting the import { schema } from '@feathersjs/schema';
export const userDataSchema = schema({
$id: 'UserData',
type: 'object',
additionalProperties: false,
required: ['email', 'password'],
properties: {
id: { type: 'number' },
email: { type: 'string' },
password: { type: 'string' }
}
});
export const userPatchSchema = schema({
$id: 'UserPatch',
type: 'object',
additionalProperties: false,
required: [],
properties: {
...userDataSchema.properties
}
}); |
Beta Was this translation helpful? Give feedback.
0 replies
-
That works, but will still accept null values (and convert them to empty string, for strings). I guess I can set minLength to prevent this for strings. Another question, feathers / json schema doesnt seem to handle uniqueness of properties. I can achieve this with hooks, but would rather have it set at database level. What would be the feathery way to achieve this using schemas? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I'm tempted to switch from mongoose models to use feathers schemas instead, as its much easier to share interfaces, validation etc with frontend.
I'm currently stuck on how to correctly create a patch resolver, the examples only mentions an "userPatchResolver".
If we take the UserSchema from the examples page. If I use the userDataResolver for a patch event and only updates the user email, it will throw an error with password missing, as it should.
I guess I could make a userPatchSchema, that extends userSchema and remove password from required properties, but this will still throw an error if not all other required properties are in the patch data.
I think the patch resolver should only resolve / validate the properties that are present in the patch data, but I'm not really sure if thats possible?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions