Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic default #2393

Closed
DrummerSi opened this issue May 30, 2019 · 3 comments · Fixed by #5001
Closed

Dynamic default #2393

DrummerSi opened this issue May 30, 2019 · 3 comments · Fixed by #5001

Comments

@DrummerSi
Copy link

DrummerSi commented May 30, 2019

I'd like to be able to specify a function for default values within a schema

The following schema use currently causes an error, due to the default timestamp field expecting a number, not a function:

export const TestSchema = {
    name: "TestItem",
    properties: {
        videoId:        "string",
        published:       "int",
        timestamp:      {
            type: "int",
            default: () => Math.round((new Date()).getTime() / 1000) 
        }
    }
}

The default function returns what is expected (a number). Could support be added to calculate default value functions? Or would that add to much overhead? I think it'd be perfect for use cases like this where you wish to store the current timestamp

@kneth
Copy link
Contributor

kneth commented Jul 8, 2019

@DrummerSi Sorry for the late reply. Yeah, we could as it but it will be costly to make a such callback. It is not so hard to implement. I like the idea and I'll add to the list of future improvements.

@lilingxi01
Copy link

Any update on this right now?

@kneth
Copy link
Contributor

kneth commented Mar 8, 2022

@lilingxi01 Unfortunately not.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants