|
1 |
| -import 'dart:async'; |
2 | 1 | import 'dart:convert';
|
3 | 2 | import 'dart:io';
|
4 | 3 |
|
@@ -38,40 +37,58 @@ void main() {
|
38 | 37 | });
|
39 | 38 |
|
40 | 39 | test('to generate command with import and type mappings', () async {
|
41 |
| - final annotations = await getReaderForAnnotation(''' |
42 |
| -@Openapi( |
43 |
| - inputSpec: InputSpec(path: '../openapi-spec.yaml'), |
44 |
| - typeMappings: {'int-or-string':'IntOrString'}, |
45 |
| - importMappings: {'IntOrString':'./int_or_string.dart'}, |
46 |
| - generatorName: Generator.dio, |
47 |
| - outputDirectory: '${testSpecPath}output', |
48 |
| - ) |
49 |
| - '''); |
50 |
| - final args = GeneratorArguments(annotations: annotations); |
| 40 | + final annotations = Openapi( |
| 41 | + inputSpec: InputSpec(path: '../openapi-spec.yaml'), |
| 42 | + typeMappings: {'int-or-string': 'IntOrString'}, |
| 43 | + importMappings: {'IntOrString': './int_or_string.dart'}, |
| 44 | + generatorName: Generator.dio, |
| 45 | + outputDirectory: '${testSpecPath}output', |
| 46 | + ); |
| 47 | + final args = await getArguments(annotations); |
51 | 48 | expect(
|
52 |
| - (await args.jarArgs).join(' '), |
| 49 | + args.jarArgs.join(' '), |
53 | 50 | contains(
|
54 | 51 | 'generate -o=${testSpecPath}output -i=../openapi-spec.yaml -g=dart-dio --import-mappings=IntOrString=./int_or_string.dart --type-mappings=int-or-string=IntOrString'));
|
55 | 52 | });
|
56 | 53 |
|
57 | 54 | test('to generate command with inline schema mappings', () async {
|
58 |
| - final annotations = await getReaderForAnnotation(''' |
59 |
| -@Openapi( |
60 |
| - inputSpec: InputSpec(path: '../openapi-spec.yaml'), |
61 |
| - typeMappings: {'int-or-string':'IntOrString'}, |
62 |
| - inlineSchemaNameMappings: {'inline_object_2':'SomethingMapped','inline_object_4':'nothing_new'}, |
63 |
| - generatorName: Generator.dio, |
64 |
| - outputDirectory: '${testSpecPath}output', |
65 |
| - ) |
66 |
| - '''); |
67 |
| - final args = GeneratorArguments(annotations: annotations); |
| 55 | + final annotation = Openapi( |
| 56 | + inputSpec: InputSpec(path: '../openapi-spec.yaml'), |
| 57 | + typeMappings: {'int-or-string': 'IntOrString'}, |
| 58 | + inlineSchemaNameMappings: { |
| 59 | + 'inline_object_2': 'SomethingMapped', |
| 60 | + 'inline_object_4': 'nothing_new' |
| 61 | + }, |
| 62 | + generatorName: Generator.dio, |
| 63 | + outputDirectory: '${testSpecPath}output', |
| 64 | + ); |
| 65 | + final args = await getArguments(annotation); |
68 | 66 | expect(
|
69 |
| - (await args.jarArgs).join(' '), |
| 67 | + args.jarArgs.join(' '), |
70 | 68 | equals('''
|
71 | 69 | generate -o=${testSpecPath}output -i=../openapi-spec.yaml -g=dart-dio --inline-schema-name-mappings=inline_object_2=SomethingMapped,inline_object_4=nothing_new --type-mappings=int-or-string=IntOrString
|
72 | 70 | '''
|
73 | 71 | .trim()));
|
74 | 72 | });
|
| 73 | + |
| 74 | + test('to generate command with enum name mappings', () async { |
| 75 | + final annotation = Openapi( |
| 76 | + inputSpec: InputSpec(path: '../openapi-spec.yaml'), |
| 77 | + typeMappings: {'int-or-string': 'IntOrString'}, |
| 78 | + inlineSchemaNameMappings: { |
| 79 | + 'inline_object_2': 'SomethingMapped', |
| 80 | + 'inline_object_4': 'nothing_new' |
| 81 | + }, |
| 82 | + enumNameMappings: {'name': 'name_', 'inline_object_4': 'nothing_new'}, |
| 83 | + generatorName: Generator.dio, |
| 84 | + outputDirectory: '${testSpecPath}output', |
| 85 | + ); |
| 86 | + final args = await getArguments(annotation); |
| 87 | + expect( |
| 88 | + args.jarArgs, |
| 89 | + contains( |
| 90 | + '--enum-name-mappings=name=name_,inline_object_4=nothing_new')); |
| 91 | + }); |
75 | 92 | });
|
76 | 93 |
|
77 | 94 | group('generator dioAlt', () {
|
@@ -110,18 +127,16 @@ class TestClassConfig extends OpenapiGeneratorConfig {}
|
110 | 127 |
|
111 | 128 | test('to generate command with import and type mappings for dioAlt',
|
112 | 129 | () async {
|
113 |
| - var annots = await getReaderForAnnotation(''' |
114 |
| - @Openapi( |
115 |
| - inputSpec: InputSpec(path:'../openapi-spec.yaml'), |
116 |
| - typeMappings: {'int-or-string':'IntOrString'}, |
117 |
| - importMappings: {'IntOrString':'./int_or_string.dart'}, |
118 |
| - generatorName: Generator.dioAlt, |
119 |
| - outputDirectory: '${testSpecPath}output', |
120 |
| - ) |
121 |
| - '''); |
122 |
| - var args = GeneratorArguments(annotations: annots); |
| 130 | + var annot = Openapi( |
| 131 | + inputSpec: InputSpec(path: '../openapi-spec.yaml'), |
| 132 | + typeMappings: {'int-or-string': 'IntOrString'}, |
| 133 | + importMappings: {'IntOrString': './int_or_string.dart'}, |
| 134 | + generatorName: Generator.dioAlt, |
| 135 | + outputDirectory: '${testSpecPath}output', |
| 136 | + ); |
| 137 | + var args = await getArguments(annot); |
123 | 138 | expect(
|
124 |
| - (await args.jarArgs).join(' '), |
| 139 | + args.jarArgs.join(' '), |
125 | 140 | equals(
|
126 | 141 | 'generate -o=${testSpecPath}output -i=../openapi-spec.yaml -g=dart2-api --import-mappings=IntOrString=./int_or_string.dart --type-mappings=int-or-string=IntOrString'));
|
127 | 142 | });
|
@@ -587,19 +602,3 @@ class TestClassConfig extends OpenapiGeneratorConfig {}
|
587 | 602 | });
|
588 | 603 | });
|
589 | 604 | }
|
590 |
| - |
591 |
| -Future<ConstantReader> getReaderForAnnotation(String annotationDef) async { |
592 |
| - final annotations = (await resolveSource(''' |
593 |
| -library test_lib; |
594 |
| -import 'package:openapi_generator_annotations/openapi_generator_annotations.dart'; |
595 |
| -
|
596 |
| -$annotationDef |
597 |
| -class TestClassConfig {} |
598 |
| - ''', |
599 |
| - (resolver) async => (await resolver.findLibraryByName('test_lib'))!)) |
600 |
| - .getClass('TestClassConfig')! |
601 |
| - .metadata |
602 |
| - .map((e) => ConstantReader(e.computeConstantValue()!)) |
603 |
| - .first; |
604 |
| - return annotations; |
605 |
| -} |
0 commit comments