This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-22
Channels
- # ai (1)
- # announcements (4)
- # babashka (23)
- # beginners (27)
- # biff (17)
- # calva (5)
- # clerk (6)
- # clj-commons (27)
- # clj-kondo (35)
- # clojars (12)
- # clojure (27)
- # clojure-denver (3)
- # clojure-europe (71)
- # clojure-norway (7)
- # clojure-spec (5)
- # clojure-uk (2)
- # clojurescript (45)
- # data-science (9)
- # datomic (4)
- # dev-tooling (2)
- # devcards (1)
- # hoplon (2)
- # hyperfiddle (36)
- # introduce-yourself (3)
- # malli (11)
- # missionary (2)
- # off-topic (63)
- # polylith (5)
- # rdf (2)
- # reagent (12)
- # schema (1)
- # shadow-cljs (11)
- # sql (6)
- # tools-deps (23)
- # xtdb (6)
Hello, I'm trying to work with both s/conditional
and abstract-map
but it does not work as I expect. I want to use s/conditional
to distinguish 2 kinds of sftp
connections and use abstract-map
to distinguish 2 kinds of transfer types. the code is:
(def base-sftp-schema
{:name s/Str
:account ObjectId
:type (s/eq "sftp")
:host s/Str
:port (s/maybe s/Int)
:path (s/maybe s/Str)
:user s/Str})
(def SftpSchema
(letfn [(login-mode= [x] #(= x (:login_mode %)))]
(s/conditional
(login-mode= "password") (merge base-sftp-schema
{:type (s/eq "sftp")
:login_mode (s/eq "password")
:password s/Str})
(login-mode= "private_key") (merge base-sftp-schema
{:type (s/eq "sftp")
:login_mode (s/eq "private_key")
:credentials_key s/Str}))))
(def TransferCreateBody
(abm/abstract-map-schema :type {:account ObjectId
:name s/Str}))
(abm/extend-schema GcsTransferCreateBody TransferCreateBody ["gcs"]
{:bucket_name s/Str
(? :path) s/Str
:credentials_key s/Str})
(abm/extend-schema SftpTransferCreateBody TransferCreateBody ["sftp"]
SftpSchema)
When I test SftpSchema
alone, everything is ok:
(s/validate SftpSchema {:type "sftp"
:account (ObjectId.)
:name "Transport SFTP"
:host ""
:port 22
:path "/export/data"
:user "fifou"
:login_mode "password"
:password "secret"})
=> {:path "/export/data",
:password "secret",
:login_mode "password",
:name "Transport SFTP",
:type "sftp",
:port 22,
:account #oid"649442876a5b1f11d8b13d93",
:host "",
:user "fifou"}
But when I test the TransferCreateBody
, result is a failure:
(s/validate TransferCreateBody {:type "sftp"
:account (ObjectId.)
:name "Transport SFTP"
:host ""
:port 22
:path "/export/data"
:user "fifou"
:login_mode "password"
:password "secret"})
=> Execution error (IllegalArgumentException) at schema.core/eval18272$fn$G (core.clj:110).
No implementation of method: :spec of protocol: #'schema.core/Schema found for class: nil
Can someone tell me what I am doing wrong? 🙏