Skip to content

Commit 0ccca8b

Browse files
authored
Revert "Refactor testing"
1 parent 45870e8 commit 0ccca8b

30 files changed

+1378
-1605
lines changed

.github/workflows/code_quality.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
steps:
2626
- name: Checkout
2727
uses: actions/checkout@v3
28+
- name: Start Docker compose containers
29+
if: ${{ matrix.work_dir == 'openapi-generator' }}
30+
run: docker-compose -f "docker-compose.yaml" up -d --build
2831
- name: Setup Dart
2932
uses: dart-lang/setup-dart@v1.5.0
3033
with:
@@ -33,9 +36,6 @@ jobs:
3336
run: dart pub get
3437
- name: Validate formatting
3538
run: dart format ./ --set-exit-if-changed
36-
- name: Generate Mocks
37-
if: ${{ matrix.work_dir == 'openapi-generator' }}
38-
run: dart run build_runner build --delete-conflicting-outputs
3939
- name: Run analyzer
4040
run: dart analyze --fatal-warnings
4141
- name: Run tests
@@ -51,6 +51,9 @@ jobs:
5151
verbose: true
5252
flags: ${{ matrix.work_dir }}
5353
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
54+
- name: Stop Docker Container
55+
if: ${{ matrix.work_dir == 'openapi-generator' && always() }}
56+
run: docker-compose -f "docker-compose.yaml" down
5457

5558
build:
5659
name: Build example project 🛠️

example/pubspec.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ dependency_overrides:
2727
path: ../openapi-generator
2828
openapi_generator_cli:
2929
path: ../openapi-generator-cli
30-
source_gen:
31-
git:
32-
ref: reviver
33-
url: https://github.com/Nexushunter/source_gen
34-
path: source_gen
30+
3531

3632
# Dependencies specify other packages that your package needs in order to work.
3733
# To automatically upgrade your package dependencies to the latest versions

openapi-generator-annotations/lib/src/openapi_generator_annotations_base.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
library openapi_generator_annotations;
2-
31
import 'dart:convert';
42
import 'dart:io';
53

64
import 'package:crypto/crypto.dart';
75
import 'package:meta/meta.dart';
8-
import 'package:source_gen/source_gen.dart';
96

107
/// Config base class
118
/// Your annotated class must extend this config class
@@ -229,6 +226,11 @@ class RemoteSpec extends InputSpec {
229226
const RemoteSpec.empty() : this(path: 'http://localhost:8080/');
230227

231228
Uri get url => Uri.parse(path);
229+
230+
RemoteSpec.fromMap(Map<String, dynamic> map)
231+
: headerDelegate =
232+
map['headerDelegate'] ?? const RemoteSpecHeaderDelegate(),
233+
super.fromMap(map);
232234
}
233235

234236
/// Default [RemoteSpecHeaderDelegate] used when retrieving a remote OAS spec.
@@ -264,6 +266,12 @@ class AWSRemoteSpecHeaderDelegate extends RemoteSpecHeaderDelegate {
264266
this.accessKeyId = null,
265267
}) : super();
266268

269+
AWSRemoteSpecHeaderDelegate.fromMap(Map<String, dynamic> map)
270+
: bucket = map['bucket'],
271+
accessKeyId = map['accessKeyId'],
272+
secretAccessKey = map['secretAccessKey'],
273+
super.fromMap(map);
274+
267275
/// Generates the [header] map used within the GET request.
268276
///
269277
/// Assumes that the user's auth AWS credentials

openapi-generator-annotations/pubspec.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,8 @@ environment:
1010
dependencies:
1111
crypto: '>=3.0.0 <4.0.0'
1212
meta: '>=1.3.0 <2.0.0'
13-
source_gen:
1413

1514
dev_dependencies:
1615
test:
1716
source_gen_test:
1817
lint:
19-
20-
dependency_overrides:
21-
source_gen:
22-
git:
23-
ref: reviver
24-
url: https://github.com/Nexushunter/source_gen.git
25-
path: source_gen

openapi-generator-annotations/test/openapi_generator_annotations_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ void main() {
9191
expect(remote.path, 'http://localhost:8080/');
9292
expect(remote.headerDelegate, isA<RemoteSpecHeaderDelegate>());
9393
});
94-
9594
test('uses path', () {
9695
final remote = RemoteSpec(path: 'https://example.com/path');
9796
expect(remote.path, 'https://example.com/path');
@@ -113,6 +112,7 @@ void main() {
113112
accessKeyId: 'test',
114113
secretAccessKey: 'test',
115114
);
115+
116116
test('signs the url correctly', () {
117117
final now = DateTime.now();
118118
final actual = delegate.authHeaderContent(
@@ -176,7 +176,6 @@ void main() {
176176
}
177177
});
178178
test('uses the provided environment', () async {
179-
print(Directory.current.path);
180179
final result = Process.runSync(
181180
'dart',
182181
[

openapi-generator/.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,4 @@ example/.dart_tool
169169

170170
# Generated test output
171171
test/specs/test-cached.json
172-
test/specs/commands-cache.json
173-
test/specs/localstack
174-
test/mocks.mocks.dart
172+
test/specs/localstack/**

openapi-generator/Makefile

Lines changed: 0 additions & 4 deletions
This file was deleted.

openapi-generator/docker-compose.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3'
2+
services:
3+
local-s3:
4+
container_name: localstack
5+
image: localstack/localstack:latest
6+
ports:
7+
- "4566:4566"
8+
environment:
9+
- SERVICES=S3
10+
- AWS_DEFAULT_REGION=us-east-1
11+
volumes:
12+
- './test/specs/localstack:/var/lib/localstack'
13+
- './test/specs/buckets.sh:/etc/localstack/init/ready.d/buckets.sh'

openapi-generator/lib/src/extensions/type_methods.dart

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'dart:mirrors';
22

33
import 'package:analyzer/dart/element/type.dart';
4+
import 'package:openapi_generator/src/utils.dart';
5+
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';
46
import 'package:source_gen/source_gen.dart' show ConstantReader, TypeChecker;
57

68
/// Extension adding the type methods to `ConstantReader`.
@@ -71,3 +73,100 @@ extension TypeMethods on ConstantReader {
7173
return values[enumIndex];
7274
}
7375
}
76+
77+
extension ReadProperty on ConstantReader {
78+
T readPropertyOrDefault<T>(String name, T defaultValue) {
79+
final v = peek(name);
80+
if (v == null) {
81+
return defaultValue;
82+
}
83+
84+
if (isA(v, InputSpec)) {
85+
final revived = v.revive();
86+
87+
if (isA(v, RemoteSpec)) {
88+
final map = revived.namedArguments;
89+
final delegate = map['headerDelegate'];
90+
final mapped = <String, dynamic>{
91+
'path': convertToPropertyValue(map['path']!),
92+
};
93+
if (delegate?.isNull ?? true) {
94+
return RemoteSpec.fromMap(mapped) as T;
95+
} else {
96+
final delegateReader = ConstantReader(delegate);
97+
if (isA(delegateReader, AWSRemoteSpecHeaderDelegate)) {
98+
mapped['headerDelegate'] = AWSRemoteSpecHeaderDelegate.fromMap(
99+
delegateReader.revive().namedArguments.map(
100+
(key, value) => MapEntry(
101+
key,
102+
convertToPropertyValue(value),
103+
),
104+
),
105+
);
106+
}
107+
return RemoteSpec.fromMap(mapped) as T;
108+
}
109+
} else {
110+
final map = revived.namedArguments.map(
111+
(key, value) => MapEntry(
112+
key,
113+
convertToPropertyValue(value),
114+
),
115+
);
116+
return InputSpec.fromMap(map) as T;
117+
}
118+
}
119+
120+
if (isA(v, AdditionalProperties)) {
121+
final map = v.revive().namedArguments.map(
122+
(key, value) => MapEntry(
123+
key,
124+
convertToPropertyValue(value),
125+
),
126+
);
127+
if (isA(v, DioProperties)) {
128+
return DioProperties.fromMap(map) as T;
129+
} else if (isA(v, DioAltProperties)) {
130+
return DioAltProperties.fromMap(map) as T;
131+
} else {
132+
return AdditionalProperties.fromMap(map) as T;
133+
}
134+
}
135+
136+
if (isA(v, InlineSchemaOptions)) {
137+
return InlineSchemaOptions.fromMap(
138+
v.revive().namedArguments.map(
139+
(key, value) => MapEntry(
140+
key,
141+
convertToPropertyValue(value),
142+
),
143+
),
144+
) as T;
145+
}
146+
147+
if (isA(v, Map<String, String>)) {
148+
return v.mapValue.map((key, value) => MapEntry(
149+
convertToPropertyValue(key!) as String,
150+
convertToPropertyValue(value!) as String)) as T;
151+
} else if (isA(v, bool)) {
152+
return v.boolValue as T;
153+
} else if (isA(v, double)) {
154+
return v.doubleValue as T;
155+
} else if (isA(v, int)) {
156+
return v.intValue as T;
157+
} else if (isA(v, String)) {
158+
return v.stringValue as T;
159+
} else if (isA(v, Set)) {
160+
return v.setValue.map(convertToPropertyValue) as T;
161+
} else if (isA(v, List)) {
162+
return v.listValue.map(convertToPropertyValue) as T;
163+
} else if (isA(v, Enum)) {
164+
return v.enumValue();
165+
} else {
166+
return defaultValue;
167+
}
168+
}
169+
}
170+
171+
bool isA(ConstantReader? v, Type t) =>
172+
v?.instanceOf(TypeChecker.fromRuntime(t)) ?? false;

openapi-generator/lib/src/gen_on_spec_changes.dart

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,23 @@ FutureOr<Map<String, dynamic>> loadSpec(
5959
}
6060
} else {
6161
Map<String, String>? headers;
62-
// if (specConfig.headerDelegate is AWSRemoteSpecHeaderDelegate) {
63-
// try {
64-
// headers = (specConfig.headerDelegate as AWSRemoteSpecHeaderDelegate)
65-
// .header(path: specConfig.url.path);
66-
// } catch (e, st) {
67-
// return Future.error(
68-
// OutputMessage(
69-
// message: 'failed to generate AWS headers',
70-
// additionalContext: e,
71-
// stackTrace: st,
72-
// level: Level.SEVERE,
73-
// ),
74-
// );
75-
// }
76-
// } else {
77-
// headers = specConfig.headerDelegate.header();
78-
// }
62+
if (specConfig.headerDelegate is AWSRemoteSpecHeaderDelegate) {
63+
try {
64+
headers = (specConfig.headerDelegate as AWSRemoteSpecHeaderDelegate)
65+
.header(path: specConfig.url.path);
66+
} catch (e, st) {
67+
return Future.error(
68+
OutputMessage(
69+
message: 'failed to generate AWS headers',
70+
additionalContext: e,
71+
stackTrace: st,
72+
level: Level.SEVERE,
73+
),
74+
);
75+
}
76+
} else {
77+
headers = specConfig.headerDelegate.header();
78+
}
7979

8080
final resp = await http.get(specConfig.url, headers: headers);
8181
if (resp.statusCode == 200) {

0 commit comments

Comments
 (0)