Fork me on GitHub
#clojure
<
2023-08-21
>
Raman Kashanok13:08:27

Hi all! Maybe you know how to solve next issue: I’m using metosin/reitit, ring-swagger-ui, ring-swagger, malli to build my app. And I need to pass only one header to the endpoint:

["/test" {:get {:summary    "testing header"
                        :parameters {:header (m/schema [:map [:account-id string?]])}
                        :responses  {200 {:body response-schema/some-response}}
                        :middleware [log-middleware]
                        :handler    (fn [request]
                                      (query-handler/handle-request request))}
                  }]
but calling this endpoint with required ‘account-id’ header leads to next exception:
{
  "humanized": {
    "referer": [
      "disallowed key"
    ],
    "user-agent": [
      "disallowed key"
    ],
 ... lot more headers ...
    "accept-language": [
      "disallowed key"
    ],
    "accept": [
      "disallowed key"
    ]
  }
}

Raman Kashanok13:08:19

So the question is how to allow swagger to read this required header for UI, and how to skip all other headers check?

dpsutton13:08:23

What is the error message saying is the problem?

Raman Kashanok13:08:42

for me - this is an error 🙂 It’s just not valid schema. Maybe I wrote not clearly 🙂

dpsutton13:08:29

You wrote clearly and the error message is clear. What is it saying

Raman Kashanok13:08:24

it says that I’m sending lots of disallowed keys ) But it’s not me it’s swagger 🙂 and I want to find possibility to check only ‘account-id’ header and skip all other headers

Raman Kashanok13:08:04

but more I’m trying, more I’m figuring out that I’m dumb… )

dpsutton13:08:49

no no. you aren’t dumb

dpsutton13:08:14

but your schema is overly restrictive. You’ve said that the only allowed header key is account-id . But regular http requests include lots of headers to do their work, like user agent, accept-language, accept, etc. So you’re kinda telling the http apparatus that it’s not allowed to do its job. And swagger is following your instructions saying, “this request is invalid. there is only one acceptable header value and you sent lots of other ones. denied”

Raman Kashanok13:08:55

I think I’m not only one and first person, who interested in such validation possibility ) maybe there are any sources where I can find how it could be done?

dpsutton13:08:55

normally people pass keys like you are in the body or in the route. But if you want this information in the header, relax your schema to ignore the other keys

Raman Kashanok13:08:21

Newer did it, but if you say it’s the way - I’ll try 🙂

dpsutton13:08:11

i don’t know what you’re trying to do so do just blindly follow my “solution”. Just understand the issue. There are lots of headers that clients are going to put. If you restrict it to not allow them, you’re gonna have these errors

dpsutton13:08:41

but interestingly (malli.core/validate (malli.core/schema [:map [:a int?]]) {:a 1 :b 2}) is true for me. So i’m not sure why your schema is “closed”. Maybe add {:closed false} after :map as an argument

Raman Kashanok14:08:20

will try in a few min

Raman Kashanok14:08:03

it works… I tried a lot of things, but not to pass {:closed false} 🤯

Raman Kashanok14:08:07

thanks a lot!

👍 2
Karthikeyan A K13:08:55

Hello All, why we get error when we try to convert list of lists into a map as shown below?

(def list-of-vectors
  (list [:a 1] [:b 2])) ; ([:a 1] [:b 2])

(into {} list-of-vectors) ; {:a 1, :b 2}

(def list-of-lists
  (list (list :a 1) (list :b 2))) ; ((:a 1) (:b 2))

(into {} list-of-lists) ; error, why?
I thought both will be treated as sequence of sequences in Clojure.

Ben Sless13:08:20

Special case, you can conj a vector of size 2 into a map, but not a list

Joshua Suskalo13:08:04

you can use

(into {} (map vec) list-of-lists)

daveliepmann13:08:36

https://clojureverse.org/t/why-only-vectors-into-map/4966/2?u=dave.liepmann (and don't miss Alex's point in the next comment about indexing versus iterating)

vncz17:08:30

How do I replicate @attribute in Clojure? I am doing @EdmEntitySet true - but I am receiving a warning when doing so Is that something I should just ignore?

hiredman17:08:34

I don't mess with annotations much, but it looks like it is expecting the string "true" and when given the boolean true it is complaining about the mismatch, and printing out the value true as java.lang.Boolean[true] for whatever reason

vncz19:08:04

@U0NCTKEV8 How did you spot that the requested type is string?

vncz19:08:13

I can't see anything in such warning line that suggests that

hiredman19:08:01

Just guessed, another option is maybe it doesn't like the boxed Boolean and wants a primitive boolean, in which case you are out of luck

vncz19:08:35

Oh ok, so check out the source code. Fair enough!

leif19:08:10

Can anyone point me to the people who run Ideaogram (and/or make the cursive ide)?

seancorfield19:08:59

There's a #C0744GXCJ channel and @U0567Q30W is usually very responsive (but he's on NZ TZ so account for that time-of-day shift).

leif19:08:13

Got it, thanks.

leif19:08:38

I'm looking for work, and I thought that adding some of the features of my IDE (https://visr.pl) to cursive would be a really good fit.

seancorfield19:08:50

There's an #C050UG324GM channel if you want to tell people about your skills and what you're looking for.

leif19:08:05

Thank you!

leif19:08:28

(Looking at that channel, it looks like a lot of people posting that they're available, but no many responses.) I'll post anyway, but thanks. 🙂

seancorfield19:08:10

It's a channel for posting -- the expectation is that companies follow-up via DM. If you want to see what folks are posting in terms of jobs, there's #C05006WDW and #C06B40HMY

seancorfield19:08:43

(and few responses there because, again, the expectation is folks follow-up directly with the job poster or company website)

leif19:08:59

Got it, thanks.