traveltime-dev / traveltime-sdk-java

TravelTime SDK for JAVA programming language
https://docs.traveltime.com/
MIT License
6 stars 1 forks source link

Add @Singular annotation to all list fields in request dtos #89

Closed mjanuszkiewicz-tt closed 1 year ago

mjanuszkiewicz-tt commented 1 year ago

Allows us to use

builder.property(x)

instead of

builder.properties(new List<>(x))

Technically a breaking change since previously a call to properties overrode the previously set properties, not it's essentially an addAll call. To reset the user would have to call clearProperties. I guess this means if merged we would have to increment a major version.

Soliciting ideas for singular names for

public class ArrivalSearches {
    @NonNull
    List<ManyToOne> manyToOne;
    @NonNull
    List<OneToMany> oneToMany;
}
Donatas-L commented 1 year ago

Tests are failing

mjanuszkiewicz-tt commented 1 year ago

Tests are failing

Fixed, the @Singular annotation means that if we don't add an element we now generate an empty list instead of not outputting a field at all. I will make sure we don't do something weird where missing filed != field with empty list.

Donatas-L commented 1 year ago

How does it work with naming?

@Singular
List<String> withinCountries;

Would be:

builder
.withinCountry("Country 1")
.withinCountry("Country 2")

?

mjanuszkiewicz-tt commented 1 year ago

How does it work with naming?

@Singular
List<String> withinCountries;

Would be:

builder
.withinCountry("Country 1")
.withinCountry("Country 2")

?

Yes. if lombok can't figure out a singular form it won't compile unless you set it manually.

Donatas-L commented 1 year ago

How does it work with naming?

@Singular
List<String> withinCountries;

Would be:

builder
.withinCountry("Country 1")
.withinCountry("Country 2")

?

Yes. if lombok can't figure out a singular form it won't compile unless you set it manually.

So a bit of magical code generation via annotations :D

mjanuszkiewicz-tt commented 1 year ago

So a bit of magical code generation via annotations :D

Yeah, lombok does a lot of heavy lifting for stuff like this.

danielnaumau commented 1 year ago

Can you please update readme and examples?