Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

declarative schemas #11

Closed
ikitommi opened this issue Jun 25, 2015 · 4 comments
Closed

declarative schemas #11

ikitommi opened this issue Jun 25, 2015 · 4 comments

Comments

@ikitommi
Copy link
Member

For web apps, Schemas are used to both validate & document the apis. Would be nice if one could create the schemas more declaratively. There could be a schema function in schema-tools that would read declarations (using multimethod dispatch) and create the needed schema structures for those.

Something like:

(require '[schma.core :as s])
(require '[schema-tools.core :as st])

(s/defschema Model 
  "Model description"
  {:size (st/schema s/Int {:min 10, :max 20, :description "number 10-20"})
   :gender (st/schema (s/enum :male :female) {:description "gender"})})
@mangolas
Copy link

How about describing schema in hiccup style

(s/defschema Model
  (st/schema 
    [:type/map {:description "Model description"} 
      [:size :type/int {:optional true 
                              :default 0 :min 10 :max 20
                              :description "number 10-20"}]
      [:gender :type/enum {:values [:male :female]
                                        :default :male
                                        :description "gender"}]]))

@Deraen
Copy link
Member

Deraen commented Jan 31, 2016

Could be alternative, but it would need to be converted to "real" Schema representation by some function. And we still need the Schemas for min/max etc.

@mangolas
Copy link

Sure, I meant it as a way to describe schema by end user, like me, who just want's to model api ins and outs. Internally it can be the "real" Schema or whatever.

@ikitommi
Copy link
Member Author

#32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants