Skip to content

Add resource configuration to disable automatic ID generation #259

@wolfgang42

Description

@wolfgang42

I have some resources whose IDs are integers auto-generated by the database server. I declare them as:

jsonApi.define({
    resource: 'Order',
    attributes: {
        id: jsonApi.Joi.number().integer(),
        // Other attributes
    },
    handler: customHandler,
})

This causes a problem when I try to create a new ID: a UUID is automatically generated, but then fails validation because it is not an integer.
I therefore propose a new key in the resource definition, generateId, which can be set to false to disable autogenerating IDs. I have implemented this on my branch create-generate-id, and it is working well for my use so far.
In the future this key could also be extended to take a function which returns an ID, so a project could define its own ID generation scheme. (For example using shortid; or perhaps even a content-addressable system where a data property is hashed to generate the ID.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions