profile
viewpoint
Metosin metosin Tampere, Helsinki, Finland http://www.metosin.fi A small house of programmers, mostly Clojure(Script).

metosin/compojure-api 1032

Sweet web apis with Compojure & Swagger

metosin/bat-test 57

Fast Clojure.test runner for Boot and Leiningen

metosin/compojure-api-examples 29

Compojure API example

metosin/c2 7

Demo about compojure-api2 stuff

metosin/boot-deps-size 4

Boot task to check size of dependencies

metosin/clj-suomi 4

A Clojure library designed to access Finnish code sets.

metosin/clojure-bootcamp-setup 4

Setup instructions for Metosin Clojure Bootcamp training

metosin/bootcamp3 3

Refactored bootcamp

metosin/boot-alt-http 2

Simple boot http server task to serve files from classpath.

pull request commentmetosin/malli

Initial implementation of json-schema import

Thanks for the reference, I'll take a look at it.

hkupty

comment created time in 15 hours

push eventmetosin/malli

Tommi Reiman

commit sha a8ff304558d7932e3baece0203da1171231c2f87

nested-properties

view details

push time in 15 hours

issue commentmetosin/malli

Feature request or bug: adding properties directly to map keys.

Started on the PR: https://github.com/metosin/malli/pull/212

johesoman

comment created time in 15 hours

PR opened metosin/malli

First class entry meta-data

Spike on whether and how MapEntry properties should used in schema applications:

  • [ ] transformation
  • [ ] error messages
  • [ ] value generation
  • [ ] json schema transformation
  • [ ] swagger2 transformation

Related issues: #80, #86, #116, #120, #182 Related PRs: #119, #197

transformation

(m/decode [:map [:x {:encode/math inc} int?] {:x 1} (mt/transformer {:name :math}))
; => {:x 2}

error messages

value generation

json-schema

swagger

+38 -38

0 comment

2 changed files

pr created time in 15 hours

push eventmetosin/malli

Tommi Reiman

commit sha 582da4c6f8ae41bd1c4b6b185d86888721f6eeff

dead code & non-privates

view details

push time in 15 hours

push eventmetosin/malli

Tommi Reiman

commit sha b31bbc17ea1cd4615529e5c28ddb3312098f0b64

dead code

view details

Tommi Reiman

commit sha 39f292649a268a4c5cba387c4045556ade677d8e

wip

view details

Tommi Reiman

commit sha 628c7aaa3d688dc48d87bcfd57321624f41bb9e4

second class entry-schma

view details

Tommi Reiman

commit sha ee5478c8a407175ce61d11a042814ede50588fc3

-parse-entry-syntax

view details

push time in 16 hours

issue openedmetosin/reitit

docs: metric used in performance comparisons not annotated

Issue

In bar charts available at https://metosin.github.io/reitit/performance.html, it is not obvious at first glance which metric is being compared across different frameworks.

In the current version, it is not clear what the metric is, or if it's the same metric in all comparison charts.

Minimal fix proposal:

Adding the name of the metric at the y axis or in the chart's header would be a sufficient fix.

created time in a day

create barnchmetosin/malli

branch : EntryProps

created branch time in a day

issue closedmetosin/malli

Database schema generations

picked from original README

closed time in a day

ikitommi

issue commentmetosin/malli

Database schema generations

not now, or a separate lib

ikitommi

comment created time in a day

issue closedmetosin/malli

Support recursion in Malli Schema definitions

Registry should support recursion, e.g.

{::age int?
 :child-age [:and ::age [:> 18]] ;; should be expanded
 :child [:map 
         [:name string?] 
         [:age :child-age] 
         [:friends [:set :child]]]} ;; recursion

closed time in a day

ikitommi

issue commentmetosin/malli

Support recursion in Malli Schema definitions

merged in master

ikitommi

comment created time in a day

pull request commentmetosin/malli

Initial implementation of json-schema import

Looking forward to this. Related project: https://github.com/akovantsev/json-schema-to-clojure-spec

hkupty

comment created time in a day

issue commentmetosin/malli

Feature request or bug: adding properties directly to map keys.

Not happy with merge as the properties would be copied to children, potentially masking child properties. Also, things like serialization and walking over schemas would just see the copied properties.

(m/form [:map [:x {:optional true} :string]])
; => [:map [:x {:optional true} [:string {:optional true}]]]

In top-level, I guess the options are:

1) it's a feature

  • entry meta is just for itself (e.g. :optional)
  • having extra keys could later give warning
  • doesn't resolve things, kinda sucks

2) have a generic way for childs to access the parent data

  • pushes all the work to extensions & user provided code
  • sucks, big time

3) have a way for each schema application (transformation, value generation etc) to resolve this

  • applications use the properties differently (some short-circuit (generators), some go too deep (e.g. errors)) -> but only once per application (e.g. the generic code which pulls errors messages, looks one step up too)
  • would yield "just works", user provided code for a given application doesn't have to know about this
  • might be a good goal
  • need to implement and see if this is better than 1

... for the 3, there are few options, but I'll take the simplest path first and create a draft PR for reviews, have a good hunch how to do that without too many tears.

johesoman

comment created time in a day

push eventmetosin/malli

Tommi Reiman

commit sha 1c6479176e47ae65a74ad9c501b2a8d67201c50c

Initial malli->mermaid conversion

view details

Tommi Reiman

commit sha b1e82834f5f69e7d4edad87dd78dbe40a5f61d12

works with cljs, uml -> class-diagram

view details

Tommi Reiman

commit sha bf156d397102f357a148eaf7acf3b6094e6ac3b3

Collect maps and enums only

view details

Tommi Reiman

commit sha 39a4ba1a4c17bf6b76dc0dab0c8f90724f48888d

Simplify

view details

Tommi Reiman

commit sha e3f9077e2c1dee6f0d05c5309d36c7586a60b2c9

cleanup

view details

Tommi Reiman

commit sha 82f08a93a5c56544a7c65a4b252be79373296cf3

Mermaid from local registry

view details

Tommi Reiman

commit sha a6abc0712133dd28b9195c42ff5e14dfd3180d9c

Consistent order

view details

Tommi Reiman

commit sha 59b14f21082d09a3a929b6dcea051417e84508e2

print the forms, not schemas (works on cljs too)

view details

Tommi Reiman

commit sha f57d4da906f74958cd6160961ee414ceb282f326

testing :min, :max and :gen/min & :gen/max on sequential schemas

view details

Tommi Reiman

commit sha 075f5ff878f3ab318f2843be64ab64823a1e7878

:string gen with min & max

view details

Tommi Reiman

commit sha 32dc790caf268ec793943a16d455e021485d362c

fix

view details

Tommi Reiman

commit sha a992edec3fbb69988067eb3330b48313fb17c497

Merge pull request #198 from metosin/MalliMermaid malli->mermaid class diagrams & :gen/min :gen/max

view details

push time in 2 days

PR merged metosin/malli

malli->mermaid class diagrams & :gen/min :gen/max

Two things:

:gen/min & :gen/max

Ability to override :min & :max for collections & :string. Throws for invalid values:

(every? #(<= 10 % 20) (map count (mg/sample [:vector {:gen/min 10, :gen/max 20}] {:size 1000})))
; => true

(mg/generate [:string {:min 2, :gen/min 1}])
; Execution error (ExceptionInfo)
; :malli.generator/invalid-property {:key :gen/min, :value 1, :min 2}

schema visualization

Inspired by schema-viz.

Given a schema:

(def Order
  [:schema
   {:registry {"Country" [:map
                          [:name [:enum :FI :PO]]
                          [:neighbors [:vector [:ref "Country"]]]]
               "Burger" [:map
                         [:name string?]
                         [:description {:optional true} string?]
                         [:origin [:maybe "Country"]]
                         [:price pos-int?]]
               "OrderLine" [:map
                            [:burger "Burger"]
                            [:amount int?]]
               "Order" [:map
                        [:lines [:vector "OrderLine"]]
                        [:delivery [:map
                                    [:delivered boolean?]
                                    [:address [:map
                                               [:street string?]
                                               [:zip int?]
                                               [:country "Country"]]]]]]}}
   "Order"])

Creating mermaid class diagrams:

(require '[malli.mermaid :as mermaid])

(mermaid/class-diagram Order)
"classDiagram
   class Burger {
     :description string?
     :name string?
     :origin [:maybe Country]
     :price pos-int?
   }
   class Country {
     :name [:enum :FI :PO]
     :neighbors [:vector [:ref Country]]
   }
   class Order {
     :delivery Order_Delivery
     :lines [:vector OrderLine]
   }
   class OrderLine {
     :amount int?
     :burger Burger
   }
   class Order_Delivery {
     :address Order_Delivery_Address
     :delivered boolean?
   }
   class Order_Delivery_Address {
     :country Country
     :street string?
     :zip int?
   }
   Burger o-- Country
   Country o-- Country
   Order o-- OrderLine
   Order *-- Order_Delivery
   OrderLine o-- Burger
   Order_Delivery *-- Order_Delivery_Address
   Order_Delivery_Address o-- Country"

Producing:

mermaid

+214 -21

1 comment

5 changed files

ikitommi

pr closed time in 2 days

push eventmetosin/malli

Tommi Reiman

commit sha 32dc790caf268ec793943a16d455e021485d362c

fix

view details

push time in 2 days

push eventmetosin/malli

Tommi Reiman

commit sha f57d4da906f74958cd6160961ee414ceb282f326

testing :min, :max and :gen/min & :gen/max on sequential schemas

view details

Tommi Reiman

commit sha 075f5ff878f3ab318f2843be64ab64823a1e7878

:string gen with min & max

view details

push time in 2 days

push eventmetosin/malli

Tommi Reiman

commit sha 59b14f21082d09a3a929b6dcea051417e84508e2

print the forms, not schemas (works on cljs too)

view details

push time in 2 days

push eventmetosin/malli

Tommi Reiman

commit sha a6abc0712133dd28b9195c42ff5e14dfd3180d9c

Consistent order

view details

push time in 2 days

push eventmetosin/malli

Tommi Reiman

commit sha 82f08a93a5c56544a7c65a4b252be79373296cf3

Mermaid from local registry

view details

push time in 2 days

pull request commentmetosin/malli

Add :map qualified keyword child syntax

Will get back to this after #86 is resolved. Sorry for taking so long.

kwrooijen

comment created time in 2 days

startedmetosin/ring-http-response

started time in 3 days

fork arohner/muuntaja

Clojure library for fast http api format negotiation, encoding and decoding.

fork in 3 days

push eventmetosin/spec-tools

Wanderson Ferreira

commit sha e6337be34ddbae26227864a2fdccdf8c27105754

spec coll-of distinguish between set and vector data types

view details

Wanderson Ferreira

commit sha 503d5345a5188be46a5d57eaf169ae9727b3ac5d

fix map-of-spec cpred check to verify for explicit maps

view details

Tommi Reiman

commit sha a96abb464d4a4e20c41581183d902683b5167615

Merge pull request #239 from wandersoncferreira/bugfix/match-data-type spec coll-of distinguish between set and vector data types

view details

push time in 3 days

PR merged metosin/spec-tools

spec coll-of distinguish between set and vector data types

Fixes the bug reported at #237 . Seems like the function impl/coll-of-spec has a property called cpred which was default to coll? however, both sets and vectors returns true to coll?. I made a change to verify the type of argument passed to the function, so the cpred is chosen apropriately.

Thus the OP example now has the expected behavior:

(s/valid? (ds/spec ::x #{int?}) #{1 2 3})  ;; => true
(s/valid? (ds/spec ::x #{int?}) [1 2 3])  ;; => false
+16 -3

1 comment

2 changed files

wandersoncferreira

pr closed time in 3 days

issue commentmetosin/malli

Make SCI dependency optional for smaller JS builds

thanks, will try that :)

Naomarik

comment created time in 3 days

push eventmetosin/spec-tools

Roman Rudakov

commit sha 22d072894e104fe1069a07607d7a3fbddfbf6bbc

Add spec for OpenAPI3

view details

Roman Rudakov

commit sha a2720bface59cca0e3700696c85da2513d8d098c

Start implementation of swagger generation for OpenAPI3

view details

Roman Rudakov

commit sha d2da5dc847cd1bc4243deee094f7eb52cf817a22

Add accept-spec methods for OpenAPI3 core

view details

Roman Rudakov

commit sha 666c9f7f3c2b668ec179c84e6f213f5afe1211b2

Add expand multimethod for openapi3 and some default dispatches

view details

Roman Rudakov

commit sha 9d878a7587c95618672663685d8e566c75fb88b3

Start unit tests for openapi3 core

view details

Roman Rudakov

commit sha e06f4d22f48ebc80911c183779d1467cf9b75561

Add unit tests for openapi3 core and fix some spec conversion

view details

Roman Rudakov

commit sha 5090e5405836688b2efc08252b16b90b887598d3

OpenAPI3: Handle nilable, extend headers and content

view details

Roman Rudakov

commit sha ff670b1ac394fbf9b33849bbf4362fd24885fba0

OpenAPI3: Add documentation

view details

Roman Rudakov

commit sha 9b3d2553a29568fcd0940436b882b24d672588a7

OpenAPI3: Add more documentation

view details

Roman Rudakov

commit sha 029b5f38877b6b43b98753b7ee6795ab6a18e6a6

OpenAPI3: Finish docs, add more unit tests, fix spec

view details

Roman Rudakov

commit sha 62565ac87a100a0f10185c67b495a738dd32b5a2

OpenAPI3: renamed openapi3 -> openapi

view details

Tommi Reiman

commit sha d70dfe3f3695d703a9736c215ab67daa4ab405ae

Merge pull request #236 from rrudakov/openapi3 OpenAPI3 support

view details

push time in 3 days

PR merged metosin/spec-tools

OpenAPI3 support

Known issues:

  • Project uses ring-swagger as dependency to validate generated swagger schema. Ring-swagger uses swagger2 specs so I can't write test to validate OpenAPI3 generated schema at the moment.
  • Any string can be used for content-type value
  • Callbacks in operations are not supported by current OpenAPI3 spec due to circular spec calls. I can declare callbacks as {string? any?} but I don't think it's a good idea.
+1626 -10

4 comments

7 changed files

rrudakov

pr closed time in 3 days

pull request commentmetosin/spec-tools

OpenAPI3 support

Big thanks!!

rrudakov

comment created time in 3 days

fork jeroenvandijk/reitit

A fast data-driven router for Clojure/Script

https://metosin.github.io/reitit/

fork in 3 days

startedmetosin/malli

started time in 3 days

startedmetosin/compojure-api

started time in 3 days

pull request commentmetosin/spec-tools

spec coll-of distinguish between set and vector data types

Codecov Report

Merging #239 into master will increase coverage by 0.00%. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #239   +/-   ##
=======================================
  Coverage   86.23%   86.24%           
=======================================
  Files          14       14           
  Lines        1707     1708    +1     
  Branches      175      175           
=======================================
+ Hits         1472     1473    +1     
  Misses         60       60           
  Partials      175      175           
Impacted Files Coverage Δ
src/spec_tools/impl.cljc 87.77% <100.00%> (+0.06%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 877f4b8...503d534. Read the comment docs.

wandersoncferreira

comment created time in 3 days

pull request commentmetosin/spec-tools

spec coll-of distinguish between set and vector data types

Just to complement with the new findings described in the issue ticket: This solution addresses the first OP situation, but not the second one. I don't think they are fully-dependant of each other.

wandersoncferreira

comment created time in 3 days

issue commentmetosin/spec-tools

Require data to match coll type

Yes, I got the whole picture now.

When the map-of-spec is called to create our data spec, we rely on clojure.spec.alpha/every-impl to create it. However, this function has the following logic to perform the dispatch for each value when you ask to conform-all values in the map: https://github.com/clojure/spec.alpha/blob/master/src/main/clojure/clojure/spec/alpha.clj#L1298

And the problem lies in the (seq x) call. x is our data in this case #{[1 2 3 4]} . However, take a look at the destructuring below (simplified version of what the every-impl does):

;; the value of v
(let [x #{[1 2 3]}
      [v & vs :as vseq] (seq x)]
  v) ;; => [1 2 3]

;;; where v is used
(let [x #{[1 2 3]}
      [v & vs :as vseq] (seq x)]
  (conform* spec v))

And what is spec? Looking at impl/map-of-spec, spec is checking for a key-value tuple. And seq just got rid off our #{} literal. Then when the number of itens inside the vector is even, (conform* spec v) returns true and everything is fine.

Now, I'm not sure how can we approach to fix the issue. I looked under the hood of s/map-of which seems to do this just fine, however the implementation to some of the parts, e.g. cpred parameter, is a lot more complex than the current coll? call spec-tools is using right now.

I will continue to look at this problem when I get more time.

brjann

comment created time in 3 days

startedmetosin/kekkonen

started time in 3 days

issue commentmetosin/spec-tools

Require data to match coll type

I would guess that ´[k v]´ is identified as a key value pair. (s/valid? (ds/spec ::x {int? int?}) [[1 2] [2 1]]) is also valid, while (s/valid? (ds/spec ::x {int? int?}) [[1 2] [2 1 3]]) is not. Also, (s/conform (ds/spec ::x {int? int?}) [[1 2] [2 1]]) => {1 2 2 1}

brjann

comment created time in 3 days

issue commentmetosin/spec-tools

Require data to match coll type

Which is interesting is that (s/valid? (ds/spec ::x {int? int?}) #{[1 2 3]}) returns false as expected. This error is only happening with exact 2 elements inside the array.

brjann

comment created time in 3 days

issue commentmetosin/spec-tools

Require data to match coll type

Unfortunately not @brjann , it seems related but it is not the same error. From some investigation, seems like the code performing the destructuring of #{[1 2]} is treating it the same way as #{1 2}. I am trying to look where this is done.

brjann

comment created time in 3 days

issue commentmetosin/spec-tools

Require data to match coll type

@wandersoncferreira wow, thanks! Does this also make (s/valid? (ds/spec ::x {int? int?}) #{[1 2]}) returen false?

brjann

comment created time in 3 days

issue commentmetosin/spec-tools

Require data to match coll type

@brjann there is some explanation in the mentioned PR above to fix the issue you reported.

brjann

comment created time in 4 days

PR opened metosin/spec-tools

spec coll-of distinguish between set and vector data types

Fixes the bug reported at #237 . Seems like the function impl/coll-of-spec has a property called cpred which was default to coll? however, both sets and vectors returns true to coll?. I made a change to verify the type of argument passed to the function, so the cpred is chosen apropriately.

Thus the OP example now has the expected behavior:

(s/valid? (ds/spec ::x #{int?}) #{1 2 3})  ;; => true
(s/valid? (ds/spec ::x #{int?}) [1 2 3])  ;; => false
+11 -2

0 comment

2 changed files

pr created time in 4 days

startedmetosin/ring-http-response

started time in 4 days

startedmetosin/ring-http-response

started time in 4 days

fork wangpengwen/malli

Plain data Schemas for Clojure/Script.

fork in 4 days

startedmetosin/malli

started time in 4 days

startedmetosin/sieppari

started time in 4 days

issue commentmetosin/malli

Feature request or bug: adding properties directly to map keys.

@ikitommi are you still thinking the parent / child relationship is the way to go on this? Would this mean that transformers would end up being able to reference them via m/-parent or something similar? And then getting properties becomes (m/properties (m/-parent schema))?

It may be worth stating that this could end up leading to inconsistent behavior for transformers, specifically if some of them end up checking parent properties, while others don't. I imagine it will be easy enough to get them to be consistent in malli.core but I do think it may lead to unintentional bugs in libraries / applications defining their own transformers. It also may be surprising for users that this is malli's behavior in core, but when consuming a library that didn't implement parent checking, the behavior is different.

In the case of merging properties into the child, and specifically merging {:optional true} into a child, isn't that essentially a no-op? Aren't the "key-props" irrelevant in the child schema?

ie. aren't

[:map [:name {:optional true} string?]]

and

[:map [:name {:optional true} [string? {:optional true}] 

essentially equivalent?

Even if they aren't, it may be worth thinking whether writing the merge logic for parent to child properties is more complex than having parent / child. As always, no strong opinions, just thinking out loud.

johesoman

comment created time in 4 days

PR opened metosin/malli

Initial implementation of json-schema import

This allows a very basic json-schema->malli conversion.

Still missing for this PR

  • [ ] cleanup TODOS;
  • [ ] ensure function names are sane;
  • [ ] ensure all json-schema features are supported (at least for one specific version, i.e. draft-7):
    • [X] String
      • [ ] Length
      • [ ] Regular Expressions
      • [ ] Format
    • [X] Numeric Types
      • [X] Number
      • [X] Integer
      • [ ] Multiples
      • [ ] Range
    • [X] Object
      • [x] Properties
      • [x] Required
      • [ ] Size
      • [ ] Dependencies
      • [ ] Pattern Properties
    • [x] Array
      • [x] Items (list)
      • [x] Items (tuple)
      • [ ] Length
      • [ ] Uniqueness
    • [x] Boolean
    • [x] Null
    • [ ] Combining
      • [x] oneOf
      • [ ] allOf
      • [ ] anyOf
      • [ ] not
    • [x] $ref
+110 -0

0 comment

1 changed file

pr created time in 4 days

fork hkupty/malli

Plain data Schemas for Clojure/Script.

fork in 4 days

Pull request review commentmetosin/malli

Recursive Schemas Impl

         gen (-> schema m/children first (generator options))]     (gen/fmap f (gen/vector-distinct gen {:min-elements min, :max-elements max, :max-tries 100})))) +(defn -or-gen [schema options]+  (gen/one-of (keep #(some->> (-recursion-options % options) (generator %)) (m/children schema options))))++(defn -multi-gen [schema options]+  (gen/one-of (keep #(some->> (-recursion-options (last %) options) (generator (last %))) (m/map-entries schema options))))+ (defn -map-gen [schema options]   (let [entries (m/map-entries schema)-        value-gen (fn [k s] (gen/fmap (fn [v] [k v]) (generator s options)))+        options' (-recursion-options schema options)

Perhaps this is better filed as a bug with them, but just worth noting that the "prime" convention isn't well supported in some editors' understanding of the clojure grammar. Emacs will attempt to convert options' into options ' causing the expression to rebind options to the quoted expression '(-recursion-options schema options). Your haskell is showing ;)

ikitommi

comment created time in 4 days

push eventmetosin/malli

Tommi Reiman

commit sha 4b279a98e9fb5c0a478635716cac9d0c6506ab37

Update README.md Add CEST talk, document map keys, fixes #189

view details

Tommi Reiman

commit sha ee150c75de1ee079f483c18bd88047453ffafa78

Update README.md document `:fn` properly

view details

Tommi Reiman

commit sha b07d17441be7a4ef8463f9cc1eb2ba55264851f4

welcome :string schema

view details

Tommi Reiman

commit sha 1cbae922d2d9c343e0e2868645bd1a73c0615e17

string errors

view details

Tommi Reiman

commit sha 51939bd076ab54288c68c4bda4e772dd5f68e1e7

Fix tests

view details

Tommi Reiman

commit sha 043046331444dd2ed169e568f591a92237f2933b

Merge pull request #205 from metosin/string welcome :string schema

view details

Tommi Reiman

commit sha 85101d12231b860702febbd09169b9226fb6e132

Update README

view details

Tommi Reiman

commit sha 2912e43b09fd89c410e35a09e23bd62e4e50e54e

Initial CHANGELOG

view details

Tommi Reiman

commit sha 5f16b75c1f91f9b2494387a0589d6d9619262fcb

Generator protocol, -generator => -schema-generator

view details

Tommi Reiman

commit sha dc5479e927accbaf7261f26aaa90e9b3bd1fc41a

Test the protocol

view details

Tommi Reiman

commit sha 449c7da5e8dc1c27fa3f5650ce913a81e4f18ab9

JsonSchema protocol

view details

Tommi Reiman

commit sha 7bd3221a8d33ece60dcfee6f95a3a5189c833e7f

SwaggerSchema & fixes to namespaced keys

view details

Tommi Reiman

commit sha ae13e3897e0cc1049c8b1bc335818ff22c14c31c

SchemaError

view details

Tommi Reiman

commit sha 93e2b5e99d7f17addf8eb353e38d9f879b399659

Fix generator tests

view details

Tommi Reiman

commit sha c0c0691ccf50fb5fc17c70021f74096fc56ca8c4

Tip to trim strings

view details

Tommi Reiman

commit sha f39b74511bdcf0dee5775458212f74c1481d6257

Fix rebase, generate full strings

view details

Tommi Reiman

commit sha d9e29fedc967791f49864b373a78099c14a5cee7

Merge pull request #204 from metosin/protocols Protocol Extensions

view details

Tommi Reiman

commit sha 10ba8b963ac419ee33729315c3defb936587447c

Update CHANGELOG

view details

Tommi Reiman

commit sha 678e754f94ba7a7f43ba75b9d132bef17f7c899f

rename m/name to m/type

view details

Tommi Reiman

commit sha a843468c0ebd48899fb8eb4e6324331c89b510bc

.

view details

push time in 4 days

push eventmetosin/malli

Tommi Reiman

commit sha dab8a45a09b19d04688485d8e96540a08fcc4773

fix :multi recursion test

view details

push time in 4 days

push eventmetosin/malli-web

Tommi Reiman

commit sha f9956a5287d8f44ec05bfbe84ba57584bf066333

fix

view details

push time in 5 days

push eventmetosin/malli-web

Tommi Reiman

commit sha eb3e38c6ed1c72c970db880dcc849f845ef2fdfc

Humanized errors

view details

push time in 5 days

issue commentmetosin/malli

Make SCI dependency optional for smaller JS builds

I have closed the PR. Instead, I'm offering you this library https://github.com/borkdude/dynaload. If you need any help, let me know. :)

Naomarik

comment created time in 5 days

PR closed metosin/malli

[#203] make sci optional for smaller JS builds

This PR makes sci optional using the same mechanisms that clojure.spec uses to dynamically load test.check. Fixes #203.

  • [ ] Maybe split the dynaload code out into a library so it can be used from other projects as well. With copyright notice for code borrowed from spec.
  • [ ] Same mechanism can be used to make test.check optional for even smaller builds.
  • [ ] The tests do pass but due to randomization in kaocha they sometimes fail. The reason is that sci.core has to be required first. There's probably a kaocha preloads plugin which can do this. But the tests have to be adapted to the optionality of sci anyway.

Note that sci users now have to bring in the sci dependency themselves. If they don't they will get an error message when using malli.core/eval.

$ plk -A:sci
ClojureScript 1.10.597
cljs.user=> (require '[malli.core :as m])
nil
cljs.user=> (require '[sci.core])
nil
cljs.user=> (m/validate int? "1")
false
cljs.user=>
undefined is not an object (evaluating 'malli.core.eval_string.call')
cljs.user=> (m/eval "(+ 1 2 3)")
6

vs.

$ plk
ClojureScript 1.10.597
cljs.user=> (require '[malli.core :as m])
nil
cljs.user=> (m/validate int? "1")
false
cljs.user=> (m/eval "(+ 1 2 3)")
Execution error (Error) at (<cljs repl>:1).
Var sci.core/eval-string does not exist, sci.core never required
+78 -12

0 comment

7 changed files

borkdude

pr closed time in 5 days

push eventmetosin/malli-web

Tommi Reiman

commit sha 61d164cd8fbcaa9a05b57e4782aad79e13b99b3c

indicator

view details

push time in 5 days

push eventmetosin/malli-web

Tommi Reiman

commit sha 61e672d0077ddb551718ae6f2c424e99b201b8fc

new version

view details

push time in 5 days

push eventmetosin/malli-web

Tommi Reiman

commit sha fd84eda79766a82f38334e54bb46b415df89e586

Update deps, recursion samples, debounce 500->1000

view details

push time in 5 days

push eventmetosin/malli

Tommi Reiman

commit sha 2c978df4c860a40280f71650d3399078223fefac

recursion limit 5->4

view details

push time in 5 days

issue commentmetosin/malli

Things to be decided before initial stable release

one to go.

ikitommi

comment created time in 5 days

push eventmetosin/malli

Tommi Reiman

commit sha 8b7bb9d16d045b86618c4a43f1dc15c21f44e9bc

Update (c)

view details

push time in 5 days

push eventmetosin/malli

Tommi Reiman

commit sha 06aae0a1e7598585a9c32b65c072cddc74fb2fb3

Update README

view details

push time in 5 days

PR closed metosin/malli

Recursive schema

PR to start a conversation about recursive schemas, a prerequisite for json-schema->malli conversion

I added an entry for base-registry that accepts :recursive as a schema

This enables us to define recursive schemas even without using the registry. Something like

[:map
  [:name string?]
  [:parent {:optional true} :recursive]]

I think we need to deal to schemas like :recursive, [:and :recursive], [:or :recursive] or anything that doesn't have any real value and can lead to StackOverflow on evaluation

I was thinking in maybe support loop/recur, with something like:

[:map 
  [:family {:malli/loop :family-member}
    [:map 
      [:name string?]
      [:parent [:recursive :family-member]]]]]

What do you think?

+65 -12

40 comments

3 changed files

RafaeLeal

pr closed time in 5 days

pull request commentmetosin/malli

Recursive schema

thanks @RafaeLeal for the original draft, and for everyone for the comments. merged #209 master. Post-comments still welcome.

RafaeLeal

comment created time in 5 days

push eventmetosin/malli

Tommi Reiman

commit sha 427a1cdd56e1b2e8b33b6982e9792119e53c8a5f

m/-chidlren, polish out core things

view details

Tommi Reiman

commit sha e6426b096fa03cf74a6aaf0b80111a133265d616

:ref schema

view details

Tommi Reiman

commit sha b4b28e0167a57618c4e53300184e9c98dca6430b

polish code

view details

Tommi Reiman

commit sha eaea510e63c4ebce64d66b0ce69bfc6101f3abcf

Support for mutual recursion via registry

view details

Tommi Reiman

commit sha 88520443a1c82b267b8cbd5217356ee99c3f92ea

Handle local vs registry ref ambiguity

view details

Tommi Reiman

commit sha f503222c9f04887b4fcba4fed3f505fd575788fa

Better schema errors on missing schema elements

view details

Tommi Reiman

commit sha f7f760e7770efe95136f1b77c199f6e09314ec40

welcome :registry

view details

Tommi Reiman

commit sha 2e2c7dd50b11efb14f9bea51e3b1c254b29f70b7

Add tests

view details

Tommi Reiman

commit sha 6fea381b0304e6bd661ee5f098e2c63fde79fcec

Added tests, clj only TODO: cljs fails on maximum call stack

view details

Tommi Reiman

commit sha 496ff82751cfb8cf984188a661eef1d86fdd889d

Support property :registry anywhere

view details

Tommi Reiman

commit sha 7cbd3bdf31bec12b5b729d1bf87a7469f3c62469

fix test

view details

Tommi Reiman

commit sha 25b41ded4694b542eea094767add598b7f3b67fe

remove the :registry

view details

Tommi Reiman

commit sha ca9f32665669ab3278e7c97099557af3a7163e08

optimize :and with single branch

view details

Tommi Reiman

commit sha 32dd6e3142bafb72ca97aca062c4bcc998bdd51d

welcome :schema!

view details

Tommi Reiman

commit sha db31c012eb519c9c202885e14f193d0b3adc2db6

raise ref-max

view details

Tommi Reiman

commit sha 7a18cbf7d5e9049fb69360a90b19be48f8619bdb

fast :or validator with 1 distict child

view details

Tommi Reiman

commit sha 63b9d520460c0b934827549392863581c33698a9

Bye bye local recursion, welcome :malli.core/schema (for durable eager schema links)

view details

Tommi Reiman

commit sha dffd9abc9c6b4072e885bb34275ac8552ad56d1b

README

view details

Tommi Reiman

commit sha a6a1a7dfea503f8b734d5151f3fc320304ad288a

docs

view details

Tommi Reiman

commit sha 6e7a4d3b613423425324ed8fee56d1c06926c22c

docs

view details

push time in 5 days

PR merged metosin/malli

Recursive Schemas Impl

Displaces impl from #117, which will remain a place to discuss & history. FIxs #20 .

  • new m/Schema method -children to get child schemas instances too
  • :multi implements m/MapSchma
  • new m/RefSchma protocol with the following impls:
    • :ref - a lazy reference, enabling recursion
    • :schema, like m/schema (entity) but in data, eager
    • malli.core/schema, eager schema (value) ref, used internally. if no properties and child is a qualified keyword, derived form from the child
  • support for local :registry in any element
  • validators, explainers etc are moved from schema creation to actual m/Schema methods, to support laziness
  • m/-distance and m/-lookup helpers
  • m/from-map-syntax works with non-map child's (enums, refs)
  • updated README (local registry, recursive schemas)

TODO

  • [x] :schema for non-lazy references (retains original information)
  • [x] local recursion using :id
  • [x] local mutual recursion using :registy
  • [x] new element to ensure local registries as data
  • [x] ambiguity rules
  • [x] ensure it's done right

Current syntax:

(testing "recursion limiting"
  (are [schema]
    (is (every? (partial m/validate schema) (mg/sample schema {:size 1000})))

    ;; maybe
    [:schema {:registry {::rec [:maybe [:ref ::rec]]}}
     ::rec]

    ;; maps
    [:schema {:registry {::rec [:map [:rec {:optional true} [:ref ::rec]]]}}
     ::rec]

    ;; or
    [:schema {:registry {::tuple [:tuple boolean? [:ref ::or]]
                         ::or [:or int? ::tuple]}}
     ::or]

    ;; multi
    [:schema {:registry {::multi
                         [:multi {:dispatch :type}
                          [:int [:map [:type [:= :int]] [:int int?]]]
                          [:multi [:map [:type [:= :multi]] [:multi [:ref ::multi]]]]]}}
     [:ref ::multi]]))

Initial Syntax:

(support for local recursion removed)

malli-rec

+542 -185

1 comment

7 changed files

ikitommi

pr closed time in 5 days

issue commentmetosin/malli

Make SCI dependency optional for smaller JS builds

Work in progress at #210. It works, but the tests need to be refactored to account for the optionality of sci.

Naomarik

comment created time in 5 days

PR opened metosin/malli

[#203] make sci optional for smaller JS builds
+78 -12

0 comment

7 changed files

pr created time in 5 days

fork borkdude/malli

Plain data Schemas for Clojure/Script.

fork in 5 days

startedmetosin/muuntaja

started time in 5 days

pull request commentmetosin/malli

Recursive schema

Thanks for the comments. Implemented the recursion in #209. Removed the local recursion in favour of using local registries and added eager :schema and :malli.core/schema reference types.

The registry shorthand notation: Doing a generic walk (using m/accept) and adding :title property to all schemas would mean that the registry shorthand would get a new Schema :title registered so I think it's better to use the explicit :registry key.

The [:and properties schema] can be now presented as [:schema properties schema] and has always been available as [schema properties] (e.g. [string? {:title "string"}]).

Will run some more tests, if no new comments arrive, will merge the recursion to master and close both issues.

cheers.

RafaeLeal

comment created time in 5 days

push eventmetosin/malli

Tommi Reiman

commit sha d17a94fb9396a653d39278f10bd5d44a60e5bc43

update README

view details

push time in 5 days

push eventmetosin/malli

Tommi Reiman

commit sha 1636ae24e824256923f1a614b474d1b279aa6f99

lazy :map

view details

Tommi Reiman

commit sha df72f17bcb8ecf701bb7a870d245816485b973f6

recursion limit on :or

view details

Tommi Reiman

commit sha 133a5224d8534fcfda43d75d5840e1ca3e41a520

:multi satisfies MapEntries

view details

Tommi Reiman

commit sha d73acc82cf8531c951fac00df7c68562fe5c763d

:multi recursion

view details

push time in 5 days

issue commentmetosin/reitit

Automatically publish Swagger :consumes for :form params

I'll take a go at this unless someone else is already working on it

ikitommi

comment created time in 5 days

startedmetosin/reitit

started time in 6 days

push eventmetosin/malli

Tommi Reiman

commit sha dd3647e43fa739fc04f48b7fa1ba24db6802819a

Proper recursion limits

view details

push time in 6 days

fork ashish-arya-kr/ring-http-response

Handling HTTP Statuses with Clojure(Script)

fork in 6 days

push eventmetosin/malli

Tommi Reiman

commit sha 6e7a4d3b613423425324ed8fee56d1c06926c22c

docs

view details

push time in 6 days

push eventmetosin/malli

Tommi Reiman

commit sha a6a1a7dfea503f8b734d5151f3fc320304ad288a

docs

view details

push time in 6 days

push eventmetosin/malli

Tommi Reiman

commit sha 7a18cbf7d5e9049fb69360a90b19be48f8619bdb

fast :or validator with 1 distict child

view details

Tommi Reiman

commit sha 63b9d520460c0b934827549392863581c33698a9

Bye bye local recursion, welcome :malli.core/schema (for durable eager schema links)

view details

Tommi Reiman

commit sha dffd9abc9c6b4072e885bb34275ac8552ad56d1b

README

view details

push time in 6 days

startedmetosin/jsonista

started time in 6 days

push eventmetosin/malli

Tommi Reiman

commit sha db31c012eb519c9c202885e14f193d0b3adc2db6

raise ref-max

view details

push time in 6 days

push eventmetosin/malli

Tommi Reiman

commit sha 25b41ded4694b542eea094767add598b7f3b67fe

remove the :registry

view details

Tommi Reiman

commit sha ca9f32665669ab3278e7c97099557af3a7163e08

optimize :and with single branch

view details

Tommi Reiman

commit sha 32dd6e3142bafb72ca97aca062c4bcc998bdd51d

welcome :schema!

view details

push time in 6 days

issue commentmetosin/spec-tools

Require data to match coll type

While (s/valid? (ds/spec ::x {int? int?}) #{1 2}) returns false, (s/valid? (ds/spec ::x {int? int?}) #{[1 2]}) returns true

So it seems that one must be able to convert the value to its correct form for the spec check to succeed

brjann

comment created time in 7 days

issue commentmetosin/spec-tools

Require data to match coll type

I wish I had enough Clojure / spec skills to submit a PR on this :-)

brjann

comment created time in 7 days

startedmetosin/pohjavirta

started time in 7 days

startedmetosin/reitit

started time in 7 days

startedmetosin/pohjavirta

started time in 7 days

PR closed metosin/reitit

Extract swagger spec generation logic from `create-swagger-handler`

Fixes https://github.com/metosin/reitit/issues/246

This extracts the logic for doing the swagger 2.0 spec creation from the reitit.swagger/create-swagger-handler as a public api (reitit.swagger/swagger-spec compiled-routes swagger-data).

+128 -102

2 comments

2 changed files

jameslintaylor

pr closed time in 7 days

issue openedmetosin/spec-tools

Encodes fails when using multi-spec

Hello!

Problem

Version: 0.10.2

The following code fails:


(require '[clojure.spec.alpha :as s])
(require '[spec-tools.core :as st])

(def strict-json-transformer (st/type-transformer st/strip-extra-keys-transformer
                                                  st/json-transformer))

(def status-set #{:success :error})
(def reason-set #{:generic-error :some-other-error})

(s/def ::reason (st/spec {:spec reason-set :type :keyword}))
(s/def ::status (st/spec {:spec status-set :type :keyword}))

(defmulti inclusion-result :status)
(defmethod inclusion-result :success [_] (s/keys :req-un [::status]))
(defmethod inclusion-result :error [_] (s/keys :req-un [::status ::reason]))

(s/def ::inclusion-result (s/multi-spec inclusion-result :status))
(st/encode ::inclusion-result {:status :error, :reason :some-other-error} strict-json-transformer)

with the following exception:

1. Unhandled java.lang.IllegalStateException
   No method of: com.piposaude.spec-serialization.core-test/inclusion-result for
   dispatch value: error

                 alpha.clj:  964  clojure.spec.alpha/multi-spec-impl/reify
                 alpha.clj:  171  clojure.spec.alpha/unform
                 alpha.clj:  166  clojure.spec.alpha/unform
                 core.cljc:  417  spec_tools.core.Spec/unform_STAR_
                 alpha.clj:  171  clojure.spec.alpha/unform
                 alpha.clj:  166  clojure.spec.alpha/unform
                 core.cljc:  259  spec_tools.core$encode/invokeStatic
                 core.cljc:  250  spec_tools.core$encode/invoke
                 ....

I believe this relates to #119 .

Looking the code I saw that in the encode function there is an conform + unform pair, but the data being passed to the unform is {:error "error" :status "some-other-error"}, therefore the multi-spec fails to perform the dispatch and find the right spec to do the unform.

Possible solution?

In the issue #119, you guys mention the possibility of:

if there is a way to ask from a multi-spec what spec it will dispatch for this given data, we could unform against that spec directly, not for the multispec itself.

Which I imagine maps to these lines of code in the spec source-code (ref1 and ref2), wheremm is the multi-method.

(let [predx #(let [^clojure.lang.MultiFn mm @mmvar]
                    (c/and (.getMethod mm ((.dispatchFn mm) %))
                           (mm %)))]
; ....
(unform* [_ x] (if-let [pred (predx x)]
                         (unform pred x)
                         (throw (IllegalStateException. (str "No method of: " form " for dispatch value: " (dval x))))))

I believe it would be possible to modify the encode to get the right spec to use in the unform in the case of multi-spec. But I'm not sure if this would be the right place to do so and how it would impact when we merge multi-spec with others specs. Maybe it would be better to wrap the multi-spec in a st/spec and modify the unform* there, but probably it would need access to the original data.

What do you think? Would be ok to add this as a condition in the encode function? If you guys could give me direction on the best way to proceed, I could try to submit a patch.

Thanks!

created time in 8 days

startedmetosin/pohjavirta

started time in 8 days

fork mickronome/reitit

A fast data-driven router for Clojure/Script

https://metosin.github.io/reitit/

fork in 9 days

fork mickronome/malli

Plain data Schemas for Clojure/Script.

fork in 9 days

startedmetosin/reitit

started time in 9 days

startedmetosin/pohjavirta

started time in 9 days

pull request commentmetosin/spec-tools

OpenAPI3 support

@ikitommi thank you for the feedback. I've renamed openapi3 to openapi.

rrudakov

comment created time in 9 days

more