Skip to content

Commit 37af696

Browse files
committed
fix: Consume testing version of the source_gen branch to simplify testing.
1 parent 3dd7054 commit 37af696

13 files changed

+211
-209
lines changed

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

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

46
import 'package:crypto/crypto.dart';
57
import 'package:meta/meta.dart';
8+
import 'package:source_gen/source_gen.dart';
69

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

228231
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);
234232
}
235233

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

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

openapi-generator-annotations/pubspec.yaml

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

1415
dev_dependencies:
1516
test:
1617
source_gen_test:
1718
lint:
19+
20+
dependency_overrides:
21+
source_gen:
22+
git:
23+
ref: reviver
24+
url: git@github.com:Nexushunter/source_gen.git
25+
path: source_gen

openapi-generator-annotations/test/openapi_generator_annotations_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ void main() {
9191
expect(remote.path, 'http://localhost:8080/');
9292
expect(remote.headerDelegate, isA<RemoteSpecHeaderDelegate>());
9393
});
94+
9495
test('uses path', () {
9596
final remote = RemoteSpec(path: 'https://example.com/path');
9697
expect(remote.path, 'https://example.com/path');
@@ -112,7 +113,6 @@ void main() {
112113
accessKeyId: 'test',
113114
secretAccessKey: 'test',
114115
);
115-
116116
test('signs the url correctly', () {
117117
final now = DateTime.now();
118118
final actual = delegate.authHeaderContent(

openapi-generator/.gitignore

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

170170
# Generated test output
171171
test/specs/test-cached.json
172+
test/specs/commands-cache.json
172173
test/specs/localstack
173174
test/mocks.mocks.dart
Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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';
64
import 'package:source_gen/source_gen.dart' show ConstantReader, TypeChecker;
75

86
/// Extension adding the type methods to `ConstantReader`.
@@ -73,99 +71,3 @@ extension TypeMethods on ConstantReader {
7371
return values[enumIndex];
7472
}
7573
}
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)) {
148-
return v.mapValue.map((key, value) => MapEntry(
149-
convertToPropertyValue(key!), convertToPropertyValue(value!))) as T;
150-
} else if (isA(v, bool)) {
151-
return v.boolValue as T;
152-
} else if (isA(v, double)) {
153-
return v.doubleValue as T;
154-
} else if (isA(v, int)) {
155-
return v.intValue as T;
156-
} else if (isA(v, String)) {
157-
return v.stringValue as T;
158-
} else if (isA(v, Set)) {
159-
return v.setValue.map(convertToPropertyValue) as T;
160-
} else if (isA(v, List)) {
161-
return v.listValue.map(convertToPropertyValue) as T;
162-
} else if (isA(v, Enum)) {
163-
return v.enumValue();
164-
} else {
165-
return defaultValue;
166-
}
167-
}
168-
}
169-
170-
bool isA(ConstantReader? v, Type t) =>
171-
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) {

openapi-generator/lib/src/models/generator_arguments.dart

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import 'dart:async';
22
import 'dart:io';
33

44
import 'package:logging/logging.dart';
5-
import 'package:openapi_generator/src/extensions/type_methods.dart';
65
import 'package:openapi_generator/src/models/output_message.dart';
76
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';
8-
import 'package:source_gen/source_gen.dart' as src_gen;
97

108
import '../utils.dart';
119

@@ -74,6 +72,7 @@ class GeneratorArguments {
7472
/// Use the provided spec instead of one located in [Directory.current].
7573
///
7674
/// Default: openapi.(ya?ml) | openapi.json
75+
@Deprecated('Use inputSpec instead.')
7776
String _inputFile;
7877

7978
/// Provides an OAS spec file.
@@ -114,12 +113,12 @@ class GeneratorArguments {
114113
final InlineSchemaOptions? inlineSchemaOptions;
115114

116115
GeneratorArguments({
117-
required src_gen.ConstantReader annotations,
116+
required Openapi annotation,
118117
bool alwaysRun = false,
119-
String inputSpecFile = '',
118+
String? inputSpecFile,
120119
InputSpec inputSpec = const InputSpec.empty(),
121120
String templateDirectory = '',
122-
Generator generator = Generator.dart,
121+
Generator? generator,
123122
Map<String, String> typeMapping = const {},
124123
Map<String, String> importMapping = const {},
125124
Map<String, String> reservedWordsMapping = const {},
@@ -130,47 +129,39 @@ class GeneratorArguments {
130129
bool runSourceGen = true,
131130
String? outputDirectory,
132131
bool fetchDependencies = true,
133-
bool useNextGen = false,
132+
bool? useNextGen,
134133
String? cachePath,
135134
String? pubspecPath,
136135
bool isDebug = false,
137-
}) : alwaysRun = annotations.readPropertyOrDefault('alwaysRun', alwaysRun),
138-
_inputFile =
139-
annotations.readPropertyOrDefault('inputSpecFile', inputSpecFile),
140-
templateDirectory = annotations.readPropertyOrDefault(
141-
'templateDirectory', templateDirectory),
142-
generator =
143-
annotations.readPropertyOrDefault('generatorName', generator),
144-
typeMappings =
145-
annotations.readPropertyOrDefault('typeMappings', typeMapping),
146-
importMappings =
147-
annotations.readPropertyOrDefault('importMappings', importMapping),
148-
reservedWordsMappings = annotations.readPropertyOrDefault(
149-
'reservedWordsMappings', reservedWordsMapping),
150-
inlineSchemaNameMappings = annotations.readPropertyOrDefault(
151-
'inlineSchemaNameMappings', inlineSchemaNameMapping),
152-
additionalProperties = annotations.readPropertyOrDefault(
153-
'additionalProperties', additionalProperties),
154-
inlineSchemaOptions = annotations.readPropertyOrDefault(
155-
'inlineSchemaOptions', inlineSchemaOptions),
156-
skipValidation = annotations.readPropertyOrDefault(
157-
'skipSpecValidation', skipValidation),
158-
runSourceGen = annotations.readPropertyOrDefault(
159-
'runSourceGenOnOutput', runSourceGen),
160-
shouldFetchDependencies = annotations.readPropertyOrDefault(
161-
'fetchDependencies', fetchDependencies),
162-
outputDirectory = annotations.readPropertyOrDefault(
163-
'outputDirectory', outputDirectory ?? Directory.current.path),
164-
useNextGen =
165-
annotations.readPropertyOrDefault('useNextGen', useNextGen),
166-
cachePath = annotations.readPropertyOrDefault(
167-
'cachePath', cachePath ?? defaultCachedPath),
168-
pubspecPath = annotations.readPropertyOrDefault<String>(
169-
'projectPubspecPath',
136+
}) : alwaysRun = annotation.alwaysRun ?? alwaysRun,
137+
_inputFile = inputSpecFile ?? annotation.inputSpecFile,
138+
templateDirectory = annotation.templateDirectory ?? templateDirectory,
139+
generator = generator ?? annotation.generatorName,
140+
typeMappings = annotation.typeMappings ?? typeMapping,
141+
importMappings = annotation.importMappings ?? importMapping,
142+
reservedWordsMappings =
143+
annotation.reservedWordsMappings ?? reservedWordsMapping,
144+
inlineSchemaNameMappings =
145+
annotation.inlineSchemaNameMappings ?? inlineSchemaNameMapping,
146+
additionalProperties =
147+
additionalProperties ?? annotation.additionalProperties,
148+
inlineSchemaOptions = inlineSchemaOptions,
149+
// ?? annotations.readPropertyOrDefault(
150+
// 'inlineSchemaOptions', inlineSchemaOptions),
151+
skipValidation = annotation.skipSpecValidation ?? skipValidation,
152+
runSourceGen = annotation.runSourceGenOnOutput ?? runSourceGen,
153+
shouldFetchDependencies =
154+
annotation.fetchDependencies ?? fetchDependencies,
155+
outputDirectory = annotation.outputDirectory ??
156+
outputDirectory ??
157+
Directory.current.path,
158+
useNextGen = useNextGen ?? annotation.useNextGen,
159+
cachePath = cachePath ?? annotation.cachePath ?? defaultCachedPath,
160+
pubspecPath = annotation.projectPubspecPath ??
170161
pubspecPath ??
171-
'${Directory.current.path}${Platform.pathSeparator}pubspec.yaml'),
172-
isDebug = annotations.readPropertyOrDefault('debugLogging', isDebug),
173-
inputSpec = annotations.readPropertyOrDefault('inputSpec', inputSpec);
162+
'${Directory.current.path}${Platform.pathSeparator}pubspec.yaml',
163+
isDebug = annotation.debugLogging,
164+
inputSpec = annotation.inputSpec ?? inputSpec;
174165

175166
/// The stringified name of the [Generator].
176167
String get generatorName => generator == Generator.dart

openapi-generator/lib/src/openapi_generator_runner.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
4949
todo: 'Remove the [Openapi] annotation from `$friendlyName`.',
5050
);
5151
} else {
52-
if (!(annotations.read('useNextGen').literalValue as bool) &&
53-
annotations.read('cachePath').literalValue != null) {
52+
final apiAnnotation = Reviver(annotations) as annots.Openapi;
53+
54+
if (!apiAnnotation.useNextGen && apiAnnotation.cachePath != null) {
5455
throw AssertionError('useNextGen must be set when using cachePath');
5556
}
5657
try {
5758
// Transform the annotations.
58-
final args = GeneratorArguments(annotations: annotations);
59+
final args = GeneratorArguments(annotation: apiAnnotation);
5960
// Determine if the project has a dependency on the flutter sdk or not.
6061
final baseCommand = await runner.checkForFlutterEnvironemt(
6162
wrapper: args.wrapper, providedPubspecPath: args.pubspecPath)

openapi-generator/pubspec.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,12 @@ dev_dependencies:
2525
pedantic:
2626
coverage: ^1.6.3
2727
mockito:
28+
29+
dependency_overrides:
30+
openapi_generator_annotations:
31+
path: ../openapi-generator-annotations
32+
source_gen:
33+
git:
34+
ref: reviver
35+
url: git@github.com:Nexushunter/source_gen.git
36+
path: source_gen

0 commit comments

Comments
 (0)