To contribute to this project, you need to have Lombok installed in your IDE. You also need to use javac >= 11 to compile (ensure that your JAVA_HOME points to such a location), even if the produced library is compatible with Java 8 (for some reasons, jdk 8 compiler fails on some Lombok annotations).
The project is a Maven project. For convenience, Eclipse files are provided in the repository, but it should be straightfoward to install in any other Java IDE.
The code is composed of:
They are the data objects. They correspond to the formats of the objects contained in the API responses.
They are builders for API requests, and also contain methods to perform the calls.
They are data objects. They correspond to the formats of the API requests.
They are data objects. They correspond to the formats of the API responses.
They are Retrofit service interfaces, that describe the API endpoints.
This class is responsible to make the Service interfaces usable to call the API. It is used by all Request classes to define the generateCall
method.
It also handles authentication and logging.
StreamResponse is the interface that correspond to an API response. Most APIs responses are StreamResponseObject (mean they contain duration and rate limit data).
StreamRequest is the generic Request class, that defines the request
and requestAsync
methods, which call the StreamServiceHandler
.
The StreamServiceHandler
class defines the synchronous and asynchronous processing. It also enriched the Response object with rate limit data when available.
They are organized by model. Each endpoint has at least one test related.
- The code should be formatted using Google formatter.
- All attributes, parameters and return values should be annotated with either
@Nullable
or@NotNull
- New implementations should follow the same principles as the existing ones (see how to section below)
- In Models, collections of submodel should be List (other collections and arrays are not supported by RequestObjectBuilder)
- String that only can take a given set of values should be represented as enums, with an
UNKNOWN
value marked@JsonEnumDefaultValue
to avoid problem if the list of possible values changes
Logging is enabled by default in tests. If you want to create a main class and activate logging, you should do the following:
StreamServiceGenerator.logLevel = HttpLoggingInterceptor.Level.BODY;
- If they already exist, skip this section
- Model class should have
@Data @NoArgsConstructor
- They should be created in the model, after other RequestObject classes
- All fields should be
@Nullable
- Collection fields should be
@Singular
- These classes should have a
@Builder
- If there is a corresponding Model object, they should have a
buildFrom
method and@Setter
- It should be created in the model, after other Response classes
- All fields should have
@JsonProperty("xxx")
- The xxxResponse class should extend
StreamResponseObject
and have@Data @NoArgsConstructor @EqualsAndHashCode(callSuper = true)
(or implementStreamResponseWithRateLimit
and have@Data @NoArgsConstructor
if the response is directly a model object)
- It should be created in the model, after other RequestData/Request classes
- All fields should be
@Nullable
except collections that should be never be null which should have@Singular
(which will make builder initialize them)
- It should be created inside the xxxRequestData class
- The xxxRequestData class should define this class as a Builder
@Builder(builderClassName = "xxxRequest", builderMethodName = "", buildMethodName = "internalBuild")
.
- They should be
@NotNull
attributes - The xxxRequest class should have a private constructor with all of them
- It should be added at the end of the model
- It should be static
- It should have the same parameters as the xxxRequest constructor
- It should be documented with Javadoc
- It should be added at the end of the service class
- It should have the same name as the method in the model to build the xxxRequest
- All parameters should be marked with
@Body
or@Query
or@Path
. You can use the@ToJson
annotation if you need the object to be transformed into a json String
You need to implement the generateCall
method, calling the service using the StreamServiceGenerator
- If they already exist, skip this section
- Model class should have
@Data @NoArgsConstructor
- It should be created in the model, after other Response classes
- All fields should have
@JsonProperty("xxx")
- The xxxResponse class should extend
StreamResponseObject
and have@Data @NoArgsConstructor @EqualsAndHashCode(callSuper = true)
(or implementStreamResponseWithRateLimit
and have@Data @NoArgsConstructor
if the response is directly a model object)
- It should be created in the model, after other RequestData/Request classes
- Define the parameters as private attributes
- The class should be annotated with
@RequiredArgsConstructor
- The class should have helper style methods for non required args
- It should be added at the end of the model
- It should be static
- It should have the same parameters as the xxxRequest constructor
- It should be documented with Javadoc
- It should be added at the end of the service class
- It should have the same name as the method in the model to build the xxxRequest
- All parameters should be marked with
@Query
or@Path
You need to implement the generateCall
method, calling the service using the StreamServiceGenerator
If you want to add new fields, just add the corresponding attributes in the Request, RequestData or Response class. That's all :)