Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define Child/Parent relationship to Schemas #120

Closed
ikitommi opened this issue Nov 24, 2019 · 3 comments
Closed

Define Child/Parent relationship to Schemas #120

ikitommi opened this issue Nov 24, 2019 · 3 comments
Labels
duplicate This issue or pull request already exists for discussion Discussion is main focus of PR
Milestone

Comments

@ikitommi
Copy link
Member

ikitommi commented Nov 24, 2019

If schemas knew their parent, we would be able to do:

;; use error message of a parent (here: map-entry schema)
[:map [:x {:error/message "not an int"} int?]]

Is this good or bad?

@ikitommi ikitommi added the for discussion Discussion is main focus of PR label Nov 24, 2019
@rschmukler
Copy link
Contributor

rschmukler commented Nov 25, 2019

Just echoing some conversation seen in other issues.

For complex transformations, having interceptors (#122, #114) takes care of most things. Any transformer that requires parent access can simply become an :after transformer on the parent type. I will admit that this, theoretically, doesn't compose as well, nor remain as focused - however in my use cases this ended up not being a big difference.

@ikitommi ikitommi added this to the alpha1 milestone Feb 1, 2020
@flow-danny
Copy link

I think I have a use-case for this.

In reitit nesting of routes allows one to define what sub-routes share access roles. I would like to define in a similar way the access level for a group of attributes. Then I could filter/transform data (anonymize, or omit keys) based on the user access level.

@ikitommi ikitommi added the duplicate This issue or pull request already exists label Jul 4, 2020
@ikitommi
Copy link
Member Author

ikitommi commented Sep 1, 2020

#212 is merged in master. Is allows all but error messages to be read from entry schemas.

(require '[malli.json-schema :as json-schema])

(json-schema/transform
  [:map
   [:x {:json-schema/example 42} int?]
   [:y {:json-schema {:type "string"}} [:fn (fn [x] (string? x))]]])
;{:type "object"
; :properties {:x {:type "integer"
;                  :format "int64"
;                  :example 42}
;              :y {:type "string"}}
; :required [:x :y]}

because of that, we don't need childs to know about their parents.

@ikitommi ikitommi closed this as completed Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists for discussion Discussion is main focus of PR
Projects
None yet
Development

No branches or pull requests

3 participants