Fork me on GitHub
#malli
<
2022-08-20
>
geraldodev00:08:33

I have a react form that has a input :type "date" and the stored value is a string "2022-08-01". How to check for valid date in malli with clojurescript ?

pppaul13:08:26

anyone here had success using malli.swagger?

pppaul14:08:27

{:info {:title "Site Map"},
 :paths {"" {:get {:parameters {:query {:type "object",
                                        :properties {:email {:type "string"}}},
                                :path {:type "object",
                                       :properties {:uuid {:type "string",
                                                           :format "uuid"}},
                                       :required [:uuid]},
                                :formData {:type "object",
                                           :properties {}}},
                   :responses {403 {:description "User tried to access something their not allowed to",
                                    :custom/template "mvp/error_pages/403.html"},
                               401 {:description "Bad Auth/Cookie gets a redirect to login"}},
                   :produces ("text/html")},
             :post {:parameters {:query {:type "object",
                                         :properties {:email {:type "string"}}},
                                 :path {:type "object",
                                        :properties {:uuid {:type "string",
                                                            :format "uuid"}},
                                        :required [:uuid]},
                                 :formData {:type "object",
                                            :properties {:email {:type "string"},
                                                         :otp {:type "array",
                                                               :items {:type "integer",
                                                                       :format "int64"}}},
                                            :required [:email :otp]}},
                    :responses {403 {:description "User tried to access something their not allowed to",
                                     :custom/template "mvp/error_pages/403.html"},
                                401 {:description "Bad Auth/Cookie gets a redirect to login"}},
                    :produces ("text/html"),
                    :consumes ("multipart/form-data")}},
         "/login3{uuid}" {}},
 :basePath "/swagger"}
this is what i'm giving it

Noah Bogart14:08:34

Maybe thread this discussion?

pppaul14:08:34

i'm using https://github.com/metosin/ring-swagger maybe this doesn't work anymore? (it's pretty old). i looked at some of the tests and my swagger objects look pretty similar to the ones in the tests. i get complaints from swagger-jsonfn saying it doesn't know how to convert my object into a swagger schema

pppaul14:08:19

looking at swagger's docs https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterObject i think malli.swagger is generating wrong data

pppaul14:08:21

well, malli.swagger output is throwing errors for the other library for swagger that metosin made. i don't know what to do

pppaul14:08:54

{
  "skipParam": {
    "name": "skip",
    "in": "query",
    "description": "number of items to skip",
    "required": true,
    "type": "integer",
    "format": "int32"
  },
  "limitParam": {
    "name": "limit",
    "in": "query",
    "description": "max records to return",
    "required": true,
    "type": "integer",
    "format": "int32"
  }
}
it's not outputting this style of object

pppaul14:08:18

i guess i have to study the swagger docs and make my own transformer

valtteri14:08:11

Please file an issue and we will look into it. 🙂

valtteri14:08:02

I'm not sure if Tommi has intended that malli.swagger should play along with ring-swagger

valtteri14:08:14

I don't also understand why would both be needed. AFAIK they both generate swagger.json

valtteri14:08:37

That you can use to render swagger ui

valtteri14:08:52

Difference being that ring-swagger can generate the json from plumatic schema / clojure.spec and malli.swagger does that for malli schemas

valtteri14:08:50

Uhhhmm.. Need to correct myself. Looks like malli.swagger produces "chunks" of swagger 2.0 compatible JSON, not the complete swagger doc.

pppaul14:08:57

ok, i did not know that

pppaul14:08:57

it makes sense that malli swagger wouldn't produce the whole swagger doc, i just don't know what to do with it's output

valtteri14:08:59

Which kinda makes sense since Malli knows only about the shape of data. It doesn't know anything about route definitions and other stuff that goes into swagger spec

valtteri14:08:22

Are you using reitit by any chance?

valtteri14:08:31

Because there's reitit.swagger

pppaul14:08:03

i was hacking on yada swagger to try to get it working with malli

pppaul14:08:17

changing over to reitit is a bigger challenge

valtteri14:08:55

Yeah, I see. I don't know how Yada swagger works but in reitit it works so that it constructs the full swagger.json from route data + schema definitions. For schemas it supports plumatic, clojure.spec and malli.. And when it's constructing the swagger, it checks which impl it is, generates the needed JSON chunks and places them into the swagger doc

pppaul14:08:33

yeah, i used malli swagger to generate the params data, but it still wasn't enough

valtteri15:08:59

Yeah.. I'm trying to look if ring-swagger has extension points where you could jack in malli

valtteri15:08:46

Mhmhmh to my 👀 it looks like some serious hacking would be required

pppaul15:08:28

i think i just have to change the params code, i already have merged route + method params

pppaul15:08:55

i just don't know what to change the params to, seems like i need to build ref structures and flatten out nested maps or something

pppaul15:08:39

i poked at it for a few hours, and i think i rather just see about using reitit...

pppaul17:08:44

thanks, I think that's exactly what I need to figure out how to fix yada

eskos11:08:52

Swagger is specifically pre-OpenAPI, which does get confusing. The name change and a whole bunch of backwards breaking changes happened with the release of OpenAPI 3.0, so a good mental note is that you really shouldn’t expect one from another. This isn’t necessarily very helpful to the issue at hand, but still an unfortunate detail one should be aware of.