vine icon indicating copy to clipboard operation
vine copied to clipboard

Discussion for a new feature - KV store in schema

Open pomarec opened this issue 7 months ago • 6 comments

Hi,

I would have the need in different situation to be able to store some data in a schema.

Something like :

const email = vine.string().email()
email.extra({ description : "my awesome field" })
const description = email.extra('description')

If you're open to this, I'll be happy to fill a PR.

Best,

pomarec avatar Jun 17 '25 16:06 pomarec

I think it will be nice to have. Maybe we can call the method as .metadata or .kv and then define the arbitrary values.

Also, can you please how and where would you access these values?

thetutlage avatar Jun 18 '25 08:06 thetutlage

.metadata sounds good !

My usage is a bit complex. I use a library that transform lucid models to vine schema. I have another library that generates openapi spec based on those schema. But this lib does not generate the description of the field yet. I would like to add the description of a property in a lucid model and be able to channel it through the openapi schema.

eg:

export class Kid extends BaseModel {
  @VineModel(vine.string().metadata({
    description: "Name of the kid",
  }))
  @column()
  declare name: string
}

would generate

properties:
  kid:
    name:
      type: string
      description: Name of the kid

The openapi lib has access to the arg of @VineModel(), it would then be able to get it's metadata.

pomarec avatar Jun 19 '25 07:06 pomarec

Hi @thetutlage, Should I give it a try ?

pomarec avatar Jul 18 '25 08:07 pomarec

@pomarec Will the jsonSchema method from this PR serve your use-case as well? https://github.com/vinejs/vine/pull/118

Essentially, we will have a dedicated method to define the JSON schema on every field and the same will be available when calling schema.toJSON().

thetutlage avatar Jul 21 '25 05:07 thetutlage

@thetutlage thanks for pointing this PR I think my usage is exactly vine.string().meta({ description: "Hello world" }) mentioned in the original PR message. I don't understand if the following comments say it will be possible or not. But I think we are talking about the same thing anyway. Ok for me to close this issue.

pomarec avatar Jul 23 '25 15:07 pomarec

Yes, you will be able to set the description via the jsonSchema method. It will also act as a KV store, but typed to allow JSON schema values

thetutlage avatar Jul 24 '25 05:07 thetutlage