Skip to content

Commit 9f5e0d5

Browse files
authored
chore: update generator to allow updating chat or video only (#19)
1 parent daf0d38 commit 9f5e0d5

File tree

3 files changed

+104
-69
lines changed

3 files changed

+104
-69
lines changed

CONTRIBUTING.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ If you don't want to squash your commits, make sure that your commits follow the
3030

3131
## Generating code from Open API
3232

33+
### Commands
34+
3335
Checkout the [protocol](https://github.com/GetStream/protocol) or [chat](https://github.com/GetStream/chat) reporisitories and run one of the following commands:
3436

3537
```shell
@@ -39,10 +41,19 @@ $ yarn generate:open-api
3941
$ yarn generate:open-api:dev
4042
```
4143

42-
Fix manually the known issues issues in the generated code:
44+
If you want to update only chat or video you need to define the `PRODUCT` env variable like this:
45+
46+
```shell
47+
$ PRODUCT=video yarn generate:open-api
48+
$ PRODUCT=chat yarn generate:open-api:dev
49+
```
4350

44-
- Add `/** @ts-expect-error */ ` for imports for `ImageSizeRequest`, `OnlyUserIDRequest` in the `gen/chat/FilesApi.ts` and `gen/chat/MessagesApi.ts` files
45-
- Add `/** @ts-expect-error */ ` for duplicate exports in `gen/chat/index.ts`
51+
### Fix issues in chat code
52+
53+
If you have updated the generated chat code you'll have to fix the following issues manually in the generated code:
54+
55+
- Add `/** @ts-expect-error */ ` (make sure to use this exact comment format otherwise they will be missing from `d.ts` files) for imports for `ImageSizeRequest`, `OnlyUserIDRequest` in the `gen/chat/FilesApi.ts` and `gen/chat/MessagesApi.ts` files
56+
- Add `/** @ts-expect-error */ ` (make sure to use this exact comment format otherwise they will be missing from `d.ts` files) for duplicate exports in `gen/chat/index.ts`
4657
- Fix the query param serizalization in the `gen/chat/MessagesApi.ts` file's `getManyMessagesRaw` function. This is the correct serialization:
4758

4859
```typescript
@@ -51,6 +62,8 @@ if (requestParameters.ids) {
5162
}
5263
```
5364

65+
### Validate that the generated code works
66+
5467
To check your work, run the following commands:
5568

5669
```

generate-openapi.sh

Lines changed: 86 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,98 @@
22
set -euo pipefail
33

44
FROM_REPO=$1;
5+
DEFAULT_PRODUCT="all";
6+
PRODUCT="${2:-$DEFAULT_PRODUCT}";
57

6-
if [ "$FROM_REPO" == 'chat' ]; then
7-
PROTOCOL_REPO_DIR="../chat"
8-
else
9-
PROTOCOL_REPO_DIR="../protocol"
10-
fi
11-
if [ "$FROM_REPO" == 'chat' ]; then
12-
SCHEMA_FILE="$PROTOCOL_REPO_DIR/releases/video-openapi.yaml"
13-
else
14-
SCHEMA_FILE="$PROTOCOL_REPO_DIR/openapi/video-openapi.yaml"
15-
fi
8+
echo $PRODUCT;
169

17-
if [ "$FROM_REPO" == 'chat' ]; then
18-
# Generate the Coordinator OpenAPI schema
19-
make -C $PROTOCOL_REPO_DIR video-openapi
10+
if [ "$PRODUCT" != 'chat' ] && [ "$PRODUCT" != 'video' ] && [ "$PRODUCT" != 'all' ]; then
11+
echo "Invalid product option $PRODUCT"
12+
exit 1
2013
fi
2114

22-
OUTPUT_DIR="./src/gen"
2315
TEMP_OUTPUT_DIR="./openapi-temp"
2416

25-
# Clean previous output
26-
rm -rf $TEMP_OUTPUT_DIR
27-
rm -rf $OUTPUT_DIR
28-
29-
mkdir $OUTPUT_DIR
30-
31-
# NOTE: https://openapi-generator.tech/docs/generators/typescript-fetch/
32-
# Generate the Coordinator API models
33-
yarn openapi-generator-cli generate \
34-
-i "$SCHEMA_FILE" \
35-
-g typescript-fetch \
36-
-o "$TEMP_OUTPUT_DIR" \
37-
--additional-properties=supportsES6=true \
38-
--additional-properties=modelPropertyNaming=original \
39-
--additional-properties=enumPropertyNaming=UPPERCASE \
40-
--additional-properties=withoutRuntimeChecks=true \
41-
--model-name-prefix=Video
42-
43-
# Remove the generated API client, just keep the models
44-
cp -r $TEMP_OUTPUT_DIR $OUTPUT_DIR/video
45-
rm -rf $TEMP_OUTPUT_DIR
46-
47-
48-
if [ "$FROM_REPO" == 'chat' ]; then
49-
PROTOCOL_REPO_DIR="../chat"
50-
else
51-
PROTOCOL_REPO_DIR="../protocol"
52-
fi
53-
if [ "$FROM_REPO" == 'chat' ]; then
54-
SCHEMA_FILE="$PROTOCOL_REPO_DIR/releases/chat-openapi.yaml"
55-
else
56-
SCHEMA_FILE="$PROTOCOL_REPO_DIR/openapi/chat-openapi.yaml"
57-
fi
17+
if [ "$PRODUCT" == 'video' ] || [ "$PRODUCT" == 'all' ] ; then
18+
if [ "$FROM_REPO" == 'chat' ]; then
19+
PROTOCOL_REPO_DIR="../chat"
20+
else
21+
PROTOCOL_REPO_DIR="../protocol"
22+
fi
23+
if [ "$FROM_REPO" == 'chat' ]; then
24+
SCHEMA_FILE="$PROTOCOL_REPO_DIR/releases/video-openapi.yaml"
25+
else
26+
SCHEMA_FILE="$PROTOCOL_REPO_DIR/openapi/video-openapi.yaml"
27+
fi
28+
29+
if [ "$FROM_REPO" == 'chat' ]; then
30+
# Generate the Coordinator OpenAPI schema
31+
make -C $PROTOCOL_REPO_DIR video-openapi
32+
fi
33+
34+
OUTPUT_DIR="./src/gen/video"
35+
36+
# Clean previous output
37+
rm -rf $TEMP_OUTPUT_DIR
38+
rm -rf $OUTPUT_DIR
39+
40+
mkdir $OUTPUT_DIR
41+
42+
# NOTE: https://openapi-generator.tech/docs/generators/typescript-fetch/
43+
# Generate the Coordinator API models
44+
yarn openapi-generator-cli generate \
45+
-i "$SCHEMA_FILE" \
46+
-g typescript-fetch \
47+
-o "$TEMP_OUTPUT_DIR" \
48+
--additional-properties=supportsES6=true \
49+
--additional-properties=modelPropertyNaming=original \
50+
--additional-properties=enumPropertyNaming=UPPERCASE \
51+
--additional-properties=withoutRuntimeChecks=true \
52+
--model-name-prefix=Video
5853

59-
if [ "$FROM_REPO" == 'chat' ]; then
60-
# Generate the Coordinator OpenAPI schema
61-
make -C $PROTOCOL_REPO_DIR chat-openapi
54+
# Remove the generated API client, just keep the models
55+
cp -r $TEMP_OUTPUT_DIR/ $OUTPUT_DIR
56+
rm -rf $TEMP_OUTPUT_DIR
6257
fi
6358

64-
# NOTE: https://openapi-generator.tech/docs/generators/typescript-fetch/
65-
# Generate the Coordinator API models
66-
yarn openapi-generator-cli generate \
67-
-i "$SCHEMA_FILE" \
68-
-g typescript-fetch \
69-
-o "$TEMP_OUTPUT_DIR" \
70-
--additional-properties=supportsES6=true \
71-
--additional-properties=modelPropertyNaming=original \
72-
--additional-properties=enumPropertyNaming=UPPERCASE \
73-
--additional-properties=withoutRuntimeChecks=true
74-
75-
# Remove the generated API client, just keep the models
76-
cp -r $TEMP_OUTPUT_DIR $OUTPUT_DIR/chat
77-
rm -rf $TEMP_OUTPUT_DIR
59+
60+
if [ "$PRODUCT" == 'chat' ] || [ "$PRODUCT" == 'all' ]; then
61+
if [ "$FROM_REPO" == 'chat' ]; then
62+
PROTOCOL_REPO_DIR="../chat"
63+
else
64+
PROTOCOL_REPO_DIR="../protocol"
65+
fi
66+
if [ "$FROM_REPO" == 'chat' ]; then
67+
SCHEMA_FILE="$PROTOCOL_REPO_DIR/releases/chat-openapi.yaml"
68+
else
69+
SCHEMA_FILE="$PROTOCOL_REPO_DIR/openapi/chat-openapi.yaml"
70+
fi
71+
72+
if [ "$FROM_REPO" == 'chat' ]; then
73+
# Generate the Coordinator OpenAPI schema
74+
make -C $PROTOCOL_REPO_DIR chat-openapi
75+
fi
76+
77+
OUTPUT_DIR="./src/gen/chat"
78+
79+
# Clean previous output
80+
rm -rf $TEMP_OUTPUT_DIR
81+
rm -rf $OUTPUT_DIR
82+
83+
mkdir $OUTPUT_DIR
84+
85+
# NOTE: https://openapi-generator.tech/docs/generators/typescript-fetch/
86+
# Generate the Coordinator API models
87+
yarn openapi-generator-cli generate \
88+
-i "$SCHEMA_FILE" \
89+
-g typescript-fetch \
90+
-o "$TEMP_OUTPUT_DIR" \
91+
--additional-properties=supportsES6=true \
92+
--additional-properties=modelPropertyNaming=original \
93+
--additional-properties=enumPropertyNaming=UPPERCASE \
94+
--additional-properties=withoutRuntimeChecks=true
95+
96+
# Remove the generated API client, just keep the models
97+
cp -r $TEMP_OUTPUT_DIR/ $OUTPUT_DIR
98+
rm -rf $TEMP_OUTPUT_DIR
99+
fi

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"test:bun": "bun run vitest",
1919
"start": "rollup -w -c",
2020
"build": "rm -rf dist && rollup -c",
21-
"generate:open-api": "./generate-openapi.sh protocol",
22-
"generate:open-api:dev": "./generate-openapi.sh chat",
21+
"generate:open-api": "./generate-openapi.sh protocol $PRODUCT",
22+
"generate:open-api:dev": "./generate-openapi.sh chat $PRODUCT",
2323
"lint": "eslint **/*.ts",
2424
"lint:fix": "eslint --fix **/*.ts",
2525
"prettier:fix": "prettier . --write"

0 commit comments

Comments
 (0)