Discussion for a new feature - KV store in schema
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,
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?
.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.
Hi @thetutlage, Should I give it a try ?
@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 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.
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