brabster / crucible

AWS CloudFormation templates built with Clojure
Eclipse Public License 1.0
72 stars 18 forks source link

Spec for internet-gateway #119

Closed keerts closed 6 years ago

keerts commented 6 years ago

The following spec is playing with me:

(defresource internet-gateway (ec2 "InternetGateway") (s/? (s/keys :opt [::res/tags]))) If I read it correctly, both of the following should be conformant:

   :ig-next (ec2/internet-gateway)
   :ig-next (ec2/internet-gateway {::res/tags [{::res/key "Name" ::res/value "next"}]})

But the second form yields the following:

1. Unhandled clojure.lang.ExceptionInfo
   Invalid resource properties
   #:clojure.spec.alpha{:problems
                        ({:path [],
                          :pred map?,
                          :val
                          [:crucible.resources/tags
                           [#:crucible.resources{:key "Name",
                                                 :value "next"}]],
                          :via [],
                          :in [0]}),
                        :spec
                        {:clojure.spec.alpha/op :clojure.spec.alpha/alt,
                         :ps
                         (#object[clojure.spec.alpha$map_spec_impl$reify__1931 0x5ab09b8a "clojure.spec.alpha$map_spec_impl$reify__1931@5ab09b8a"]
                          {:clojure.spec.alpha/op
                           :clojure.spec.alpha/accept,
                           :ret :clojure.spec.alpha/nil}),
                         :ks nil,
                         :forms
                         ((clojure.spec.alpha/keys
                           :opt
                           [:crucible.resources/tags])
                          :clojure.spec.alpha/nil),
                         :maybe
                         (clojure.spec.alpha/keys
                          :opt
                          [:crucible.resources/tags])},
                        :value
                        #:crucible.resources{:tags
                                             [#:crucible.resources{:key
                                                                   "Name",
                                                                   :value
                                                                   "next"}]}}

Must be my lacking experience with spec, but I need a little help understanding the error. Any help appreciated.

keerts commented 6 years ago

Also, should ::tags be replaced by ::res/tags, like:

-(defresource internet-gateway (ec2 "InternetGateway") (s/? (s/keys :opt [::tags]))) +(defresource internet-gateway (ec2 "InternetGateway") (s/? (s/keys :opt [::res/tags])))

Again, my Clojure / spec experience might be lacking, any explanation greatly appreciated.

brabster commented 6 years ago

I think the s/? only works on sequences within s/cat. I think if you take that out it'll work but I haven't checked yet.

keerts commented 6 years ago

It can be s/nilable if you meant to make the map optional.

keerts commented 6 years ago

And it will also work when removing the s/? then you will always have to pass the empty map.