Skip to content

Commit 4156d9a

Browse files
committed
fix: Correct most of the tests while using the newest verison of the source gen changes
1 parent 37af696 commit 4156d9a

File tree

8 files changed

+34
-78
lines changed

8 files changed

+34
-78
lines changed

openapi-generator-annotations/test/openapi_generator_annotations_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ void main() {
176176
}
177177
});
178178
test('uses the provided environment', () async {
179+
print(Directory.current.path);
179180
final result = Process.runSync(
180181
'dart',
181182
[

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

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -114,44 +114,47 @@ class GeneratorArguments {
114114

115115
GeneratorArguments({
116116
required Openapi annotation,
117-
bool alwaysRun = false,
117+
bool? alwaysRun,
118118
String? inputSpecFile,
119-
InputSpec inputSpec = const InputSpec.empty(),
120-
String templateDirectory = '',
119+
InputSpec? inputSpec,
120+
String? templateDirectory,
121121
Generator? generator,
122-
Map<String, String> typeMapping = const {},
123-
Map<String, String> importMapping = const {},
124-
Map<String, String> reservedWordsMapping = const {},
125-
Map<String, String> inlineSchemaNameMapping = const {},
122+
Map<String, String>? typeMapping,
123+
Map<String, String>? importMapping,
124+
Map<String, String>? reservedWordsMapping,
125+
Map<String, String>? inlineSchemaNameMapping,
126126
AdditionalProperties? additionalProperties,
127127
InlineSchemaOptions? inlineSchemaOptions,
128-
bool skipValidation = false,
129-
bool runSourceGen = true,
128+
bool? skipValidation,
129+
bool? runSourceGen,
130130
String? outputDirectory,
131-
bool fetchDependencies = true,
131+
bool? fetchDependencies,
132132
bool? useNextGen,
133133
String? cachePath,
134134
String? pubspecPath,
135-
bool isDebug = false,
136-
}) : alwaysRun = annotation.alwaysRun ?? alwaysRun,
135+
bool? isDebug,
136+
}) : alwaysRun = alwaysRun ?? annotation.alwaysRun ?? true,
137137
_inputFile = inputSpecFile ?? annotation.inputSpecFile,
138-
templateDirectory = annotation.templateDirectory ?? templateDirectory,
138+
templateDirectory =
139+
templateDirectory ?? annotation.templateDirectory ?? '',
139140
generator = generator ?? annotation.generatorName,
140-
typeMappings = annotation.typeMappings ?? typeMapping,
141-
importMappings = annotation.importMappings ?? importMapping,
141+
typeMappings = typeMapping ?? annotation.typeMappings ?? {},
142+
importMappings = importMapping ?? annotation.importMappings ?? {},
142143
reservedWordsMappings =
143-
annotation.reservedWordsMappings ?? reservedWordsMapping,
144-
inlineSchemaNameMappings =
145-
annotation.inlineSchemaNameMappings ?? inlineSchemaNameMapping,
144+
reservedWordsMapping ?? annotation.reservedWordsMappings ?? {},
145+
inlineSchemaNameMappings = inlineSchemaNameMapping ??
146+
annotation.inlineSchemaNameMappings ??
147+
{},
146148
additionalProperties =
147149
additionalProperties ?? annotation.additionalProperties,
148150
inlineSchemaOptions = inlineSchemaOptions,
149151
// ?? annotations.readPropertyOrDefault(
150152
// 'inlineSchemaOptions', inlineSchemaOptions),
151-
skipValidation = annotation.skipSpecValidation ?? skipValidation,
152-
runSourceGen = annotation.runSourceGenOnOutput ?? runSourceGen,
153+
skipValidation =
154+
skipValidation ?? annotation.skipSpecValidation ?? false,
155+
runSourceGen = runSourceGen ?? annotation.runSourceGenOnOutput ?? true,
153156
shouldFetchDependencies =
154-
annotation.fetchDependencies ?? fetchDependencies,
157+
fetchDependencies ?? annotation.fetchDependencies ?? true,
155158
outputDirectory = annotation.outputDirectory ??
156159
outputDirectory ??
157160
Directory.current.path,
@@ -161,7 +164,7 @@ class GeneratorArguments {
161164
pubspecPath ??
162165
'${Directory.current.path}${Platform.pathSeparator}pubspec.yaml',
163166
isDebug = annotation.debugLogging,
164-
inputSpec = annotation.inputSpec ?? inputSpec;
167+
inputSpec = inputSpec ?? annotation.inputSpec ?? InputSpec.empty();
165168

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

openapi-generator/lib/src/openapi_generator_runner.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
4949
todo: 'Remove the [Openapi] annotation from `$friendlyName`.',
5050
);
5151
} else {
52-
final apiAnnotation = Reviver(annotations) as annots.Openapi;
52+
final apiAnnotation = Reviver(annotations).toInstance() as annots.Openapi;
5353

5454
if (!apiAnnotation.useNextGen && apiAnnotation.cachePath != null) {
5555
throw AssertionError('useNextGen must be set when using cachePath');

openapi-generator/test/generator_test.dart

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import 'utils.dart';
1818
void main() {
1919
group('OpenApiGenerator', () {
2020
group('NextGen', () {
21-
late MockConstantReader mockedAnnotations;
2221
late src_gen.ConstantReader defaultAnnotations;
2322
late Openapi annotation;
2423
late GeneratorArguments realArguments;
@@ -29,7 +28,6 @@ void main() {
2928
resetMockitoState();
3029
mockedArgs = MockGeneratorArguments();
3130
mockRunner = MockCommandRunner();
32-
mockedAnnotations = MockConstantReader();
3331
defaultAnnotations =
3432
await loadAnnoation('next_gen_builder_test_config.dart');
3533
annotation = src_gen.Reviver(defaultAnnotations).toInstance();
@@ -71,19 +69,11 @@ void main() {
7169

7270
test('throws AssertionError when useCache is set but useNextGen is not',
7371
() async {
74-
final mockedUseNextGen = MockConstantReader();
75-
when(mockedUseNextGen.literalValue).thenReturn(false);
76-
77-
final mockedUseCachePath = MockConstantReader();
78-
when(mockedUseCachePath.literalValue).thenReturn('something');
79-
80-
when(mockedAnnotations.read('useNextGen')).thenReturn(mockedUseNextGen);
81-
when(mockedAnnotations.read('cachePath'))
82-
.thenReturn(mockedUseCachePath);
83-
8472
try {
8573
await OpenapiGenerator().generateForAnnotatedElement(
86-
MockClassElement(), mockedAnnotations, MockBuildStep());
74+
MockClassElement(),
75+
await loadAnnoation('next_gen_builder_test_invalid_config.dart'),
76+
MockBuildStep());
8777
fail('Should throw when useNextGen is false and cache path is set.');
8878
} catch (e, _) {
8979
expect(e, isA<AssertionError>());
@@ -188,7 +178,8 @@ void main() {
188178
cachedSpec: anyNamed('cachedSpec'),
189179
loadedSpec: anyNamed('loadedSpec')))
190180
.thenAnswer((_) async => true);
191-
final args = GeneratorArguments(annotation: annotation);
181+
final args = GeneratorArguments(
182+
annotation: annotation, generator: Generator.dart);
192183
await OpenapiGenerator(logger: logger, runner: mockRunner)
193184
.generatorV2(
194185
args: args,

openapi-generator/test/mocks.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ import 'package:openapi_generator/src/models/command.dart';
77
import 'package:openapi_generator/src/models/generator_arguments.dart';
88
import 'package:openapi_generator/src/openapi_generator_runner.dart';
99
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';
10-
import 'package:source_gen/source_gen.dart';
1110

1211
@GenerateNiceMocks([
1312
MockSpec<OpenapiGenerator>(),
14-
MockSpec<ConstantReader>(),
1513
MockSpec<BuildStep>(),
1614
MockSpec<MethodElement>(),
1715
MockSpec<ClassElement>(),

openapi-generator/test/specs/next_gen_builder_local_test_config.dart

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

openapi-generator/test/specs/next_gen_builder_test_aws_config.dart

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

openapi-generator/test/specs/next_gen_builder_dio_alt_test_config.dart renamed to openapi-generator/test/specs/next_gen_builder_test_invalid_config.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import 'package:openapi_generator_annotations/openapi_generator_annotations.dart
99
path:
1010
'https://raw.githubusercontent.com/Nexushunter/tagmine-api/main/openapi.yaml',
1111
),
12-
generatorName: Generator.dioAlt,
13-
useNextGen: true,
12+
generatorName: Generator.dio,
13+
useNextGen: false,
1414
cachePath: './test/specs/output-nextgen/expected-args/cache.json',
1515
outputDirectory: './test/specs/output-nextgen/expected-args')
1616
class TestClassConfig {}

0 commit comments

Comments
 (0)