AppsFlyer / pronto

Clojure support for protocol buffers
110 stars 8 forks source link

One-of functions always use kebab-case to find field #32

Open neilprosser opened 7 months ago

neilprosser commented 7 months ago

Firstly, thank you for this library! Hopefully this will all make sense but essentially we're trying to use which-one-of and one-of with a snake-case field and we're getting actual: java.lang.IllegalArgumentException: Cannot check which one-of for :snakey_field. We're using the default :key-name-fn in our defmapper by not specifying anything.

If you take the example people.proto and alter the Address message to change the home field to be home_details:

message Address {
  string city = 1;
  string street = 2;
  int32 house_num = 3;
  oneof home_details {
    House house = 4;
    Apartment apartment = 5;
  }
  UUID address_id = 6;
}

And alter the one-of-test here to attempt to use the new home_details field:

(is (= house (:house address2)))
(is (= (p/which-one-of address2 :home_details) :house))
(is (= house (p/one-of address2 :home_details)))

(is (= apartment (:apartment address3)))
(is (= (p/which-one-of address3 :home_details) :apartment))
(is (= apartment (p/one-of address3 :home_details)))

The test will start failing with the above IllegalArgumentException as it's trying to look for :home-details in the proto-map rather than :home_details. one-of will also fail similarly if the field name inside the oneof is also snake-case.

I think the bug comes from this line and that should be using the :key-name-fn from the respective mapper in some way. It looks like this might be a bit more than minor surgery to solve this using my limited knowledge of the project so I thought I should at least report it to get some ideas on how best to solve it.