|
| 1 | +# :recycle: Contributing <!-- omit in toc --> |
| 2 | + |
| 3 | +> [!NOTE] |
| 4 | +> Most of the code in this repository is **automatically generated** from the [OpenAPI specification](https://getstream.github.io/protocol/) of the Stream API. Therefore, **it does NOT make sense to try to change them manually**. |
| 5 | +
|
| 6 | +Tests are written manually and more tests are always welcome. |
| 7 | +Some parts like `lib/src/main/java/io/getstream/services/framework` and `lib/src/main/java/io/getstream/models/framework`, serve as the base and are written manually as well. |
| 8 | + |
| 9 | +## Requirements <!-- omit in toc --> |
| 10 | + |
| 11 | +To contribute to this project, you need to have [Lombok](https://projectlombok.org/) installed in your IDE. |
| 12 | +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). |
| 13 | + |
| 14 | +- [Setup the project](#setup-the-project) |
| 15 | +- [Architecture explanation](#architecture-explanation) |
| 16 | + - [Model classes](#model-classes) |
| 17 | + - [Request classes](#request-classes) |
| 18 | + - [RequestData and RequestObject classes](#requestdata-and-requestobject-classes) |
| 19 | + - [Response classes](#response-classes) |
| 20 | + - [Service interfaces](#service-interfaces) |
| 21 | + - [The StreamServiceGenerator class](#the-streamservicegenerator-class) |
| 22 | + - [The StreamResponse interface and related classes](#the-streamresponse-interface-and-related-classes) |
| 23 | + - [The StreamRequest and StreamServiceHandler classes](#the-streamrequest-and-streamservicehandler-classes) |
| 24 | + - [Test classes](#test-classes) |
| 25 | +- [Code rules](#code-rules) |
| 26 | +- [How to](#how-to) |
| 27 | + - [Enable logging](#enable-logging) |
| 28 | +- [Commit message convention](#commit-message-convention) |
| 29 | +- [Releasing a new version (for Stream developers)](#releasing-a-new-version-for-stream-developers) |
| 30 | + |
| 31 | +## Setup the project |
| 32 | + |
| 33 | +The project is a Maven project. |
| 34 | + |
| 35 | +Copy `local.properties.example` to `local.properties` and put configuration there. These properties are automatically picked up during tests execution |
| 36 | + |
| 37 | +```shell |
| 38 | +# Run tests |
| 39 | +./gradlew test |
| 40 | + |
| 41 | +# Check code style |
| 42 | +./gradlew spotlessCheck |
| 43 | + |
| 44 | +# Fix code style problems |
| 45 | +./gradlew spotlessApply |
| 46 | +``` |
| 47 | + |
| 48 | +## Architecture explanation |
| 49 | + |
| 50 | +The code is composed of: |
| 51 | + |
| 52 | +### Model classes |
| 53 | + |
| 54 | +They are the data objects. They correspond to the formats of the objects contained in the API responses. |
| 55 | + |
| 56 | +### Request classes |
| 57 | + |
| 58 | +They are builders for API requests, and also contain methods to perform the calls. |
| 59 | + |
| 60 | +### RequestData and RequestObject classes |
| 61 | + |
| 62 | +They are data objects. They correspond to the formats of the API requests. |
| 63 | + |
| 64 | +### Response classes |
| 65 | + |
| 66 | +They are data objects. They correspond to the formats of the API responses. |
| 67 | + |
| 68 | +### Service interfaces |
| 69 | + |
| 70 | +They are the interfaces that define the API endpoints. |
| 71 | + |
| 72 | +### The StreamServiceGenerator class |
| 73 | + |
| 74 | +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. |
| 75 | +It also handles authentication and logging. |
| 76 | + |
| 77 | +### The StreamResponse interface and related classes |
| 78 | + |
| 79 | +StreamResponse is the interface that correspond to an API response. Most APIs responses are StreamResponseObject (mean they contain duration and rate limit data). |
| 80 | + |
| 81 | +### The StreamRequest and StreamServiceHandler classes |
| 82 | + |
| 83 | +StreamRequest is the generic Request class, that defines the `request` and `requestAsync` methods, which call the `StreamServiceHandler`. |
| 84 | +The `StreamServiceHandler` class defines the synchronous and asynchronous processing. It also enriched the Response object with rate limit data when available. |
| 85 | + |
| 86 | +### Test classes |
| 87 | + |
| 88 | +They are organized by model. Each endpoint has at least one test related. |
| 89 | + |
| 90 | +## Code rules |
| 91 | + |
| 92 | +- The code should be formatted using Google formatter. |
| 93 | +- All attributes, parameters and return values should be annotated with either `@Nullable` or `@NotNull` |
| 94 | +- New implementations should follow the same principles as the existing ones (see how to section below) |
| 95 | +- In Models, collections of submodel should be List (other collections and arrays are not supported by RequestObjectBuilder) |
| 96 | +- 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 |
| 97 | + |
| 98 | +## How to |
| 99 | + |
| 100 | +### Enable logging |
| 101 | + |
| 102 | +Logging is enabled by default in tests. If you want to create a main class and activate logging, you should do the following: |
| 103 | + |
| 104 | +```java |
| 105 | +StreamServiceGenerator.logLevel = HttpLoggingInterceptor.Level.BODY; |
| 106 | +``` |
| 107 | + |
| 108 | +## Commit message convention |
| 109 | + |
| 110 | +This repository follows a commit message convention in order to automatically generate the [CHANGELOG](./CHANGELOG.md). Make sure you follow the rules of [conventional commits](https://www.conventionalcommits.org/) when opening a pull request. |
| 111 | + |
| 112 | +## Releasing a new version (for Stream developers) |
| 113 | + |
| 114 | +In order to release new version you need to be a maintainer of the library. |
| 115 | + |
| 116 | +- Kick off a job called `initiate_release` ([link](https://github.com/GetStream/stream-sdk-java/actions/workflows/initiate_release.yml)). |
| 117 | + |
| 118 | +The job creates a pull request with the changelog. Check if it looks good. |
| 119 | + |
| 120 | +- Merge the pull request. |
| 121 | + |
| 122 | +Once the PR is merged, it automatically kicks off another job which will upload the Gem to RubyGems.org and creates a GitHub release. |
0 commit comments