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

Support namespaced keywords #16

Closed
skuro opened this issue Jan 13, 2021 · 3 comments · Fixed by #17
Closed

Support namespaced keywords #16

skuro opened this issue Jan 13, 2021 · 3 comments · Fixed by #17

Comments

@skuro
Copy link
Contributor

skuro commented Jan 13, 2021

Currently, encoding of keywords strips away the namespace:

user> (yaml/encode {:one/two 42})
;; => {"two" 42}

I discovered this while round-tripping (yaml/parse-string + yaml/generate-string) a Kubernetes YAML, which included something like:

nodeSelector:
    cloud.google.com/gke-nodepool: custom-pool

I fixed it locally with

(extend-type clojure.lang.Keyword
  yaml/YAMLCodec
  (encode [data] (let [n (namespace data)
                       v (name data)]
                   (cond->> v
                     (some? n) (str n "/")))))
@borkdude
Copy link
Collaborator

I think this library should support this (by default) and consider this a bug. What do you think @slipset @marcomorain ?

@slipset
Copy link
Member

slipset commented Jan 15, 2021

I generally defer to @marcomorain for these kinds of questions, but it seems reasonable to me. @skuro would you be interested in whipping up a PR?

@skuro
Copy link
Contributor Author

skuro commented Jan 15, 2021

Opened #17 which uses a slightly optimized approach to the same result:

  clojure.lang.Keyword
  (encode [data]
    ;; using clojure.core/name would drop the namespace
    (subs (str data) 1))

Hail hail the anti-if campaign!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants