Re: spec key aliasing or different specs for same keyword

2017-12-29 Thread Gary Verhaegen
You could always extract specific keys from the payload and validate that,
something like:

(GET "/..." req
  (let [b (:body req)
data {:my/result (:resultCount b)
  :my/other-key (get-in b [:some :path])}]
(my-business-logic data)))

i.e. spec what your code (my-business-logic here) expects, not the API call
itself.

On 28 December 2017 at 19:09, Jonathon McKitrick 
wrote:

> Yes, the namespacing is great, so I have no issue with that. I would just
> rather use snake-case in Clojure than camel-case. Since the payload has
> 'resultCount' I'd like to map that to a spec named result-count instead.
>
> I think I figured out part of the answer:
>
> (s/def :my/result int?)
> (s/def :your/result pos-int?)
> (s/def ::test-spec-1 (s/keys :req-un [:my/result]))
> (s/def ::test-spec-2 (s/keys :req-un [:your/result]))
>
> I see here that I can have an unqualified keyword as part of a qualified
> spec name. I think that's what I want.
>
> On Thursday, December 28, 2017 at 12:26:59 PM UTC-5, adrian...@mail.yu.edu
> wrote:
>>
>> Avoiding global name collision is the reason why specs are named with
>> namespace-qualified keywords. I am confused by your last sentence though.
>> Do you mean Clojure namespaces or the namespace component of the keyword
>> itself? There is no requirement in clojure.spec that the namespace of the
>> specs you def be coupled to the Clojure namespace they happen to be defined
>> in. If you are actually asking about how to write specs for unqualified
>> keys in a map there is a built-in facility to do that as well:
>> clojure.spec.alpha/keys has a :req-un and :opt-un argument.
>>
>> On Thursday, December 28, 2017 at 11:28:18 AM UTC-5, Jonathon McKitrick
>> wrote:
>>>
>>> I have one spec question covering two scenarios.
>>>
>>> 1. Suppose I want to spec a payload from a third-party API that has the
>>> keyword ':resultCount' in it. Does that mean my specs for that item must
>>> have the same name?
>>>
>>> 2. Supposed I have a few payloads from that API and each has a keyword
>>> ':result' but the spec for each will be different. Other than using an
>>> entirely different namespace, how can I map the :result keyword to
>>> different specs?
>>>
>>> Thanks!
>>>
>> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: spec key aliasing or different specs for same keyword

2017-12-28 Thread Jonathon McKitrick
Yes, the namespacing is great, so I have no issue with that. I would just 
rather use snake-case in Clojure than camel-case. Since the payload has 
'resultCount' I'd like to map that to a spec named result-count instead.

I think I figured out part of the answer:

(s/def :my/result int?)
(s/def :your/result pos-int?)
(s/def ::test-spec-1 (s/keys :req-un [:my/result]))
(s/def ::test-spec-2 (s/keys :req-un [:your/result]))

I see here that I can have an unqualified keyword as part of a qualified 
spec name. I think that's what I want.

On Thursday, December 28, 2017 at 12:26:59 PM UTC-5, adrian...@mail.yu.edu 
wrote:
>
> Avoiding global name collision is the reason why specs are named with 
> namespace-qualified keywords. I am confused by your last sentence though. 
> Do you mean Clojure namespaces or the namespace component of the keyword 
> itself? There is no requirement in clojure.spec that the namespace of the 
> specs you def be coupled to the Clojure namespace they happen to be defined 
> in. If you are actually asking about how to write specs for unqualified 
> keys in a map there is a built-in facility to do that as well: 
> clojure.spec.alpha/keys has a :req-un and :opt-un argument.
>
> On Thursday, December 28, 2017 at 11:28:18 AM UTC-5, Jonathon McKitrick 
> wrote:
>>
>> I have one spec question covering two scenarios.
>>
>> 1. Suppose I want to spec a payload from a third-party API that has the 
>> keyword ':resultCount' in it. Does that mean my specs for that item must 
>> have the same name?
>>
>> 2. Supposed I have a few payloads from that API and each has a keyword 
>> ':result' but the spec for each will be different. Other than using an 
>> entirely different namespace, how can I map the :result keyword to 
>> different specs?
>>
>> Thanks!
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: spec key aliasing or different specs for same keyword

2017-12-28 Thread adrian . medina
Avoiding global name collision is the reason why specs are named with 
namespace-qualified keywords. I am confused by your last sentence though. 
Do you mean Clojure namespaces or the namespace component of the keyword 
itself? There is no requirement in clojure.spec that the namespace of the 
specs you def be coupled to the Clojure namespace they happen to be defined 
in. If you are actually asking about how to write specs for unqualified 
keys in a map there is a built-in facility to do that as well: 
clojure.spec.alpha/keys has a :req-un and :opt-un argument.

On Thursday, December 28, 2017 at 11:28:18 AM UTC-5, Jonathon McKitrick 
wrote:
>
> I have one spec question covering two scenarios.
>
> 1. Suppose I want to spec a payload from a third-party API that has the 
> keyword ':resultCount' in it. Does that mean my specs for that item must 
> have the same name?
>
> 2. Supposed I have a few payloads from that API and each has a keyword 
> ':result' but the spec for each will be different. Other than using an 
> entirely different namespace, how can I map the :result keyword to 
> different specs?
>
> Thanks!
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


spec key aliasing or different specs for same keyword

2017-12-28 Thread Jonathon McKitrick
I have one spec question covering two scenarios.

1. Suppose I want to spec a payload from a third-party API that has the 
keyword ':resultCount' in it. Does that mean my specs for that item must 
have the same name?

2. Supposed I have a few payloads from that API and each has a keyword 
':result' but the spec for each will be different. Other than using an 
entirely different namespace, how can I map the :result keyword to 
different specs?

Thanks!

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.