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

Easier way to add custom conforming #96

Closed
ikitommi opened this issue Dec 21, 2017 · 1 comment · Fixed by #116
Closed

Easier way to add custom conforming #96

ikitommi opened this issue Dec 21, 2017 · 1 comment · Fixed by #116

Comments

@ikitommi
Copy link
Member

Currently, to add a new dynamic conforming, one needs to do the following things:

  1. create a new type keyword, e.g. :color
  2. create a new type-conformer, with the new type-conforming options
  3. create a new Spec with the given predicate & type
  4. map how the new type should be rendered into different formats, like Swagger2

Instead, we should allow inlined type definitions, something like:

(require '[spec-tools.core :as st])

(st/spec
  {:name "Color"
   :spec color?
   :conforming/json string->color
   :conforming/string string->color
   :json-schema/type "string"
   :json-schema/default "white"})
@ikitommi
Copy link
Member Author

This works now in 0.6.2-SNAPSHOT:

(require '[spec-tools.core :as st])
(require '[spec-tools.conform :as conform])

(def spec
  (st/spec
    {:spec string?
     :description "a string spec"
     ::conform/json #(str %2 "-json")
     ::conform/string #(str %2 "-string")}))

(st/conform spec "kikka")
; "kikka"

(st/conform spec "kikka" st/json-conforming)
; "kikka-json"

(st/conform spec "kikka" st/string-conforming)
; "kikka-string"

@ikitommi ikitommi mentioned this issue May 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant