diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 18f8ac2..dbfff79 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,6 +30,8 @@ If you don't want to squash your commits, make sure that your commits follow the ## Generating code from Open API +### Commands + Checkout the [protocol](https://github.com/GetStream/protocol) or [chat](https://github.com/GetStream/chat) reporisitories and run one of the following commands: ```shell @@ -39,10 +41,19 @@ $ yarn generate:open-api $ yarn generate:open-api:dev ``` -Fix manually the known issues issues in the generated code: +If you want to update only chat or video you need to define the `PRODUCT` env variable like this: + +```shell +$ PRODUCT=video yarn generate:open-api +$ PRODUCT=chat yarn generate:open-api:dev +``` -- Add `/** @ts-expect-error */ ` for imports for `ImageSizeRequest`, `OnlyUserIDRequest` in the `gen/chat/FilesApi.ts` and `gen/chat/MessagesApi.ts` files -- Add `/** @ts-expect-error */ ` for duplicate exports in `gen/chat/index.ts` +### Fix issues in chat code + +If you have updated the generated chat code you'll have to fix the following issues manually in the generated code: + +- 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 +- 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` - Fix the query param serizalization in the `gen/chat/MessagesApi.ts` file's `getManyMessagesRaw` function. This is the correct serialization: ```typescript @@ -51,6 +62,8 @@ if (requestParameters.ids) { } ``` +### Validate that the generated code works + To check your work, run the following commands: ``` diff --git a/generate-openapi.sh b/generate-openapi.sh index 36a6e07..4e03b4b 100755 --- a/generate-openapi.sh +++ b/generate-openapi.sh @@ -2,76 +2,98 @@ set -euo pipefail FROM_REPO=$1; +DEFAULT_PRODUCT="all"; +PRODUCT="${2:-$DEFAULT_PRODUCT}"; -if [ "$FROM_REPO" == 'chat' ]; then - PROTOCOL_REPO_DIR="../chat" -else - PROTOCOL_REPO_DIR="../protocol" -fi -if [ "$FROM_REPO" == 'chat' ]; then - SCHEMA_FILE="$PROTOCOL_REPO_DIR/releases/video-openapi.yaml" -else - SCHEMA_FILE="$PROTOCOL_REPO_DIR/openapi/video-openapi.yaml" -fi +echo $PRODUCT; -if [ "$FROM_REPO" == 'chat' ]; then - # Generate the Coordinator OpenAPI schema - make -C $PROTOCOL_REPO_DIR video-openapi +if [ "$PRODUCT" != 'chat' ] && [ "$PRODUCT" != 'video' ] && [ "$PRODUCT" != 'all' ]; then + echo "Invalid product option $PRODUCT" + exit 1 fi -OUTPUT_DIR="./src/gen" TEMP_OUTPUT_DIR="./openapi-temp" -# Clean previous output -rm -rf $TEMP_OUTPUT_DIR -rm -rf $OUTPUT_DIR - -mkdir $OUTPUT_DIR - -# NOTE: https://openapi-generator.tech/docs/generators/typescript-fetch/ -# Generate the Coordinator API models -yarn openapi-generator-cli generate \ - -i "$SCHEMA_FILE" \ - -g typescript-fetch \ - -o "$TEMP_OUTPUT_DIR" \ - --additional-properties=supportsES6=true \ - --additional-properties=modelPropertyNaming=original \ - --additional-properties=enumPropertyNaming=UPPERCASE \ - --additional-properties=withoutRuntimeChecks=true \ - --model-name-prefix=Video - -# Remove the generated API client, just keep the models -cp -r $TEMP_OUTPUT_DIR $OUTPUT_DIR/video -rm -rf $TEMP_OUTPUT_DIR - - -if [ "$FROM_REPO" == 'chat' ]; then - PROTOCOL_REPO_DIR="../chat" -else - PROTOCOL_REPO_DIR="../protocol" -fi -if [ "$FROM_REPO" == 'chat' ]; then - SCHEMA_FILE="$PROTOCOL_REPO_DIR/releases/chat-openapi.yaml" -else - SCHEMA_FILE="$PROTOCOL_REPO_DIR/openapi/chat-openapi.yaml" -fi +if [ "$PRODUCT" == 'video' ] || [ "$PRODUCT" == 'all' ] ; then + if [ "$FROM_REPO" == 'chat' ]; then + PROTOCOL_REPO_DIR="../chat" + else + PROTOCOL_REPO_DIR="../protocol" + fi + if [ "$FROM_REPO" == 'chat' ]; then + SCHEMA_FILE="$PROTOCOL_REPO_DIR/releases/video-openapi.yaml" + else + SCHEMA_FILE="$PROTOCOL_REPO_DIR/openapi/video-openapi.yaml" + fi + + if [ "$FROM_REPO" == 'chat' ]; then + # Generate the Coordinator OpenAPI schema + make -C $PROTOCOL_REPO_DIR video-openapi + fi + + OUTPUT_DIR="./src/gen/video" + + # Clean previous output + rm -rf $TEMP_OUTPUT_DIR + rm -rf $OUTPUT_DIR + + mkdir $OUTPUT_DIR + + # NOTE: https://openapi-generator.tech/docs/generators/typescript-fetch/ + # Generate the Coordinator API models + yarn openapi-generator-cli generate \ + -i "$SCHEMA_FILE" \ + -g typescript-fetch \ + -o "$TEMP_OUTPUT_DIR" \ + --additional-properties=supportsES6=true \ + --additional-properties=modelPropertyNaming=original \ + --additional-properties=enumPropertyNaming=UPPERCASE \ + --additional-properties=withoutRuntimeChecks=true \ + --model-name-prefix=Video -if [ "$FROM_REPO" == 'chat' ]; then - # Generate the Coordinator OpenAPI schema - make -C $PROTOCOL_REPO_DIR chat-openapi + # Remove the generated API client, just keep the models + cp -r $TEMP_OUTPUT_DIR/ $OUTPUT_DIR + rm -rf $TEMP_OUTPUT_DIR fi -# NOTE: https://openapi-generator.tech/docs/generators/typescript-fetch/ -# Generate the Coordinator API models -yarn openapi-generator-cli generate \ - -i "$SCHEMA_FILE" \ - -g typescript-fetch \ - -o "$TEMP_OUTPUT_DIR" \ - --additional-properties=supportsES6=true \ - --additional-properties=modelPropertyNaming=original \ - --additional-properties=enumPropertyNaming=UPPERCASE \ - --additional-properties=withoutRuntimeChecks=true - -# Remove the generated API client, just keep the models -cp -r $TEMP_OUTPUT_DIR $OUTPUT_DIR/chat -rm -rf $TEMP_OUTPUT_DIR \ No newline at end of file + +if [ "$PRODUCT" == 'chat' ] || [ "$PRODUCT" == 'all' ]; then + if [ "$FROM_REPO" == 'chat' ]; then + PROTOCOL_REPO_DIR="../chat" + else + PROTOCOL_REPO_DIR="../protocol" + fi + if [ "$FROM_REPO" == 'chat' ]; then + SCHEMA_FILE="$PROTOCOL_REPO_DIR/releases/chat-openapi.yaml" + else + SCHEMA_FILE="$PROTOCOL_REPO_DIR/openapi/chat-openapi.yaml" + fi + + if [ "$FROM_REPO" == 'chat' ]; then + # Generate the Coordinator OpenAPI schema + make -C $PROTOCOL_REPO_DIR chat-openapi + fi + + OUTPUT_DIR="./src/gen/chat" + + # Clean previous output + rm -rf $TEMP_OUTPUT_DIR + rm -rf $OUTPUT_DIR + + mkdir $OUTPUT_DIR + + # NOTE: https://openapi-generator.tech/docs/generators/typescript-fetch/ + # Generate the Coordinator API models + yarn openapi-generator-cli generate \ + -i "$SCHEMA_FILE" \ + -g typescript-fetch \ + -o "$TEMP_OUTPUT_DIR" \ + --additional-properties=supportsES6=true \ + --additional-properties=modelPropertyNaming=original \ + --additional-properties=enumPropertyNaming=UPPERCASE \ + --additional-properties=withoutRuntimeChecks=true + + # Remove the generated API client, just keep the models + cp -r $TEMP_OUTPUT_DIR/ $OUTPUT_DIR + rm -rf $TEMP_OUTPUT_DIR +fi diff --git a/package.json b/package.json index 4fa168e..bc3c1a3 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,8 @@ "test:bun": "bun run vitest", "start": "rollup -w -c", "build": "rm -rf dist && rollup -c", - "generate:open-api": "./generate-openapi.sh protocol", - "generate:open-api:dev": "./generate-openapi.sh chat", + "generate:open-api": "./generate-openapi.sh protocol $PRODUCT", + "generate:open-api:dev": "./generate-openapi.sh chat $PRODUCT", "lint": "eslint **/*.ts", "lint:fix": "eslint --fix **/*.ts", "prettier:fix": "prettier . --write"