Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
packages/emoji/src/emoji.json linguist-generated=true
# Generated by `bun run --cwd packages/contracts generate`; collapsed in diffs.
packages/contracts/openapi.json linguist-generated=true
# Generated by `node apps/codegen/generate.ts`; collapsed in diffs.
apps/android/**/*.generated.kt linguist-generated=true
31 changes: 31 additions & 0 deletions .github/workflows/native.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Native apps

# Checks that the files the native apps generate from the web's packages and
# the API are what the generators make from them now. Only when the apps
# change: until then they keep the files they last took, so a change to the
# web or the API doesn't wait on them. Whoever changes an app regenerates
# first, with `node apps/codegen/generate.ts`, and catches it up then.

on:
push:
branches: [main]
paths:
- "apps/**"
- ".github/workflows/native.yml"
pull_request:
paths:
- "apps/**"
- ".github/workflows/native.yml"

concurrency:
group: native-${{ github.ref }}
cancel-in-progress: true

jobs:
generated:
name: Generated files
runs-on: depot-ubuntu-24.04-4
steps:
- uses: actions/checkout@v5
- uses: ./.github/actions/setup
- run: bunx vitest run --config apps/codegen/vitest.config.ts
3 changes: 3 additions & 0 deletions apps/android/api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
.gradle/
.kotlin/
32 changes: 32 additions & 0 deletions apps/android/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Sugabots API for Android

The API's types and routes in Kotlin, package `ai.sugabots.api`, for the Android
app to depend on once there is one. It needs only kotlinx.serialization and
kotlinx.coroutines.

- `Api.generated.kt` is generated from `packages/contracts/openapi.json`. Don't
edit it by hand. It stays as it was last generated while the API moves on;
from the repo root, regenerate it to take the API's changes:

```sh
node apps/codegen/generate.ts
```

On a change under `apps/`, the `codegen` tests
(`bunx vitest run --config apps/codegen/vitest.config.ts`) fail while it is out of date.
The generator is `apps/codegen/generate-api.ts`: `api/model.ts` reads the
API, and `api/kotlin.ts` writes this file.
- `ApiSupport.kt` is what it's written against: `ApiTransport`, which the app
implements over OkHttp or Ktor to send requests with the API's address and the
bearer token; `ApiJson`; `Omittable`, for a field a request may leave out or
send as null; and the serializers that read enums and unions a newer server
sends.

`ApiClient(transport)` groups the routes as the web's client does:
`api.threads.get(...)` there is `client.threads.get(...)` here.

Build and test it with Gradle (JDK 17):

```sh
gradle -p apps/android/api build
```
23 changes: 23 additions & 0 deletions apps/android/api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
kotlin("jvm") version "2.0.21"
kotlin("plugin.serialization") version "2.0.21"
}

repositories {
mavenCentral()
}

dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
testImplementation(kotlin("test"))
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0")
}

kotlin {
jvmToolchain(17)
}

tasks.test {
useJUnitPlatform()
}
1 change: 1 addition & 0 deletions apps/android/api/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "sugabots-api"
Loading
Loading