metosin / metosin/schema-tools

Slicing schemas with partial values

Open
#19 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Clojure
Stars
110
Forks
15
Avg merge
6m
Merged PRs (30d)
1

Description

additional schema transformation function, which takes in an value and a schema and returns a new Schema, which is a sub-schema of the original, having all the fields that we not present in the value.

(s/defschema Order
  {:id s/Str
   :type (s/enum :take-away :normal)
   :address {:street s/Str
             :zip s/Str}})

(st/sub-schema 
  {:id "123", 
   :address {:street "Aleksis Kiven katu 24 B 37"}})
; => {:type (s/enum :take-away :normal), :address {:zip s/Str})

(st/sub-schema 
  {:id "123", 
   :type :take-away 
   :address {:street "Aleksis Kiven katu 24 B 37"
             :zip "33200"}})
; => {}

Would be utterly cool with data-driven forms.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the schema transformation code and the st/sub-schema entry point referenced in the issue, then compare its behavior with the s/defschema examples. Done means a function accepts a value and schema and returns the original schema with fields present in the value removed, including nested fields, producing the two shown results.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.