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

feat(cat-voices): vit ss endpoints generating #1302

Open
wants to merge 4 commits into
base: mve3
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions catalyst_voices/melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ command:
asn1lib: ^1.5.3
bip39: ^1.0.6
bloc_concurrency: ^0.2.2
chopper: ^8.0.3
collection: ^1.18.0
cryptography: ^2.7.0
dotted_border: ^2.1.0
Expand Down Expand Up @@ -132,6 +133,7 @@ command:
dev_dependencies:
test: ^1.24.9
build_runner: ^2.4.12
chopper_generator: ^8.0.3
mocktail: ^1.0.1

scripts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
path: ../catalyst_voices_services
catalyst_voices_shared:
path: ../catalyst_voices_shared
chopper: ^7.2.0
chopper: ^8.0.3
flutter:
sdk: flutter
http: ^1.2.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ targets:
options:
input_folder: "openapi/"
output_folder: "lib/generated/catalyst_gateway"
separate_models: true
separate_models: true
overriden_models:
- file_name: "vitss-openapi"
import_url: "../../src/api_models/overriden_models.dart"
overriden_models:
- SimpleProposal$ProposalCategory
- SimpleProposal$Proposer
- CommunityChoiceProposal$ProposalCategory
- CommunityChoiceProposal$Proposer
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export 'cat_gateway_api.swagger.dart' show CatGatewayApi;
export 'vit.swagger.dart' show Vit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import 'package:catalyst_voices_services/generated/catalyst_gateway/vit.models.swagger.dart';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if vitss was not under catalyst)gateway because its not part of catalyst gateway.
Just so the distinction is clearer.
Perhaps in package:catalyst_voices_services/generated/vitss/* instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, wanted to do it too but swagger_dart_code_generator allows only one input_folder/output_folder folder.

I was thinking about renaming catalyst_gateway to api because later generated classes have descriptive names anyways.

so from

├── generated
│   └── catalyst_gateway
│       ├── cat_gateway_api.enums.swagger.dart
│       ├── cat_gateway_api.models.swagger.dart
│       ├── cat_gateway_api.models.swagger.g.dart
│       ├── cat_gateway_api.swagger.chopper.dart
│       ├── cat_gateway_api.swagger.dart
│       ├── client_index.dart
│       ├── client_mapping.dart
│       ├── vit.enums.swagger.dart
│       ├── vit.models.swagger.dart
│       ├── vit.models.swagger.g.dart
│       ├── vit.swagger.chopper.dart
│       └── vit.swagger.dart

to

├── generated
│   └── api
│       ├── cat_gateway_api.enums.swagger.dart
│       ├── cat_gateway_api.models.swagger.dart
│       ├── cat_gateway_api.models.swagger.g.dart
│       ├── cat_gateway_api.swagger.chopper.dart
│       ├── cat_gateway_api.swagger.dart
│       ├── client_index.dart
│       ├── client_mapping.dart
│       ├── vit.enums.swagger.dart
│       ├── vit.models.swagger.dart
│       ├── vit.models.swagger.g.dart
│       ├── vit.swagger.chopper.dart
│       └── vit.swagger.dart

does it make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe even rename cat_gateway_api to just cat_gateway


/// For some reason VitSS openapi spec does not play nice with generating
/// sub classes for Proposal while extending more then 2 level.
///
/// As temporary solution we're overriding not generated classes because
/// we're remove VitSS integration later.

// SimpleProposal

class SimpleProposal$ProposalCategory extends Proposal$ProposalCategory {
SimpleProposal$ProposalCategory({
super.categoryId,
super.categoryName,
super.categoryDescription,
});

factory SimpleProposal$ProposalCategory.fromJson(Map<String, dynamic> json) {
return Proposal$ProposalCategory.fromJson(json)._toSimple();
}
}

class SimpleProposal$Proposer extends Proposal$Proposer {
SimpleProposal$Proposer({
super.proposerName,
super.proposerEmail,
super.proposerUrl,
});

factory SimpleProposal$Proposer.fromJson(Map<String, dynamic> json) {
return Proposal$Proposer.fromJson(json)._toSimple();
}
}

// CommunityChoiceProposal

class CommunityChoiceProposal$ProposalCategory
extends Proposal$ProposalCategory {
CommunityChoiceProposal$ProposalCategory({
super.categoryId,
super.categoryName,
super.categoryDescription,
});

factory CommunityChoiceProposal$ProposalCategory.fromJson(
Map<String, dynamic> json,
) {
return Proposal$ProposalCategory.fromJson(json)._toCommunityChoice();
}
}

class CommunityChoiceProposal$Proposer extends Proposal$Proposer {
CommunityChoiceProposal$Proposer({
super.proposerName,
super.proposerEmail,
super.proposerUrl,
});

factory CommunityChoiceProposal$Proposer.fromJson(Map<String, dynamic> json) {
return Proposal$Proposer.fromJson(json)._toCommunityChoice();
}
}

// Private extension

extension _Proposal$ProposalCategoryExt on Proposal$ProposalCategory {
SimpleProposal$ProposalCategory _toSimple() {
return SimpleProposal$ProposalCategory(
categoryId: categoryId,
categoryName: categoryName,
categoryDescription: categoryDescription,
);
}

CommunityChoiceProposal$ProposalCategory _toCommunityChoice() {
return CommunityChoiceProposal$ProposalCategory(
categoryId: categoryId,
categoryName: categoryName,
categoryDescription: categoryDescription,
);
}
}

extension _Proposal$ProposerExt on Proposal$Proposer {
SimpleProposal$Proposer _toSimple() {
return SimpleProposal$Proposer(
proposerName: proposerName,
proposerEmail: proposerEmail,
proposerUrl: proposerUrl,
);
}

CommunityChoiceProposal$Proposer _toCommunityChoice() {
return CommunityChoiceProposal$Proposer(
proposerName: proposerName,
proposerEmail: proposerEmail,
proposerUrl: proposerUrl,
);
}
}
Loading
Loading