This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-09
Channels
- # announcements (16)
- # babashka (28)
- # beginners (27)
- # calva (39)
- # chlorine-clover (6)
- # cider (8)
- # clara (28)
- # cljs-dev (19)
- # cljsrn (22)
- # clojure (78)
- # clojure-australia (3)
- # clojure-europe (64)
- # clojure-nl (3)
- # clojure-norway (14)
- # clojure-spec (2)
- # clojure-uk (11)
- # clojurescript (11)
- # core-async (24)
- # datomic (3)
- # deps-new (5)
- # emacs (9)
- # fulcro (4)
- # gis (2)
- # graalvm (9)
- # honeysql (2)
- # hoplon (5)
- # instaparse (1)
- # introduce-yourself (5)
- # jobs (5)
- # luminus (4)
- # observability (7)
- # off-topic (6)
- # pathom (18)
- # pedestal (5)
- # polylith (4)
- # re-frame (2)
- # reagent (1)
- # reitit (1)
- # remote-jobs (7)
- # shadow-cljs (47)
- # specter (1)
- # sql (27)
- # testing (6)
- # tools-deps (4)
- # vim (3)
- # xtdb (8)
I have a question about returning a JSON response. I am trying to return a map like this: (def Product {:id int :product_id int :product string? :package_type string? :package_type_description string? :is_discrete string? :category string? :manufacturer string? :brand string? :image string? :tag string? :weight float :unit string? :uom_id int :catalogue_id int :price float? :sale_price float? :price_with_tax float? :tax_category_id int? :tax_rate string? :tax_fields string?}) (def Products [Product]) And I have a route setup to return the list of products like this: ["/products-search" {:get {:summary "Returns the list of product details by name" :parameters {:query {:search string?}} :responses {200 {:body {:products Products}}} :handler (fn [{{{:keys [search]} :body} :parameters}] (do (def products (db/get-products-details-by-name {:name-like (str search "%")})) {:status 200 :body {:products products}}))}}] However, I am getting an error when I try and execute this from withing Swagger-UI. The error message I am getting is:
{
"spec": "(spec-tools.core/spec {:spec (clojure.spec.alpha/keys :req-un [:spec$21193/products]), :type :map, :leaf? false})",
"problems": [
{
"path": [
"products",
"price_with_tax"
],
"pred": "clojure.core/float?",
"val": 22,
"via": [
"spec$21193/products",
"spec$21193$products/price_with_tax"
],
"in": [
"products",
0,
"price_with_tax"
]
},
{
"path": [
"products",
"tax_fields"
],
"pred": "clojure.core/string?",
"val": null,
"via": [
"spec$21193/products",
"spec$21193$products/tax_fields"
],
"in": [
"products",
0,
"tax_fields"
]
},
{
"path": [
"products",
"tax_rate"
],
"pred": "clojure.core/string?",
"val": null,
"via": [
"spec$21193/products",
"spec$21193$products/tax_rate"
],
"in": [
"products",
0,
"tax_rate"
]
},
{
"path": [
"products",
"brand"
],
"pred": "clojure.core/string?",
"val": null,
"via": [
"spec$21193/products",
"spec$21193$products/brand"
],
"in": [
"products",
0,
"brand"
]
},
{
"path": [
"products",
"sale_price"
],
"pred": "clojure.core/float?",
"val": 22,
"via": [
"spec$21193/products",
"spec$21193$products/sale_price"
],
"in": [
"products",
0,
"sale_price"
]
},
There is more but truncating to this point for now. Some of the fields such as "tax_rate" could have null values. Would really appreciate some pointers