Skip to content

Standard JSON Schema Default Values #1575

@logaretm

Description

@logaretm

When trying out the recent Standard JSON Schema API like this:

const schema = type({
  firstName: 'string = "First"',
  lastName: 'string = "Last"',
});

const input = schema['~standard']['jsonSchema'].input({ target: "draft-07" });
console.log(input);

I noticed that the JSON schema doesn't have default values included:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "firstName": {
            "type": "string"
        },
        "lastName": {
            "type": "string"
        }
    }
}

When compared to other implementers like valibot and zod, I get the following:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "firstName": {
            "default": "First",
            "type": "string"
        },
        "lastName": {
            "default": "Last",
            "type": "string"
        }
    }
}

What I'm working on

I'm implementing a few functionalities that plan to consume standard JSON schemas for forms, one of those features is default value resolution in formwerkjs/formwerk#238

This will also be ported to vee-validate v5 since v4 had that capability via resolvers which is dropped in favor of standard schema support.


So is there any plans to support that? I'm not sure if there was a discussion about it. Happy to try PRing it if that's something arktype will be willing to support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    To do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions