Skip to content

Commit

Permalink
chore(cat-voices): Filter OpenAPI json for Flutter (#1187)
Browse files Browse the repository at this point in the history
* chore: First version of filter-openapi job

* chore: comment out openapi-filters.json copy in Earthfile to avoid confusion during build process

* chore: change node image

* chore: verbose flag for openapi-format

* chore: copy openapi-filters

* chore: change dir of copy openapi-filters

* chore: don't delete cat-gateway-api for now

* chore: working filtering of openapi json

* fix: default value for using filtered openapi

* fix: new filtered cat gateway openAPI files

---------

Co-authored-by: Oleksandr Prokhorenko <[email protected]>
  • Loading branch information
LynxLynxx and minikin authored Nov 18, 2024
1 parent 51c128f commit 31ad353
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
6 changes: 5 additions & 1 deletion catalyst_voices/.gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
### Dart ###
# See https://www.dartlang.org/guides/libraries/private-files


# Generated files from code generation tools
*.g.dart
*.freezed.dart
*.chopper.dart
*.swagger.dart
*.openapi.dart
*.gen.dart
*.swagger.*.dart

# Un-ignore generated files in public packages
!**/packages/libs/**/*.g.dart
Expand Down Expand Up @@ -149,4 +151,6 @@ coverage/
**/fastlane/test_output

# Fastlane.swift runner binary
**/fastlane/FastlaneRunner
**/fastlane/FastlaneRunner

devtools_options.yaml
33 changes: 29 additions & 4 deletions catalyst_voices/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,32 @@ builder:
COPY +repo-catalyst-voices/repo .
DO flutter-ci+BOOTSTRAP

# Creates filtered OpenAPI spec
# Takes json file from openapi-filter from /packages/internal/catalyst_voices_services
filter-openapi:
FROM node:18
WORKDIR /packages/internal/catalyst_voices_services

COPY catalyst-gateway+build/doc/cat-gateway-api.json openapi/cat-gateway-api.json
COPY packages/internal/catalyst_voices_services/openapi-filters.json openapi-filters.json

RUN npm install -g openapi-format
RUN openapi-format openapi/cat-gateway-api.json -o openapi/filtered-openapi.json --filterFile openapi-filters.json --verbose

RUN rm openapi/cat-gateway-api.json

SAVE ARTIFACT openapi/filtered-openapi.json

# Generates flutter code.
# Generates codes for Catalyst Gateway OpenAPI, Voices Localization and
# VoicesAssets and other packages that depend on code-generator.
# It accepts [save_locally] ARG that when true place the artifacts in the
# proper folders
# It accepts [filter_openapi] ARG that when true filter the openapi spec
# using filters from /packages/internal/catalyst_voices_services/openapi-filters.json
code-generator:
ARG save_locally=false
ARG save_locally=false
ARG filter_openapi=true
FROM +builder
LET gen_code_path = lib/generated/catalyst_gateway
LET local_gen_code_path = packages/internal/catalyst_voices_services/lib/generated/catalyst_gateway/
Expand All @@ -33,16 +52,22 @@ code-generator:
RUN melos build_runner

IF [ $save_locally = true ]
RUN find . \( -name "*.g.dart" -o -name "*.freezed.dart" -o -name "*.chopper.dart" -o -name "*.swagger.dart" -o -name "*.openapi.dart" -o -name "*.gen.dart" -o -name "catalyst_voices_localizations*.dart" \)
RUN find . \( -name "*.g.dart" -o -name "*.freezed.dart" -o -name "*.chopper.dart" -o -name "*.swagger.dart" -o -name "*.openapi.dart" -o -name "*.gen.dart" -o -name "catalyst_voices_localizations*.dart" -o -name "cat_gateway_api.*.swagger.*" \)

FOR generated_file IN $(find . \( -name "*.g.dart" -o -name "*.freezed.dart" -o -name "*.chopper.dart" -o -name "*.swagger.dart" -o -name "*.openapi.dart" -o -name "*.gen.dart" -o -name "catalyst_voices_localizations*.dart" \))
FOR generated_file IN $(find . \( -name "*.g.dart" -o -name "*.freezed.dart" -o -name "*.chopper.dart" -o -name "*.swagger.dart" -o -name "*.openapi.dart" -o -name "*.gen.dart" -o -name "catalyst_voices_localizations*.dart" -o -name "cat_gateway_api.*.swagger.*" \))
SAVE ARTIFACT $generated_file AS LOCAL $generated_file
END
ELSE
SAVE ARTIFACT .
END
WORKDIR packages/internal/catalyst_voices_services
COPY catalyst-gateway+build/doc/cat-gateway-api.json openapi/cat-gateway-api.json

IF [ $filter_openapi = true ]
COPY +filter-openapi/filtered-openapi.json openapi/cat-gateway-api.json
ELSE
COPY catalyst-gateway+build/doc/cat-gateway-api.json openapi/cat-gateway-api.json
END

DO flutter-ci+OPENAPI_CODE_GEN \
--SAVE_LOCALLY=$save_locally \
--GEN_CODE_PATH=$gen_code_path \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"inverseTags": [
"Health",
"Legacy"
],
"operations": [
"*::/api/draft/*"
],
"unusedComponents": [
"schemas",
"parameters",
"examples",
"headers",
"requestBodies",
"responses"
]
}

0 comments on commit 31ad353

Please sign in to comment.