palantir / palantir/conjure-java
Foo.Of method makes all arguments mandatory, including optionals
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 39
- Forks
- 49
- Avg merge
- 8h 22m
- Merged PRs (30d)
- 32
Description
What happened?
Adding an optional field to an object definition in yml causes the generated object to require the field in its of method. This technically makes any optional field addition breaking.
e.g. going from
DuplicateRequest:
fields:
parentFolderId: optional<string>
to
DuplicateRequest:
fields:
parentFolderId: optional<string>
foo: optional<string>
generates
@JsonDeserialize(builder = DuplicateRequest.Builder.class)
@Generated("com.palantir.conjure.java.types.BeanGenerator")
public final class DuplicateRequest {
...
public static DuplicateRequest of(String parentFolderId, String foo) {
return builder().parentFolderId(Optional.of(parentFolderId)).foo(Optional.of(foo)).build();
}
}
A few things seem off wrong here:
ofshouldn't require optional fields - they should be optional or hidden via overloading- adding an optional field should preserve the previous
ofmethods in case consumers were already using them - removing them
What did you want to happen?
Some combination of:
- The
ofmethod should require optionals for optional fields. - The
ofmethod should be overloaded for all possible argument combinations given optional arguments - The
ofmethod only takes required fields, ignoring optional ones so there's no chance of breaks - No
ofmethod in the first place
I'm making the assumption that the method signature change here is a (small) break.
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
The issue does not name source files or tests; start by locating the BeanGenerator implementation and the generated object's of methods. Compare generation for required and optional fields, then review existing compatibility tests if present. Done means the behavior for optional fields is decided and generated APIs do not unnecessarily break existing callers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100