You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ai.md
+34-38Lines changed: 34 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,51 +16,47 @@ This is not a KMP project.
16
16
-`build.gradle.kts`: Gradle build file for the project.
17
17
-`settings.gradle.kts`: Gradle settings file for the project.
18
18
19
-
## 4. Coding Conventions
20
-
- Use Kotlin's idiomatic style.
21
-
- Use Routers for organising API "domains". A domain is a particular resource that the API supports. Example: `projects`.
19
+
## 4. Coding Style and Conventions
20
+
### Router Pattern
21
+
- Routers are used to organize API "domains" (e.g., operations, time bands, projects).
22
+
- Each router is responsible for a specific resource or domain and provides methods to interact with the corresponding API endpoints.
23
+
24
+
### Router Structure
25
+
- Routers extend a base `Router` class, which provides HTTP utility methods (e.g., `fetchJsonApiResource`, `fetchPaginatedJsonApiResources`).
26
+
- Routers are typically constructed with a `HttpClient` instance.
27
+
28
+
### Request Parameters
29
+
- Routers use request parameter classes (e.g., `OperationRequestParameters`, `TimeBandsRequestParameters`) to encapsulate query parameters such as pagination (`offset`, `limit`), filtering, and includes.
30
+
- These parameter classes often inherit from abstract base classes like `AbstractRequestParameters` or `RequestParametersWithIncludes` for consistency and code reuse.
31
+
32
+
### Method Naming and Return Types
33
+
- The main method to fetch all resources is named `all` and returns a paginated or full list (e.g., `PaginatedList<Operation>` or `java.util.List<TimeBand>`).
34
+
- The method to fetch a single resource is named `one` and returns the resource object (e.g., `Operation`, `TimeBand`).
35
+
- Methods are `suspend` functions to support asynchronous calls.
36
+
37
+
### Extension Properties
38
+
- Routers register an extension property on the `Api` class for convenient access (e.g., `val Api.operations: OperationsRouter`, `val Api.timeBands: TimeBandsRouter`).
39
+
40
+
### Response Models
41
+
- Response models are annotated for JSON:API serialization/deserialization using the `jasminb.jsonapi-converter` library.
42
+
- IDs are always strings.
43
+
- Collections use `java.util.List` for Java compatibility.
44
+
45
+
### Coding Conventions
46
+
- Use idiomatic Kotlin.
47
+
- Use `data class` for models.
48
+
- Use `@JvmField` for Java interop if needed.
22
49
- Use `suspend` functions for API calls to allow for asynchronous programming.
23
-
- Use `data class` for models to represent API responses.
24
50
- API responses are annotated using the `jasminb.jsonapi-converter` library for JSONAPI serialization/deserialization.
25
51
- IDs are strings, not integers.
26
52
- Use `@JvmField` for fields that need to be accessed from Java code.
27
53
- Responses that reference a collection use `java.util.List` instead of Kotlin's `List` to ensure compatibility with Java and the JSON API library.
28
54
- Routers register an extension function on the `Api` class to provide a convenient way to access the API endpoints.
29
55
30
-
## Git Commits
56
+
## 5. Git Commits
31
57
- Use conventional commit messages.
32
-
- First line of the commit should be 72 characters or less.
58
+
- First line of the commit should be 72 characters or fewer.
33
59
- Provide a description of the changes in the commit body if necessary.
34
60
35
-
## 7. Examples
36
-
Given the following JSON snippet:
37
-
```json
38
-
{
39
-
"data": {
40
-
"type": "projects",
41
-
"id": "123",
42
-
"attributes": {
43
-
"name": "My Project"
44
-
}
45
-
}
46
-
}
47
-
```
48
-
49
-
You can create a data class to represent this response:
- The `OperationsRouter` is a canonical example, with methods for `all` and `one`, a request parameters class supporting includes, and extension properties for access from `Api` and related routers.
0 commit comments