-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add and configure swagger_dart_code_generator. * feat: Add Earthly targets for code generation. * feat: Restore `catalyst_analysis` package in the pipeline for the code generation. * docs: Describe code generation process. * feat: Add generated models. * chore: Lint README. * chore: Spell check. * chore: Rename earthly targets based on CI style guide. * refactor: Move generated files in catalyst_voices_services. * refactor: Introduce `save_locally` arg to generate code locally. * docs: Update code generator documentation. --------- Co-authored-by: Oleksandr Prokhorenko <[email protected]>
- Loading branch information
Showing
12 changed files
with
2,073 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
catalyst_voices/packages/catalyst_voices_services/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,35 @@ | ||
# 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` is necessary only when running the command from a | ||
different platform. | ||
|
||
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 `+check-flutter-code-generator` generates the code on the CI and compares | ||
it with the code currently in repo, failing if there is an inconsistency. |
15 changes: 15 additions & 0 deletions
15
catalyst_voices/packages/catalyst_voices_services/build.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
targets: | ||
$default: | ||
sources: | ||
- lib/** | ||
- openapi/** | ||
- $package$ | ||
builders: | ||
chopper_generator: | ||
options: | ||
header: "// Generated code" | ||
swagger_dart_code_generator: | ||
options: | ||
input_folder: "openapi/" | ||
output_folder: "lib/generated/catalyst_gateway" | ||
separate_models: true |
68 changes: 68 additions & 0 deletions
68
...atalyst_voices_services/lib/generated/catalyst_gateway/cat_gateway_api.enums.swagger.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:collection/collection.dart'; | ||
|
||
enum Animals { | ||
@JsonValue(null) | ||
swaggerGeneratedUnknown(null), | ||
|
||
@JsonValue('Dogs') | ||
dogs('Dogs'), | ||
@JsonValue('Cats') | ||
cats('Cats'), | ||
@JsonValue('Rabbits') | ||
rabbits('Rabbits'); | ||
|
||
final String? value; | ||
|
||
const Animals(this.value); | ||
} | ||
|
||
enum Network { | ||
@JsonValue(null) | ||
swaggerGeneratedUnknown(null), | ||
|
||
@JsonValue('Mainnet') | ||
mainnet('Mainnet'), | ||
@JsonValue('Testnet') | ||
testnet('Testnet'), | ||
@JsonValue('Preprod') | ||
preprod('Preprod'), | ||
@JsonValue('Preview') | ||
preview('Preview'); | ||
|
||
final String? value; | ||
|
||
const Network(this.value); | ||
} | ||
|
||
enum ReasonRejected { | ||
@JsonValue(null) | ||
swaggerGeneratedUnknown(null), | ||
|
||
@JsonValue('FragmentAlreadyInLog') | ||
fragmentalreadyinlog('FragmentAlreadyInLog'), | ||
@JsonValue('FragmentInvalid') | ||
fragmentinvalid('FragmentInvalid'), | ||
@JsonValue('PreviousFragmentInvalid') | ||
previousfragmentinvalid('PreviousFragmentInvalid'), | ||
@JsonValue('PoolOverflow') | ||
pooloverflow('PoolOverflow'); | ||
|
||
final String? value; | ||
|
||
const ReasonRejected(this.value); | ||
} | ||
|
||
enum VoterGroupId { | ||
@JsonValue(null) | ||
swaggerGeneratedUnknown(null), | ||
|
||
@JsonValue('rep') | ||
rep('rep'), | ||
@JsonValue('direct') | ||
direct('direct'); | ||
|
||
final String? value; | ||
|
||
const VoterGroupId(this.value); | ||
} |
Oops, something went wrong.