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

Add auto-generated tests and travis config to Dart clients #3006

Merged
merged 5 commits into from
May 27, 2019
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ samples/server/petstore/erlang-server/rebar.lock
samples/client/petstore/dart/petstore/packages
samples/client/petstore/dart/flutter_petstore/test/packages
samples/client/petstore/dart/petstore/test/packages
**/.dart_tool

# JS
samples/client/petstore/javascript/package-lock.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
protected String sourceFolder = "";
protected String apiDocPath = "docs" + File.separator;
protected String modelDocPath = "docs" + File.separator;
protected String apiTestPath = "test" + File.separator;
protected String modelTestPath = "test" + File.separator;

public DartClientCodegen() {
super();
Expand All @@ -66,6 +68,9 @@ public DartClientCodegen() {
modelDocTemplateFiles.put("object_doc.mustache", ".md");
apiDocTemplateFiles.put("api_doc.mustache", ".md");

modelTestTemplateFiles.put("model_test.mustache", ".dart");
apiTestTemplateFiles.put("api_test.mustache", ".dart");

setReservedWordsLowerCase(
Arrays.asList(
"abstract", "as", "assert", "async", "async*", "await",
Expand Down Expand Up @@ -214,6 +219,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml"));
}

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

@Override
public String apiTestFileFolder() {
return outputFolder + File.separator + apiTestPath.replace('/', File.separatorChar);
}

@Override
public String modelTestFileFolder() {
return outputFolder + File.separator + modelTestPath.replace('/', File.separatorChar);
}

@Override
public String apiDocFileFolder() {
return outputFolder + File.separator + apiDocPath.replace('/', File.separatorChar);
Expand Down Expand Up @@ -295,6 +311,16 @@ public String toApiFilename(String name) {
return underscore(toApiName(name));
}

@Override
public String toApiTestFilename(String name) {
return toApiFilename(name) + "_test";
}

@Override
public String toModelTestFilename(String name) {
return toModelFilename(name) + "_test";
}

@Override
public String toDefaultValue(Schema schema) {
if (ModelUtils.isMapSchema(schema)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml"));

final String authFolder = sourceFolder + File.separator + "lib" + File.separator + "auth";
supportingFiles.add(new SupportingFile("auth/api_key_auth.mustache", authFolder, "api_key_auth.dart"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:{{pubName}}/api.dart';
import 'package:test/test.dart';

{{#operations}}

/// tests for {{classname}}
void main() {
var instance = new {{classname}}();

group('tests for {{classname}}', () {
{{#operation}}
{{#summary}}
// {{{.}}}
//
{{/summary}}
{{#notes}}
// {{{.}}}
//
{{/notes}}
//{{#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
test('test {{operationId}}', () async {
// TODO
});

{{/operation}}
});
}
{{/operations}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{#models}}
{{#model}}
import 'package:{{pubName}}/api.dart';
import 'package:test/test.dart';

// tests for {{classname}}
void main() {
var instance = new Pet();
wing328 marked this conversation as resolved.
Show resolved Hide resolved

group('test {{classname}}', () {
{{#vars}}
{{#description}}
// {{{description}}}
{{/description}}
// {{{dataType}}} {{name}}{{#defaultValue}} (default value: {{{.}}}){{/defaultValue}}
test('to test the property `{{name}}`', () async {
// TODO
});

{{/vars}}

});

}
{{/model}}
{{/models}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://docs.travis-ci.com/user/languages/dart/
#
language: dart
dart:
# Install a specific stable release
- "1.24.3"
install:
- pub get

script:
- pub run test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:{{pubName}}/api.dart';
import 'package:test/test.dart';

{{#operations}}

/// tests for {{classname}}
void main() {
var instance = new {{classname}}();

group('tests for {{classname}}', () {
{{#operation}}
{{#summary}}
// {{{.}}}
//
{{/summary}}
{{#notes}}
// {{{.}}}
//
{{/notes}}
//{{#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
test('test {{operationId}}', () async {
// TODO
});

{{/operation}}
});
}
{{/operations}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{#models}}
{{#model}}
import 'package:{{pubName}}/api.dart';
import 'package:test/test.dart';

// tests for {{classname}}
void main() {
var instance = new Pet();

group('test {{classname}}', () {
{{#vars}}
{{#description}}
// {{{description}}}
{{/description}}
// {{{dataType}}} {{name}}{{#defaultValue}} (default value: {{{.}}}){{/defaultValue}}
test('to test the property `{{name}}`', () async {
// TODO
});

{{/vars}}

});

}
{{/model}}
{{/models}}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ version: {{pubVersion}}
description: {{pubDescription}}
dependencies:
http: '>=0.11.1 <0.13.0'
dev_dependencies:
test: ^1.3.0
11 changes: 11 additions & 0 deletions modules/openapi-generator/src/main/resources/dart/travis.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://docs.travis-ci.com/user/languages/dart/
#
language: dart
dart:
# Install a specific stable release
- "1.24.3"
install:
- pub get

script:
- pub run test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:{{pubName}}/api.dart';
import 'package:test/test.dart';

{{#operations}}

/// tests for {{classname}}
void main() {
var instance = new {{classname}}();

group('tests for {{classname}}', () {
{{#operation}}
{{#summary}}
// {{{.}}}
//
{{/summary}}
{{#notes}}
// {{{.}}}
//
{{/notes}}
//{{#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
test('test {{operationId}}', () async {
// TODO
});

{{/operation}}
});
}
{{/operations}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{#models}}
{{#model}}
import 'package:{{pubName}}/api.dart';
import 'package:test/test.dart';

// tests for {{classname}}
void main() {
var instance = new Pet();

group('test {{classname}}', () {
{{#vars}}
{{#description}}
// {{{description}}}
{{/description}}
// {{{dataType}}} {{name}}{{#defaultValue}} (default value: {{{.}}}){{/defaultValue}}
test('to test the property `{{name}}`', () async {
// TODO
});

{{/vars}}

});

}
{{/model}}
{{/models}}
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ environment:
sdk: '>=2.0.0 <3.0.0'
dependencies:
http: '>=0.11.1 <0.13.0'
dev_dependencies:
test: ^1.3.0
11 changes: 11 additions & 0 deletions modules/openapi-generator/src/main/resources/dart2/travis.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://docs.travis-ci.com/user/languages/dart/
#
language: dart
dart:
# Install a specific stable release
- "2.2.0"
install:
- pub get

script:
- pub run test
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.0-SNAPSHOT
4.0.1-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://docs.travis-ci.com/user/languages/dart/
#
language: dart
dart:
# Install a specific stable release
- "1.24.3"
install:
- pub get

script:
- pub run test
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is a sample server Petstore server. For this sample, you can use the api ke
This Dart package is automatically generated by the [Open API Codegen](https://github.com/OpenAPITools/openapi-generator) project:

- API version: 1.0.0
- Build date: 2019-03-01T12:01:27.554664+01:00[Europe/Paris]
- Build date: 2019-05-27T15:39:26.158+08:00[Asia/Hong_Kong]
- Build package: org.openapitools.codegen.languages.DartJaguarClientCodegen

## Requirements
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:openapi/api.dart';
import 'package:test/test.dart';

// tests for ApiResponse
void main() {
var instance = new Pet();

group('test ApiResponse', () {
// int code (default value: null)
test('to test the property `code`', () async {
// TODO
});

// String type (default value: null)
test('to test the property `type`', () async {
// TODO
});

// String message (default value: null)
test('to test the property `message`', () async {
// TODO
});


});

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:openapi/api.dart';
import 'package:test/test.dart';

// tests for Category
void main() {
var instance = new Pet();

group('test Category', () {
// int id (default value: null)
test('to test the property `id`', () async {
// TODO
});

// String name (default value: null)
test('to test the property `name`', () async {
// TODO
});


});

}
Loading