Fork me on GitHub
#malli
<
2022-11-22
>
Hankstenberg09:11:57

What is the best way to tell if a given string is a valid malli schema? As I understand it this is a two-step process... first I need to determine if it's valid edn data and in a second step I have to determine if it's a valid malli schema. There is a schema called "`:schema` " in malli.core/base-schemas , but how do I use it properly?

1
ikitommi09:11:02

valid string like "[:enum :kikka :kukka]"?

Hankstenberg09:11:38

Well the idea is that the user provides a schema definition and I want to check if it's a valid malli schema, so something like "[:cat :int]", anything that can be turned into a schema with m/schema in the current context should be valid, everthing else I'd like to give proper error messages on.

Hankstenberg09:11:07

I'd like to humanize the output of "trying to use the input as a malli schema".

ikitommi09:11:35

without humanizing:

(malli.edn/read-string "[:enum :kikka :kukka]")
; => [:enum :kikka :kukka]

(malli.edn/read-string "[:enumz :kikka :kukka]")
; =throws=> :malli.core/invalid-schema {:schema :enumz}

Hankstenberg09:11:50

Yea, but is there a meta-schema for a malli schema? I thought it was maybe malli.core/base-schema/:schema

Hankstenberg09:11:52

It's got to be something that me/read-string does under the hood.

ikitommi09:11:03

there is no Malli Schema for Malli Schemas. There is support for it (each schema can define it's supported properties & schema for children), but no-one has had time to actually describe those.

Hankstenberg09:11:38

Okay good to know, thanks! 🙂