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

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

Open
neilprosser opened this issue Apr 28, 2024 · 0 comments
Open

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

neilprosser opened this issue Apr 28, 2024 · 0 comments

Comments

@neilprosser
Copy link

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.

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

No branches or pull requests

1 participant