Skip to content

Commit 6224377

Browse files
committed
test: added test for #115
closes #115
1 parent be60694 commit 6224377

File tree

4 files changed

+168
-0
lines changed

4 files changed

+168
-0
lines changed

openapi-generator/test/github_issues_test.dart

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,88 @@ void main() {
195195
},
196196
);
197197
});
198+
199+
group('#115', () {
200+
var issueNumber = '115';
201+
var parentFolder = path.join(testSpecPath, 'issue', issueNumber);
202+
var workingDirectory = path.join(parentFolder, 'output');
203+
setUpAll(
204+
() {
205+
var workingDirectory = path.join(parentFolder, 'output');
206+
cleanup(workingDirectory);
207+
},
208+
);
209+
test(
210+
'[dart] test that json parsing does not return wrong Set when uniqueItems is enabled',
211+
() async {
212+
var annotatedFile = File(
213+
'$parentFolder/github_issue_${issueNumber}_dart_test_config.dart');
214+
// var annotatedFileContents = annotatedFile.readAsStringSync();
215+
var inputSpecFile =
216+
File('$parentFolder/github_issue_#$issueNumber.json');
217+
218+
var generatedOutput = await generateForSource(
219+
annotatedFile.path,
220+
openapiSpecFilePath: inputSpecFile.path,
221+
preProcessor: (annotatedFileContent) =>
222+
annotatedFileContent.replaceAll('{{issueNumber}}', issueNumber),
223+
);
224+
225+
expect(generatedOutput,
226+
contains('Skipping source gen because generator does not need it.'),
227+
reason: generatedOutput);
228+
expect(generatedOutput, contains('Successfully formatted code.'),
229+
reason: generatedOutput);
230+
var analyzeResult = await Process.run(
231+
'dart',
232+
['analyze', '--fatal-warnings'],
233+
workingDirectory: workingDirectory,
234+
);
235+
expect(analyzeResult.exitCode, 0,
236+
reason: '${analyzeResult.stdout}\n\n${analyzeResult.stderr}');
237+
cleanup(workingDirectory);
238+
});
239+
240+
test(
241+
'[dio] test that json parsing does not return wrong Set when uniqueItems is enabled',
242+
() async {
243+
var annotatedFile = File(
244+
'$parentFolder/github_issue_${issueNumber}_dio_test_config.dart');
245+
// var annotatedFileContents = annotatedFile.readAsStringSync();
246+
var inputSpecFile =
247+
File('$parentFolder/github_issue_#$issueNumber.json');
248+
249+
var generatedOutput = await generateForSource(
250+
annotatedFile.path,
251+
openapiSpecFilePath: inputSpecFile.path,
252+
preProcessor: (annotatedFileContent) =>
253+
annotatedFileContent.replaceAll('{{issueNumber}}', issueNumber),
254+
);
255+
256+
expect(
257+
generatedOutput,
258+
contains(
259+
'pub run build_runner build --delete-conflicting-outputs'),
260+
reason: generatedOutput);
261+
expect(generatedOutput, contains('Successfully formatted code.'),
262+
reason: generatedOutput);
263+
var workingDirectory = path.join(parentFolder, 'output');
264+
await Process.run(
265+
'dart',
266+
['fix', '--apply'],
267+
workingDirectory: workingDirectory,
268+
);
269+
var analyzeResult = await Process.run(
270+
'dart',
271+
['analyze', '--no-fatal-warnings'],
272+
workingDirectory: workingDirectory,
273+
);
274+
expect(analyzeResult.exitCode, 0,
275+
reason: '${analyzeResult.stdout}\n\n ${analyzeResult.stderr}');
276+
cleanup(workingDirectory);
277+
},
278+
);
279+
});
198280
});
199281
}
200282

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "my-service",
5+
"version": "1.0"
6+
},
7+
"servers": [
8+
{
9+
"url": "/my-service"
10+
}
11+
],
12+
"security": [
13+
{
14+
"Authorization": []
15+
}
16+
],
17+
"paths": {
18+
"/api/v2/subscription/cancel": {
19+
"delete": {
20+
"tags": [
21+
"subscription-v-2-controller"
22+
],
23+
"operationId": "cancelSubscription_2",
24+
"responses": {
25+
"200": {
26+
"description": "OK"
27+
}
28+
}
29+
}
30+
}
31+
},
32+
"components": {
33+
"schemas": {
34+
"WechatPayRedirectToAndroidApp": {
35+
"type": "object",
36+
"properties": {
37+
"timestamp": {
38+
"type": "string"
39+
},
40+
"experts": {
41+
"uniqueItems": true,
42+
"type": "array",
43+
"items": {
44+
"type": "string"
45+
}
46+
},
47+
"package": {
48+
"type": "string"
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';
2+
3+
@Openapi(
4+
inputSpec: InputSpec(
5+
path:
6+
'./test/specs/issue/{{issueNumber}}/github_issue_#{{issueNumber}}.json',
7+
),
8+
updateAnnotatedFile: false,
9+
nameMappings: {'package_': 'otherPackage'},
10+
additionalProperties:
11+
AdditionalProperties(pubName: 'salad_api_client', pubAuthor: 'Google'),
12+
generatorName: Generator.dart,
13+
cleanSubOutputDirectory: ['./test/specs/issue/{{issueNumber}}/output'],
14+
cachePath: './test/specs/issue/{{issueNumber}}/output/cache.json',
15+
outputDirectory: './test/specs/issue/{{issueNumber}}/output')
16+
class GithubIssue135 {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';
2+
3+
@Openapi(
4+
inputSpec: InputSpec(
5+
path:
6+
'./test/specs/issue/{{issueNumber}}/github_issue_#{{issueNumber}}.json',
7+
),
8+
updateAnnotatedFile: false,
9+
nameMappings: {'package_': 'otherPackage'},
10+
additionalProperties:
11+
AdditionalProperties(pubName: 'salad_api_client', pubAuthor: 'Google'),
12+
generatorName: Generator.dio,
13+
cleanSubOutputDirectory: ['./test/specs/issue/{{issueNumber}}/output'],
14+
cachePath: './test/specs/issue/{{issueNumber}}/output/cache.json',
15+
outputDirectory: './test/specs/issue/{{issueNumber}}/output')
16+
class GithubIssue135 {}

0 commit comments

Comments
 (0)