Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cat-voices): 1128 remove openapi #1130

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
29 changes: 0 additions & 29 deletions catalyst_voices/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,6 @@ builder:
COPY +repo-catalyst-voices/repo .
DO flutter-ci+BOOTSTRAP

# Generates flutter code.
# Based on Catalyst Gateway OpenAPI specifications generates models, clients
# and serialization logic.
# It accepts [save_locally] ARG that when true place the artifacts in the
# proper folder of `catalyst_voices_services` local code.
code-generator:
ARG save_locally=false

LET gen_code_path = lib/generated/catalyst_gateway
LET local_gen_code_path = packages/internal/catalyst_voices_services/lib/generated/catalyst_gateway/

FROM +builder
WORKDIR packages/internal/catalyst_voices_services
COPY catalyst-gateway+build/doc/cat-gateway-api.json openapi/cat-gateway-api.json
DO flutter-ci+OPENAPI_CODE_GEN \
--SAVE_LOCALLY=$save_locally \
--GEN_CODE_PATH=$gen_code_path \
--LOCAL_GEN_CODE_PATH=$local_gen_code_path

# Tests that the code generation is consistent
# with the generated code currently in the repo.
# This MUST be a test target because it requires artifacts from build targets.
test-flutter-code-generator:
FROM +code-generator
# Copy generated files in the local file tree to a temporary folder
COPY packages/internal/catalyst_voices_services/lib/generated/catalyst_gateway /tmp/repo_generated
# Check diff between local code and earthly artifacts
RUN diff /tmp/repo_generated lib/generated/catalyst_gateway

# Runs static analysis on the code.
check-static-analysis:
FROM +builder
Expand Down
2 changes: 1 addition & 1 deletion catalyst_voices/apps/voices/integration_test/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ integration-test-web:
# END
RUN ($driver --port=$driver_port > $driver.log &) && \
sleep 5 && \
flutter drive --driver=test_driver/integration_tests.dart \
flutter drive --driver=test_driver/integration_tests.dart --verbose \
--target=integration_test/app_test.dart \
-d web-server --browser-name=$browser --driver-port=$driver_port \
# https://github.com/flutter/flutter/issues/154727
Expand Down
8 changes: 0 additions & 8 deletions catalyst_voices/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,5 @@ check-code:
test-code:
earthly +test-unit

# Generates gateway services in packages/internal/catalyst_voices_services
generate-gateway-services:
cd .. && earthly ./catalyst_voices+code-generator --platform=linux/amd64 --save_locally=true

# Test generated gateway services
test-gateway-services:
cd .. && earthly ./catalyst_voices+test-flutter-code-generator --platform=linux/amd64

# Pre Push Checks
pre-push: check-code
Original file line number Diff line number Diff line change
@@ -1,37 +1 @@
# Catalyst Voices Services

## Automated Code Generation

This package is used for the code generation from the OpenAPI specifications.
It leverages `swagger_dart_code_generator` library and the artifacts generated
for the documentation of the `catalyst-gateway` backend.
The process consists in 3 simple steps:

1. The OpenAPI specification is picked from the artifact generated in the
`Earthfile` of `catalyst-gateway`.
2. The code is generated and saved as an artifact in the `Earthfile` of
`catalyst_voices`
3. Generated code is placed in the proper location within the `catalyst_voices`
project (`packages/catalyst_voices_services/lib/generated/catalyst_gateway`)
and it's ready for local usage.

This process can be achieved by executing from the `catalyst_voices` root
folder:

```sh
earthly +code-generator --platform=linux/amd64 --save_locally=true
```

The `--platform=linux/amd64` flag is necessary only when running the command from
a different platform such as **Windows** or **macOS**.
It ensures that the code generation process is compatible with the target platform.
If you are running the command on a **Linux** platform, you can omit this flag.

In this way it's possible to locally generate the code using the same version of
OpenAPI specs defined in the backend code and developers have full control of
what should be committed.

To ensure the consistency of the generated code (especially when backend changes
occur) an earthly target is automatically executed on PR against main.
This `+test-flutter-code-generator` generates the code on the CI and compares
it with the code currently in repo, failing if there is an inconsistency.

This file was deleted.

Loading
Loading