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

Please provide a has(field) #2104

Closed
tweidema opened this issue Nov 4, 2024 · 2 comments
Closed

Please provide a has(field) #2104

tweidema opened this issue Nov 4, 2024 · 2 comments
Labels
kind/enhancement Improvements to existing feature.

Comments

@tweidema
Copy link

tweidema commented Nov 4, 2024

2.x branch.
As far as I can see, today you provide <Model>.has<Field>() -> Bool methods for all fields marked as optional in the proto schema.
My request is that you also provide a has(field: String, includeNonOptionals: Bool) -> Bool method or alternatively a presentFields(includeNonOptionals: Bool) -> [String] with all the present fields. Today you have no has method for fields that are not marked as optional. The includeNonOptionals should include these if set to true.

My current use-case is that I want to check that all fields specified in an updateMask are actually specifically set by the caller - instead of just taking on their default values. I can get the updateMask paths with request.message.updateMask.paths, but I can find no easy, general way check that the value for a path component was set, without writing an ugly method myself with a big switch (for the has() method) or a lot of ifs (for the presentFields() variant).

I am new to both Swift and gRPC, so maybe what I want is already possible in some other way I have not discovered?

@tweidema tweidema added the kind/enhancement Improvements to existing feature. label Nov 4, 2024
@glbrntt
Copy link
Collaborator

glbrntt commented Nov 4, 2024

Thanks for opening this – this project doesn't control how messages are generated, that's done by the SwiftProtobuf project. You should ask the folks over there instead: https://github.com/apple/swift-protobuf

@glbrntt glbrntt closed this as not planned Won't fix, can't repro, duplicate, stale Nov 4, 2024
@tweidema
Copy link
Author

tweidema commented Nov 4, 2024

@glbrntt Thanks for responding so quickly.
For anyone else coming here, I found these that seem to be more generalized versions of what I want:
apple/swift-protobuf#1029
apple/swift-protobuf#731
apple/swift-protobuf#1284
None of them seem to have gained much traction with the developers, but the last one contains a workaround that I will see if I can adapt to my use-case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements to existing feature.
Projects
None yet
Development

No branches or pull requests

2 participants