@@ -153,50 +153,155 @@ void main() {
153
153
),
154
154
);
155
155
});
156
- test ('uses config' , () async {
157
- final config = File (
158
- '${Directory .current .path }${Platform .pathSeparator }test${Platform .pathSeparator }specs${Platform .pathSeparator }test_config.dart' )
159
- .readAsStringSync ();
160
- final annotations = (await resolveSource (
161
- config,
162
- (resolver) async =>
163
- (await resolver.findLibraryByName ('test_lib' ))! ))
164
- .getClass ('TestClassConfig' )!
165
- .metadata
166
- .map ((e) => src_gen.ConstantReader (e.computeConstantValue ()! ))
167
- .first;
168
- final args = GeneratorArguments (annotations: annotations);
169
- expect (args.alwaysRun, isTrue);
170
- expect (args.useNextGen, isTrue);
171
- expect (args.cachePath, './test/specs/output/cache.json' );
172
- expect (args.outputDirectory, './test/specs/output' );
173
- expect (args.runSourceGen, isTrue);
174
- expect (args.shouldFetchDependencies, isTrue);
175
- expect (args.skipValidation, isFalse);
176
- expect (await args.inputFileOrFetch, './test/specs/openapi.test.yaml' );
177
- expect (args.templateDirectory, 'template' );
178
- expect (args.generator, Generator .dio);
179
- expect (args.wrapper, Wrapper .fvm);
180
- expect (args.importMappings, {'package' : 'test' });
181
- expect (args.typeMappings, {'key' : 'value' });
182
- expect (args.reservedWordsMappings, {'const' : 'final' });
183
- expect (args.inlineSchemaNameMappings, {'200resp' : 'OkResp' });
184
- expect (args.pubspecPath, './test/specs/dart_pubspec.test.yaml' );
185
- expect (args.isRemote, isFalse);
186
- expect (args.generatorName, 'dart-dio' );
187
- expect (args.shouldGenerateSources, isTrue);
188
- expect (await args.jarArgs, [
189
- 'generate' ,
190
- '-o=${args .outputDirectory }' ,
191
- '-i=${await args .inputFileOrFetch }' ,
192
- '-t=${args .templateDirectory }' ,
193
- '-g=${args .generatorName }' ,
194
- '--reserved-words-mappings=${args .reservedWordsMappings .entries .fold ('' , foldStringMap ())}' ,
195
- '--inline-schema-name-mappings=${args .inlineSchemaNameMappings .entries .fold ('' , foldStringMap ())}' ,
196
- '--import-mappings=${args .importMappings .entries .fold ('' , foldStringMap ())}' ,
197
- '--type-mappings=${args .typeMappings .entries .fold ('' , foldStringMap ())}' ,
198
- '--additional-properties=${args .additionalProperties !.toMap ().entries .fold ('' , foldStringMap (keyModifier : convertToPropertyKey ))}'
199
- ]);
156
+ group ('annotation specification' , () {
157
+ // https://github.com/gibahjoe/openapi-generator-dart/issues/110
158
+ test ('Processes annotations correctly' , () async {
159
+ final config = File (
160
+ '${Directory .current .path }${Platform .pathSeparator }test${Platform .pathSeparator }specs${Platform .pathSeparator }test_config.dart' )
161
+ .readAsStringSync ();
162
+ final annotations = (await resolveSource (
163
+ config,
164
+ (resolver) async =>
165
+ (await resolver.findLibraryByName ('test_lib' ))! ))
166
+ .getClass ('TestClassConfig' )!
167
+ .metadata
168
+ .map ((e) => src_gen.ConstantReader (e.computeConstantValue ()! ))
169
+ .first;
170
+ final args = GeneratorArguments (annotations: annotations);
171
+ expect (args.alwaysRun, isTrue);
172
+ expect (args.useNextGen, isTrue);
173
+ expect (args.cachePath, './test/specs/output/cache.json' );
174
+ expect (args.outputDirectory, './test/specs/output' );
175
+ expect (args.runSourceGen, isTrue);
176
+ expect (args.shouldFetchDependencies, isTrue);
177
+ expect (args.skipValidation, isFalse);
178
+ expect (await args.inputFileOrFetch, './test/specs/openapi.test.yaml' );
179
+ expect (args.templateDirectory, 'template' );
180
+ expect (args.generator, Generator .dio);
181
+ expect (args.wrapper, Wrapper .fvm);
182
+ expect (args.importMappings, {'package' : 'test' });
183
+ expect (args.typeMappings, {'key' : 'value' });
184
+ expect (args.reservedWordsMappings, {'const' : 'final' });
185
+ expect (args.inlineSchemaNameMappings, {'200resp' : 'OkResp' });
186
+ expect (args.pubspecPath, './test/specs/dart_pubspec.test.yaml' );
187
+ expect (args.isRemote, isFalse);
188
+ expect (args.generatorName, 'dart-dio' );
189
+ expect (args.shouldGenerateSources, isTrue);
190
+ expect (args.additionalProperties? .useEnumExtension, isTrue);
191
+ expect (args.additionalProperties? .pubAuthor, 'test author' );
192
+ expect (await args.jarArgs, [
193
+ 'generate' ,
194
+ '-o=${args .outputDirectory }' ,
195
+ '-i=${await args .inputFileOrFetch }' ,
196
+ '-t=${args .templateDirectory }' ,
197
+ '-g=${args .generatorName }' ,
198
+ '--reserved-words-mappings=${args .reservedWordsMappings .entries .fold ('' , foldStringMap ())}' ,
199
+ '--inline-schema-name-mappings=${args .inlineSchemaNameMappings .entries .fold ('' , foldStringMap ())}' ,
200
+ '--import-mappings=${args .importMappings .entries .fold ('' , foldStringMap ())}' ,
201
+ '--type-mappings=${args .typeMappings .entries .fold ('' , foldStringMap ())}' ,
202
+ '--additional-properties=${args .additionalProperties !.toMap ().entries .fold ('' , foldStringMap (keyModifier : convertToPropertyKey ))}'
203
+ ]);
204
+ });
205
+ test ('Processes annotation with DioProperties correctly' , () async {
206
+ final config = File (
207
+ '${Directory .current .path }${Platform .pathSeparator }test${Platform .pathSeparator }specs${Platform .pathSeparator }dio_properties_test_config.dart' )
208
+ .readAsStringSync ();
209
+ final annotations = (await resolveSource (
210
+ config,
211
+ (resolver) async =>
212
+ (await resolver.findLibraryByName ('test_lib' ))! ))
213
+ .getClass ('DioPropertiesTestConfig' )!
214
+ .metadata
215
+ .map ((e) => src_gen.ConstantReader (e.computeConstantValue ()! ))
216
+ .first;
217
+ final args = GeneratorArguments (annotations: annotations);
218
+ expect (args.alwaysRun, isTrue);
219
+ expect (args.useNextGen, isTrue);
220
+ expect (args.cachePath, './test/specs/output/cache.json' );
221
+ expect (args.outputDirectory, './test/specs/output' );
222
+ expect (args.runSourceGen, isTrue);
223
+ expect (args.shouldFetchDependencies, isTrue);
224
+ expect (args.skipValidation, isFalse);
225
+ expect (await args.inputFileOrFetch, './test/specs/openapi.test.yaml' );
226
+ expect (args.templateDirectory, 'template' );
227
+ expect (args.generator, Generator .dio);
228
+ expect (args.wrapper, Wrapper .fvm);
229
+ expect (args.importMappings, {'package' : 'test' });
230
+ expect (args.typeMappings, {'key' : 'value' });
231
+ expect (args.reservedWordsMappings, {'const' : 'final' });
232
+ expect (args.inlineSchemaNameMappings, {'200resp' : 'OkResp' });
233
+ expect (args.pubspecPath, './test/specs/dart_pubspec.test.yaml' );
234
+ expect (args.isRemote, isFalse);
235
+ expect (args.generatorName, 'dart-dio' );
236
+ expect (args.shouldGenerateSources, isTrue);
237
+ expect (args.additionalProperties? .useEnumExtension, isTrue);
238
+ expect ((args.additionalProperties as DioProperties ? )? .nullableFields,
239
+ isTrue);
240
+ expect (await args.jarArgs, [
241
+ 'generate' ,
242
+ '-o=${args .outputDirectory }' ,
243
+ '-i=${await args .inputFileOrFetch }' ,
244
+ '-t=${args .templateDirectory }' ,
245
+ '-g=${args .generatorName }' ,
246
+ '--reserved-words-mappings=${args .reservedWordsMappings .entries .fold ('' , foldStringMap ())}' ,
247
+ '--inline-schema-name-mappings=${args .inlineSchemaNameMappings .entries .fold ('' , foldStringMap ())}' ,
248
+ '--import-mappings=${args .importMappings .entries .fold ('' , foldStringMap ())}' ,
249
+ '--type-mappings=${args .typeMappings .entries .fold ('' , foldStringMap ())}' ,
250
+ '--additional-properties=${args .additionalProperties !.toMap ().entries .fold ('' , foldStringMap (keyModifier : convertToPropertyKey ))}'
251
+ ]);
252
+ });
253
+ test ('Processes annotation with DioAltProperties correctly' , () async {
254
+ final config = File (
255
+ '${Directory .current .path }${Platform .pathSeparator }test${Platform .pathSeparator }specs${Platform .pathSeparator }dio_alt_properties_test_config.dart' )
256
+ .readAsStringSync ();
257
+ final annotations = (await resolveSource (
258
+ config,
259
+ (resolver) async =>
260
+ (await resolver.findLibraryByName ('test_lib' ))! ))
261
+ .getClass ('DioAltPropertiesTestConfig' )!
262
+ .metadata
263
+ .map ((e) => src_gen.ConstantReader (e.computeConstantValue ()! ))
264
+ .first;
265
+ final args = GeneratorArguments (annotations: annotations);
266
+ expect (args.alwaysRun, isTrue);
267
+ expect (args.useNextGen, isTrue);
268
+ expect (args.cachePath, './test/specs/output/cache.json' );
269
+ expect (args.outputDirectory, './test/specs/output' );
270
+ expect (args.runSourceGen, isTrue);
271
+ expect (args.shouldFetchDependencies, isTrue);
272
+ expect (args.skipValidation, isFalse);
273
+ expect (await args.inputFileOrFetch, './test/specs/openapi.test.yaml' );
274
+ expect (args.templateDirectory, 'template' );
275
+ expect (args.generator, Generator .dio);
276
+ expect (args.wrapper, Wrapper .fvm);
277
+ expect (args.importMappings, {'package' : 'test' });
278
+ expect (args.typeMappings, {'key' : 'value' });
279
+ expect (args.reservedWordsMappings, {'const' : 'final' });
280
+ expect (args.inlineSchemaNameMappings, {'200resp' : 'OkResp' });
281
+ expect (args.pubspecPath, './test/specs/dart_pubspec.test.yaml' );
282
+ expect (args.isRemote, isFalse);
283
+ expect (args.generatorName, 'dart-dio' );
284
+ expect (args.shouldGenerateSources, isTrue);
285
+ expect (args.additionalProperties? .useEnumExtension, isTrue);
286
+ expect (
287
+ (args.additionalProperties as DioAltProperties ? )? .nullSafe, isTrue);
288
+ expect (
289
+ (args.additionalProperties as DioAltProperties ? )
290
+ ? .nullSafeArrayDefault,
291
+ isTrue);
292
+ expect (await args.jarArgs, [
293
+ 'generate' ,
294
+ '-o=${args .outputDirectory }' ,
295
+ '-i=${await args .inputFileOrFetch }' ,
296
+ '-t=${args .templateDirectory }' ,
297
+ '-g=${args .generatorName }' ,
298
+ '--reserved-words-mappings=${args .reservedWordsMappings .entries .fold ('' , foldStringMap ())}' ,
299
+ '--inline-schema-name-mappings=${args .inlineSchemaNameMappings .entries .fold ('' , foldStringMap ())}' ,
300
+ '--import-mappings=${args .importMappings .entries .fold ('' , foldStringMap ())}' ,
301
+ '--type-mappings=${args .typeMappings .entries .fold ('' , foldStringMap ())}' ,
302
+ '--additional-properties=${args .additionalProperties !.toMap ().entries .fold ('' , foldStringMap (keyModifier : convertToPropertyKey ))}'
303
+ ]);
304
+ });
200
305
});
201
306
});
202
307
}
0 commit comments