Skip to content

Commit

Permalink
test: added test for #115
Browse files Browse the repository at this point in the history
closes #115
  • Loading branch information
gibahjoe committed Nov 5, 2024
1 parent be60694 commit 6224377
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 0 deletions.
82 changes: 82 additions & 0 deletions openapi-generator/test/github_issues_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,88 @@ void main() {
},
);
});

group('#115', () {
var issueNumber = '115';
var parentFolder = path.join(testSpecPath, 'issue', issueNumber);
var workingDirectory = path.join(parentFolder, 'output');
setUpAll(
() {
var workingDirectory = path.join(parentFolder, 'output');
cleanup(workingDirectory);
},
);
test(
'[dart] test that json parsing does not return wrong Set when uniqueItems is enabled',
() async {
var annotatedFile = File(
'$parentFolder/github_issue_${issueNumber}_dart_test_config.dart');
// var annotatedFileContents = annotatedFile.readAsStringSync();
var inputSpecFile =
File('$parentFolder/github_issue_#$issueNumber.json');

var generatedOutput = await generateForSource(
annotatedFile.path,
openapiSpecFilePath: inputSpecFile.path,
preProcessor: (annotatedFileContent) =>
annotatedFileContent.replaceAll('{{issueNumber}}', issueNumber),
);

expect(generatedOutput,
contains('Skipping source gen because generator does not need it.'),
reason: generatedOutput);
expect(generatedOutput, contains('Successfully formatted code.'),
reason: generatedOutput);
var analyzeResult = await Process.run(
'dart',
['analyze', '--fatal-warnings'],
workingDirectory: workingDirectory,
);
expect(analyzeResult.exitCode, 0,
reason: '${analyzeResult.stdout}\n\n${analyzeResult.stderr}');
cleanup(workingDirectory);
});

test(
'[dio] test that json parsing does not return wrong Set when uniqueItems is enabled',
() async {
var annotatedFile = File(
'$parentFolder/github_issue_${issueNumber}_dio_test_config.dart');
// var annotatedFileContents = annotatedFile.readAsStringSync();
var inputSpecFile =
File('$parentFolder/github_issue_#$issueNumber.json');

var generatedOutput = await generateForSource(
annotatedFile.path,
openapiSpecFilePath: inputSpecFile.path,
preProcessor: (annotatedFileContent) =>
annotatedFileContent.replaceAll('{{issueNumber}}', issueNumber),
);

expect(
generatedOutput,
contains(
'pub run build_runner build --delete-conflicting-outputs'),
reason: generatedOutput);
expect(generatedOutput, contains('Successfully formatted code.'),
reason: generatedOutput);
var workingDirectory = path.join(parentFolder, 'output');
await Process.run(
'dart',
['fix', '--apply'],
workingDirectory: workingDirectory,
);
var analyzeResult = await Process.run(
'dart',
['analyze', '--no-fatal-warnings'],
workingDirectory: workingDirectory,
);
expect(analyzeResult.exitCode, 0,
reason: '${analyzeResult.stdout}\n\n ${analyzeResult.stderr}');
cleanup(workingDirectory);
},
);
});
});
}

Expand Down
54 changes: 54 additions & 0 deletions openapi-generator/test/specs/issue/115/github_issue_#115.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"openapi": "3.0.1",
"info": {
"title": "my-service",
"version": "1.0"
},
"servers": [
{
"url": "/my-service"
}
],
"security": [
{
"Authorization": []
}
],
"paths": {
"/api/v2/subscription/cancel": {
"delete": {
"tags": [
"subscription-v-2-controller"
],
"operationId": "cancelSubscription_2",
"responses": {
"200": {
"description": "OK"
}
}
}
}
},
"components": {
"schemas": {
"WechatPayRedirectToAndroidApp": {
"type": "object",
"properties": {
"timestamp": {
"type": "string"
},
"experts": {
"uniqueItems": true,
"type": "array",
"items": {
"type": "string"
}
},
"package": {
"type": "string"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';

@Openapi(
inputSpec: InputSpec(
path:
'./test/specs/issue/{{issueNumber}}/github_issue_#{{issueNumber}}.json',
),
updateAnnotatedFile: false,
nameMappings: {'package_': 'otherPackage'},
additionalProperties:
AdditionalProperties(pubName: 'salad_api_client', pubAuthor: 'Google'),
generatorName: Generator.dart,
cleanSubOutputDirectory: ['./test/specs/issue/{{issueNumber}}/output'],
cachePath: './test/specs/issue/{{issueNumber}}/output/cache.json',
outputDirectory: './test/specs/issue/{{issueNumber}}/output')
class GithubIssue135 {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';

@Openapi(
inputSpec: InputSpec(
path:
'./test/specs/issue/{{issueNumber}}/github_issue_#{{issueNumber}}.json',
),
updateAnnotatedFile: false,
nameMappings: {'package_': 'otherPackage'},
additionalProperties:
AdditionalProperties(pubName: 'salad_api_client', pubAuthor: 'Google'),
generatorName: Generator.dio,
cleanSubOutputDirectory: ['./test/specs/issue/{{issueNumber}}/output'],
cachePath: './test/specs/issue/{{issueNumber}}/output/cache.json',
outputDirectory: './test/specs/issue/{{issueNumber}}/output')
class GithubIssue135 {}

0 comments on commit 6224377

Please sign in to comment.