Skip to content

Commit b88b1d6

Browse files
authored
Add auto-generated tests and travis config to Dart clients (#3006)
* add auto-generated tests and travis config for dart * improve tests * fix tests * add test, travis files to dart jaguar generator
1 parent 5c6824f commit b88b1d6

136 files changed

Lines changed: 4388 additions & 17 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ samples/server/petstore/erlang-server/rebar.lock
221221
samples/client/petstore/dart/petstore/packages
222222
samples/client/petstore/dart/flutter_petstore/test/packages
223223
samples/client/petstore/dart/petstore/test/packages
224+
**/.dart_tool
224225

225226
# JS
226227
samples/client/petstore/javascript/package-lock.json

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
4949
protected String sourceFolder = "";
5050
protected String apiDocPath = "docs" + File.separator;
5151
protected String modelDocPath = "docs" + File.separator;
52+
protected String apiTestPath = "test" + File.separator;
53+
protected String modelTestPath = "test" + File.separator;
5254

5355
public DartClientCodegen() {
5456
super();
@@ -66,6 +68,9 @@ public DartClientCodegen() {
6668
modelDocTemplateFiles.put("object_doc.mustache", ".md");
6769
apiDocTemplateFiles.put("api_doc.mustache", ".md");
6870

71+
modelTestTemplateFiles.put("model_test.mustache", ".dart");
72+
apiTestTemplateFiles.put("api_test.mustache", ".dart");
73+
6974
setReservedWordsLowerCase(
7075
Arrays.asList(
7176
"abstract", "as", "assert", "async", "async*", "await",
@@ -214,6 +219,7 @@ public void processOpts() {
214219
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
215220
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
216221
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
222+
supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml"));
217223
}
218224

219225
@Override
@@ -231,6 +237,16 @@ public String modelFileFolder() {
231237
return outputFolder + File.separator + sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar);
232238
}
233239

240+
@Override
241+
public String apiTestFileFolder() {
242+
return outputFolder + File.separator + apiTestPath.replace('/', File.separatorChar);
243+
}
244+
245+
@Override
246+
public String modelTestFileFolder() {
247+
return outputFolder + File.separator + modelTestPath.replace('/', File.separatorChar);
248+
}
249+
234250
@Override
235251
public String apiDocFileFolder() {
236252
return outputFolder + File.separator + apiDocPath.replace('/', File.separatorChar);
@@ -295,6 +311,16 @@ public String toApiFilename(String name) {
295311
return underscore(toApiName(name));
296312
}
297313

314+
@Override
315+
public String toApiTestFilename(String name) {
316+
return toApiFilename(name) + "_test";
317+
}
318+
319+
@Override
320+
public String toModelTestFilename(String name) {
321+
return toModelFilename(name) + "_test";
322+
}
323+
298324
@Override
299325
public String toDefaultValue(Schema schema) {
300326
if (ModelUtils.isMapSchema(schema)) {

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public void processOpts() {
177177
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
178178
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
179179
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
180+
supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml"));
180181

181182
final String authFolder = sourceFolder + File.separator + "lib" + File.separator + "auth";
182183
supportingFiles.add(new SupportingFile("auth/api_key_auth.mustache", authFolder, "api_key_auth.dart"));
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'package:{{pubName}}/api.dart';
2+
import 'package:test/test.dart';
3+
4+
{{#operations}}
5+
6+
/// tests for {{classname}}
7+
void main() {
8+
var instance = new {{classname}}();
9+
10+
group('tests for {{classname}}', () {
11+
{{#operation}}
12+
{{#summary}}
13+
// {{{.}}}
14+
//
15+
{{/summary}}
16+
{{#notes}}
17+
// {{{.}}}
18+
//
19+
{{/notes}}
20+
//{{#returnType}}Future<{{{returnType}}}> {{/returnType}}{{^returnType}}Future {{/returnType}}{{operationId}}({{#allParams}}{{#required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}} }{{/hasOptionalParams}}) async
21+
test('test {{operationId}}', () async {
22+
// TODO
23+
});
24+
25+
{{/operation}}
26+
});
27+
}
28+
{{/operations}}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{{#models}}
2+
{{#model}}
3+
import 'package:{{pubName}}/api.dart';
4+
import 'package:test/test.dart';
5+
6+
// tests for {{classname}}
7+
void main() {
8+
var instance = new Pet();
9+
10+
group('test {{classname}}', () {
11+
{{#vars}}
12+
{{#description}}
13+
// {{{description}}}
14+
{{/description}}
15+
// {{{dataType}}} {{name}}{{#defaultValue}} (default value: {{{.}}}){{/defaultValue}}
16+
test('to test the property `{{name}}`', () async {
17+
// TODO
18+
});
19+
20+
{{/vars}}
21+
22+
});
23+
24+
}
25+
{{/model}}
26+
{{/models}}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# https://docs.travis-ci.com/user/languages/dart/
2+
#
3+
language: dart
4+
dart:
5+
# Install a specific stable release
6+
- "1.24.3"
7+
install:
8+
- pub get
9+
10+
script:
11+
- pub run test
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'package:{{pubName}}/api.dart';
2+
import 'package:test/test.dart';
3+
4+
{{#operations}}
5+
6+
/// tests for {{classname}}
7+
void main() {
8+
var instance = new {{classname}}();
9+
10+
group('tests for {{classname}}', () {
11+
{{#operation}}
12+
{{#summary}}
13+
// {{{.}}}
14+
//
15+
{{/summary}}
16+
{{#notes}}
17+
// {{{.}}}
18+
//
19+
{{/notes}}
20+
//{{#returnType}}Future<{{{returnType}}}> {{/returnType}}{{^returnType}}Future {{/returnType}}{{operationId}}({{#allParams}}{{#required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}} }{{/hasOptionalParams}}) async
21+
test('test {{operationId}}', () async {
22+
// TODO
23+
});
24+
25+
{{/operation}}
26+
});
27+
}
28+
{{/operations}}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{{#models}}
2+
{{#model}}
3+
import 'package:{{pubName}}/api.dart';
4+
import 'package:test/test.dart';
5+
6+
// tests for {{classname}}
7+
void main() {
8+
var instance = new Pet();
9+
10+
group('test {{classname}}', () {
11+
{{#vars}}
12+
{{#description}}
13+
// {{{description}}}
14+
{{/description}}
15+
// {{{dataType}}} {{name}}{{#defaultValue}} (default value: {{{.}}}){{/defaultValue}}
16+
test('to test the property `{{name}}`', () async {
17+
// TODO
18+
});
19+
20+
{{/vars}}
21+
22+
});
23+
24+
}
25+
{{/model}}
26+
{{/models}}

modules/openapi-generator/src/main/resources/dart/pubspec.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ version: {{pubVersion}}
33
description: {{pubDescription}}
44
dependencies:
55
http: '>=0.11.1 <0.13.0'
6+
dev_dependencies:
7+
test: ^1.3.0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# https://docs.travis-ci.com/user/languages/dart/
2+
#
3+
language: dart
4+
dart:
5+
# Install a specific stable release
6+
- "1.24.3"
7+
install:
8+
- pub get
9+
10+
script:
11+
- pub run test

0 commit comments

Comments
 (0)