Open james-atlasopen opened 1 month ago
Hey, can you share the purpose for which you are reading the schema_name
?
@thetutlage The purpose is to dynamically populate a form with fields depending on the type.
i.e., name
is a string, so use a text input, age
is a number, so use a number input.
The goal is that we can reuse the Vine schema for this information (essentially, the Vine schema is the "source of truth"), instead of creating another object with the mappings.
The schema_name
property is for internal usage via unionOfTypes
schema type and using it for other purposes may not provide the desired results.
So, for your use-case, you can use the JSON
representation of the schema.
const validator = vine.compile(
vine.object({
})
)
console.log(validator.toJSON())
Ah, I see.
The toJSON()
representation doesn't appear to give the type as "string", "number", "boolean", etc. Only "literal".
Is there a way to get this type information? Ultimately we just want to know the primitive type of a Vine schema object/property.
Yeah. It will be nice to encode that info. Lemme do that
May I make a request that it be exposed in both the compiled toJSON()
representation, and the schema.getProperties()
object?
Thank you for looking at this, it's really only a minor thing in the grand scheme of things, but it does mean less technical maintenance for us, so it is greatly appreciated.
Package version
2.1.0
Describe the bug
When using a modifier on a schema, e.g.,
.optional()
, you can no longer get the schema name.Example:
Reproduction repo
No response