OpenAPITools / OpenAPITools/openapi-generator
[REQ] [Protobuf-Schema] Option to generate wrapper types for primitives
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
Proto3 primitive types don't handle well missing values.
In Java you need to call message.hasField(MyMessage.getDescriptor().findFieldByName("myfield")) to know if a field was actually present on the wire, which is not very usable. Calling message.getField() would return the primitive default value.
With #11072 support was added for optional keyword (https://github.com/protocolbuffers/protobuf/blob/main/docs/field_presence.md), but it has some constraints such as fields having null type in the spec.
Another approach that could be supported is to use the built-in wrapper types or "WellKnownTypes" of Protobuf (https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/wrappers.proto)
Describe the solution you'd like
Add a codegen option <useWrapperTypes>true</useWrapperTypes> to use the google.protobuf.xxxxValue types instead of primitive types, and add the import "google/protobuf/wrappers.proto"; in the generated .proto
Describe alternatives you've considered
Allow custom type mapping between OAS types and proto types. But WellKnownTypes being part of proto coding guidelines, they make sense to be pre-set.
Additional context
I'm willing to contribute a PR with the changes.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the protobuf schema generator and the code that emits generated .proto files; the issue does not name repository files or tests. Read google/protobuf/wrappers.proto to map primitive types to wrapper types, then verify that the option causes the wrappers import and corresponding generated field types to appear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100