palantir / palantir/conjure-java

Foo.Of method makes all arguments mandatory, including optionals

Open
#96 5 comments 0 reactions 0 assignees View on GitHub

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:

  • of shouldn't require optional fields - they should be optional or hidden via overloading
  • adding an optional field should preserve the previous of methods in case consumers were already using them - removing them

What did you want to happen?

Some combination of:

  • The of method should require optionals for optional fields.
  • The of method should be overloaded for all possible argument combinations given optional arguments
  • The of method only takes required fields, ignoring optional ones so there's no chance of breaks
  • No of method in the first place

I'm making the assumption that the method signature change here is a (small) break.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.