reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
Prem Kurian Philip 2021-06-09T07:52:17.086900Z

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