This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-17
Channels
- # announcements (6)
- # babashka-sci-dev (6)
- # beginners (99)
- # biff (3)
- # cider (4)
- # clerk (44)
- # clj-kondo (2)
- # clojure (65)
- # clojure-europe (57)
- # clojure-germany (5)
- # clojure-nl (1)
- # clojure-norway (13)
- # clojure-spec (19)
- # clojure-uk (3)
- # clojurescript (8)
- # conjure (3)
- # cursive (21)
- # datahike (19)
- # datomic (1)
- # events (7)
- # fulcro (14)
- # graalvm (3)
- # gratitude (1)
- # guix (5)
- # honeysql (1)
- # humbleui (19)
- # hyperfiddle (39)
- # lsp (4)
- # malli (7)
- # music (1)
- # off-topic (33)
- # pathom (65)
- # re-frame (9)
- # reagent (3)
- # reitit (6)
- # releases (1)
- # sql (15)
- # tools-build (7)
- # vim (5)
- # xtdb (16)
I'd like to be able to take existing instances of java classes and wrap them such that method calls are generally delegated to the wrapped object, except for any overrides I specify (which also need to be able to call the wrapped class). Pretty sure I could do this with gen-class
, but I believe that means I also need to hand-author all of the delegating methods. Is there some library or function which just lets you override selected methods on a class instance without the boilerplate?
What do you mean by wrap them? Would you be calling these methods from java or clojure? Are you talking about generating a new class that has the same methods or trying to monkey patch classes somehow?
Monkey patch. Specifically, I want to extend the implementation of java.sql.Connection
to include some extra schema meta-data for consumption by honeyeql and graphqlize.
I'd need to do something like pass in a custom instance of java.sql.DataSource
which provides an instance of my monkey-patched java.sql.Connection
.
java.sql.Connection is an interface, so you don't need to monkey patch. You can just create a new instance that also implements java.sql.Connection
.
I'm not super familiar with honeysql and graphqlize, but there's probably a more idiomatic way to get what you want too.
Right, but I'm going to want to use the existing MySQL implementation, and just monkey-patch the bits I need (which would include calling through to the MySQL instance.
Can you give a little more background on why the existing implementation isn't working for you?
I'm not seeing any other way to do this without forking honeyeql. The schema-related stuff is pretty much hardwired, which does make sense. The issue I'm trying to address is that MySQL views don't provide any schema info about foreign keys, so honeyeql (and hence graphqlize) don't know how to navigate from an entity defined by a MySQL view to a foreign key reference from the original table.
Given an existing instance, it would be pretty easy to create a new instance that adds the bits of functionality you're interested in using proxy
or reify
. It wouldn't apply to every instance, but it should be workable.
There are some limitations to proxy
and reify
which I don't think will get in your way, but in some cases, it may make sense to either write a small bit of java or use https://github.com/jgpc42/insn.
There's also a #C66EM8D5H channel that can probably give you more specific advice.
Hello clojurians ! Is there a way to change the name of a body parameter in the swagger ? Here's a screenshot below.
What did you use to generate the Swagger JSON? (Or whatever it is that ends up creating this web page)
metosin/reitit
Yes, I dont want it to use body
as the name by default.
Here's how my route is defined :
(def routes
[["/"
{:swagger {:tags ["Authentication"]}
:middleware
[wrap-json-params
wrap-keyword-params
wrap-spec
wrap-json-response]}
["authentication"
{:post
{:spec ::authentication/authentication#post.body
:handler handle-authentication
:summary "Authenticate user"
:name "Authenticate user"
:body "Authenticate user"
:description "TODO abstract description"
:parameters {:body ::authentication/authentication#post.body}}}]]])
I've tried :body and :name. It doesn't work.
Any idea ?are you talking about ::authentication/authentication#post.body
or that you pass this to the :body
?
If it's the former you should be able to define it as you wish?
If it's the latter, that's part of the http standard. You put the data you want to send into the body of a HTTP message.
Sorry if it's obvious, but I'm confused.
Sorry if I'm not clear. I'm talking about the rs.metav.request.api.authentication/authentication#post.body in the screenshot. I want to change it to something else in the swagger. By default, it takes the path of the body param which I dont want.
Ah, I wondered where that #
came from. :)
Just in case - while it works, note that it's not a valid character for keywords. No idea whether it can lead to any problems, but I wouldn't use it.
I've tried without it, it didnt solve my problem
Judging by the source, you can require [spec-tools.core :as st]
and then wrap you spec in (st/spec ... {:name "body data"})
.
I was curious how this page was generated -> https://clojuredocs.org/clojure.core and I get most of the way there with (sort (keys (ns-publics 'clojure.core)))
minus def
seemingly. I assume that because def
is needed for the vars in https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj that it's implementation is actually somewhere else. Perhaps I am overlooking a few things, but I thought this would be a good question for this channel. 😄
@U0ETXRFEW yes? I think so, haha. I am actually unfamiliar
Oh, I meant a special form. Thanks @U11BV7MTK!
@U03810HB7QS Clojure the language is bootstrapped from some first special forms, 14 I think they are. def
fn
, are amongst them. Then core functions and macros are build from these, and then more core functions and macros built from these and so on. You might want to try the Getting Started REPL in Calva, which tries to get this across in an interactive way, using the REPL.
Actually, looking at core.clj
I see that fn
is defined there.
(def
^{:macro true
:added "1.0"}
fn (fn* fn [&form &env & decl]
(.withMeta ^clojure.lang.IObj (cons 'fn* decl)
(.meta ^clojure.lang.IMeta &form))))
It is a special special form. 😃reading this closely -> https://clojure.org/reference/special_forms is filling in some blanks, for sure
If its of interest, I did a small random function generator which would show a public function (and its metadata) from clojure.core or any namespace provided https://practical.li/clojure/simple-projects/random-clojure-function/
Is there a way to type hint (or cast) from a direct child of java.lang.Object
to Object
? Trying to type hint function args seems to have no effect. And I'm curious why if I write some (contrived) code like (type (first (object-array ["foo"])))
I still get java.lang.String
.
Hey guys. Spec question:
(s/def ::year (s/and int? #(< 1900 % 2150)))
(s/def ::month (s/and int? #(<= 1 % 12)))
(s/def ::start-date (s/keys :req [::year ::month]))
(generate (s/gen ::year)) ; Gave 2039
(generate (s/gen ::month)) ; Gave 7
This is all nice, simple and it works. The issue is when I try (generate (s/gen ::start-date))
, which fails with:
Error: Couldn't satisfy such-that predicate after 100
What the hell? It's just composing two fields together.It's CLJS, but that shouldn't matter.
I would personally use :req-un in the keys spec and if it still fails, write a generator function
the sad reality of spec is that most interesting schemas are going to be too hard to generate randomly and youll simply have to write generators for most of your stuff, but once you get the hang of it, it's not bad
what you're encountering is that some generator making guesses about the inputs to your arbitrary function, and it might take a very long time if you have a picky predicate
so (s/and int? #(< 1900 % 2150)) generates using int? and then throws away stuff that doesn't pass #(< 1900 % 2150)
so the more a/and stuff you combine together the less likely it is that you will be able to generate something successfully
Confirmed: s/int-in
is the solution here.
And for other similar cases, s/and
or not, it should be possible to write a custom generator.
I'm a lazy bastard. If the computer can do it, why should I? @U2FRKM4TW
well, I expect s/int-in and related stuff to have reasonably "good" generators ootb, but again, any interesting spec, like a string representing a valid IP address, will simply need a custom generator
That's fair enough.