Skip to content

Commit

Permalink
Merge pull request #258 from go-generalize/tsuzu/remove-dart-warnings
Browse files Browse the repository at this point in the history
Remove warnings in dart client
  • Loading branch information
54m authored Jan 13, 2022
2 parents db3fa6e + fa911a1 commit 5dc56e3
Show file tree
Hide file tree
Showing 19 changed files with 282 additions and 271 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
require (
github.com/go-generalize/go-dartfmt v0.1.0
github.com/go-generalize/go-easyparser v0.2.0
github.com/go-generalize/go2dart v0.4.6
github.com/go-generalize/go2dart v0.4.7
github.com/swaggo/swag v1.7.8
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ github.com/go-generalize/go-easyparser v0.2.0 h1:BAkuf9qkgIX1rm2nMVT3HiXO787Tnja
github.com/go-generalize/go-easyparser v0.2.0/go.mod h1:I+Ifnjzw7UNzxkENknQQY9yB2gsz9RekzAbKLYq/Dzw=
github.com/go-generalize/go2dart v0.4.6 h1:YarRucKM1thDBXcf8OJjOtferGzlFaqo0QUNo6oE7Sk=
github.com/go-generalize/go2dart v0.4.6/go.mod h1:qCKIC028FFZnNDSjs3brBSuC6VoiRACdpO2erlYVg0k=
github.com/go-generalize/go2dart v0.4.7 h1:vBSSVrQRzHWs5KFzw6LwWDT5p/ZRzLumz+S40d9ijI0=
github.com/go-generalize/go2dart v0.4.7/go.mod h1:qCKIC028FFZnNDSjs3brBSuC6VoiRACdpO2erlYVg0k=
github.com/go-generalize/go2go v0.0.0-20210311170338-9701de42e3ad h1:9oYY/ZcAf3VVRhxaxolqoTVprrx9A7N8INWAfWCRwBc=
github.com/go-generalize/go2go v0.0.0-20210311170338-9701de42e3ad/go.mod h1:YCmZm0ss4r71rT/Q6AgK4vre4tSFfJ1W/eDHWsmnLCc=
github.com/go-generalize/go2ts v1.0.5-0.20210311100632-95c274e947f1/go.mod h1:075q+zcpc6IjwYy9WpJpY+M9ssbEA6uccjzWwr59t3M=
Expand Down
6 changes: 4 additions & 2 deletions pkg/client/dart/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ func (g *generator) generateGroup(gr *parser.Group) childrenType {
client.Children = append(client.Children, g.generateGroup(child))
}

// Update global variables
g.Imports = append(g.Imports, it)
if len(client.Methods) != 0 {
// Update global variables
g.Imports = append(g.Imports, it)
}

if gr.GetParent() == nil {
g.clientType = client
Expand Down
20 changes: 10 additions & 10 deletions pkg/client/dart/templates/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class {{ $elem.Name }} {
this.baseURL,
this.headers,
this.client,
) {
){{ if .Children }} {
{{- range $index, $elem := .Children }}
this.{{ $elem.Name }} = {{ $elem.ClassName }}(
this.baseURL,
this.headers,
this.client,
{{ $elem.Name }} = {{ $elem.ClassName }}(
baseURL,
headers,
client,
);
{{- end }}
}
}{{ else }};{{ end }}

Map<String, dynamic> getRequestObject(Map<String, dynamic> obj, List<String> routingPath) {
final copied = {...obj};
Expand All @@ -52,7 +52,7 @@ class {{ $elem.Name }} {
) async {
client = client ?? this.client;

List<String> excludeParams = [{{ range $param := $method.URLParams }}'{{ $param }}', {{ end }}];
final excludeParams = <String>[{{ range $param := $method.URLParams }}'{{ $param }}', {{ end }}];

headers = {...this.headers, ...headers ?? {}};

Expand Down Expand Up @@ -128,8 +128,8 @@ class APIClient {
this.headers['Content-Type'] = 'application/json';
{{- range $index, $elem := .Children }}

this.{{ $elem.Name }} = {{ $elem.ClassName }}(
this.baseURL,
{{ $elem.Name }} = {{ $elem.ClassName }}(
baseURL,
this.headers,
this.client,
);
Expand All @@ -156,7 +156,7 @@ class APIClient {
) async {
client = client ?? this.client;

List<String> excludeParams = [{{ range $param := $method.URLParams }}'{{ $param }}', {{ end }}];
final excludeParams = <String>[{{ range $param := $method.URLParams }}'{{ $param }}', {{ end }}];

headers = {...this.headers, ...headers ?? {}};

Expand Down
18 changes: 8 additions & 10 deletions samples/empty_root/clients/dart/api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import './classes/foo/bar/types.dart' as types__foo_bar;
import './classes/foo/types.dart' as types__foo;
import './classes/types.dart' as types_;

class FooBarClient {
Map<String, String> headers = {};
Expand All @@ -16,7 +14,7 @@ class FooBarClient {
this.baseURL,
this.headers,
this.client,
) {}
);

Map<String, dynamic> getRequestObject(
Map<String, dynamic> obj, List<String> routingPath) {
Expand All @@ -34,7 +32,7 @@ class FooBarClient {
Object? mockOption}) async {
client = client ?? this.client;

List<String> excludeParams = [];
final excludeParams = <String>[];

headers = {...this.headers, ...headers ?? {}};

Expand Down Expand Up @@ -69,10 +67,10 @@ class FooClient {
this.headers,
this.client,
) {
this.bar = FooBarClient(
this.baseURL,
this.headers,
this.client,
bar = FooBarClient(
baseURL,
headers,
client,
);
}

Expand Down Expand Up @@ -111,8 +109,8 @@ class APIClient {

this.headers['Content-Type'] = 'application/json';

this.foo = FooClient(
this.baseURL,
foo = FooClient(
baseURL,
this.headers,
this.client,
);
Expand Down
2 changes: 1 addition & 1 deletion samples/empty_root/clients/dart/classes/foo/bar/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ListConverter<T, Base> implements JsonConverter<List<T>, List<Base>> {

@override
List<Base> toJson(List<T> arr) {
return arr.map((e) => internalConverter.toJson(e) as Base).toList();
return arr.map((e) => internalConverter.toJson(e)).toList();
}
}

Expand Down
2 changes: 1 addition & 1 deletion samples/empty_root/clients/dart/classes/foo/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ListConverter<T, Base> implements JsonConverter<List<T>, List<Base>> {

@override
List<Base> toJson(List<T> arr) {
return arr.map((e) => internalConverter.toJson(e) as Base).toList();
return arr.map((e) => internalConverter.toJson(e)).toList();
}
}

Expand Down
2 changes: 1 addition & 1 deletion samples/empty_root/clients/dart/classes/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ListConverter<T, Base> implements JsonConverter<List<T>, List<Base>> {

@override
List<Base> toJson(List<T> arr) {
return arr.map((e) => internalConverter.toJson(e) as Base).toList();
return arr.map((e) => internalConverter.toJson(e)).toList();
}
}

Expand Down
Loading

0 comments on commit 5dc56e3

Please sign in to comment.