Skip to content

Commit b2e13a6

Browse files
committed
docs: Update instruction file
1 parent a535ee4 commit b2e13a6

File tree

1 file changed

+34
-38
lines changed

1 file changed

+34
-38
lines changed

ai.md

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,47 @@ This is not a KMP project.
1616
- `build.gradle.kts`: Gradle build file for the project.
1717
- `settings.gradle.kts`: Gradle settings file for the project.
1818

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.
2249
- Use `suspend` functions for API calls to allow for asynchronous programming.
23-
- Use `data class` for models to represent API responses.
2450
- API responses are annotated using the `jasminb.jsonapi-converter` library for JSONAPI serialization/deserialization.
2551
- IDs are strings, not integers.
2652
- Use `@JvmField` for fields that need to be accessed from Java code.
2753
- Responses that reference a collection use `java.util.List` instead of Kotlin's `List` to ensure compatibility with Java and the JSON API library.
2854
- Routers register an extension function on the `Api` class to provide a convenient way to access the API endpoints.
2955

30-
## Git Commits
56+
## 5. Git Commits
3157
- 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.
3359
- Provide a description of the changes in the commit body if necessary.
3460

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:
50-
51-
```kotlin
52-
import com.fasterxml.jackson.annotation.JsonCreator
53-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
54-
import com.fasterxml.jackson.annotation.JsonProperty
55-
import com.github.jasminb.jsonapi.StringIdHandler
56-
import com.github.jasminb.jsonapi.annotations.Id
57-
import com.github.jasminb.jsonapi.annotations.Relationship
58-
import com.github.jasminb.jsonapi.annotations.Type
59-
60-
@Type("projects")
61-
@JsonIgnoreProperties(ignoreUnknown = true)
62-
data class Project @JsonCreator constructor(
63-
@Id(StringIdHandler::class) var id: String = "",
64-
@JsonProperty("name") var name: String = ""
65-
)
66-
```
61+
## 6. Example
62+
- 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

Comments
 (0)