Skip to content

Commit fc6efa8

Browse files
committed
got some more tests working
1 parent 28e6676 commit fc6efa8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Spec/Swagger2.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ public function getDefinitions()
319319
foreach ($sch['properties'] as $name => $def) {
320320
$sch['properties'][$name]['name'] = $name;
321321
$sch['properties'][$name]['description'] = $def['description'];
322+
$sch['properties'][$name]['example'] = $def['x-example'];
322323
$sch['properties'][$name]['required'] = in_array($name, $sch['required']);
323324
if (isset($def['items']['$ref'])) {
324325
//nested model

templates/flutter/test/services/service_test.dart.twig

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,18 @@ void main() {
4141
{%~ elseif method.type == 'location' ~%}
4242
final Uint8List data = Uint8List.fromList([]);
4343
{% else %}
44+
45+
{%~ if method.responseModel and method.responseModel != 'any' ~%}
4446
final Map<String, dynamic> data = {
47+
{%- for definition in spec.definitions ~%}{%~ if definition.name == method.responseModel -%}
48+
{%~ for property in definition.properties | filter((param) => param.required) ~%}
49+
'{{property.name | escapeKeyword | escapeDollarSign}}': {% if property.type == 'object' %}{}{% elseif property.type == 'array' %}[]{% elseif property.type == 'string' %}'{{property.example}}'{% else %}{{property.example}}{% endif %},
50+
{%~ endfor ~%}{% set break = true %}{%- else -%}{% set continue = true %}{%- endif -%}{%~ endfor ~%}
4551
{# need response model #}
4652
};
53+
{%~ else ~%}
54+
final data = null;
55+
{%- endif -%}
4756
{% endif %}
4857

4958
when(client.call(
@@ -53,14 +62,17 @@ void main() {
5362
final response = await {{service.name | caseCamel}}.{{method.name | caseCamel}}(
5463
{% for parameter in method.parameters.all %}
5564
{% if parameter.required %}
56-
{{parameter.name | caseCamel}}: '{{parameter.example}}',
65+
{{parameter.name | caseCamel}}: {% if parameter.type == 'object' %}{}{% else %}'{{parameter.example}}'{% endif %},
5766
{% endif %}
5867
{% endfor %}
5968
);
6069

6170
{%~ if method.type == 'location' ~%}
6271
expect(response, isA<Uint8List>());
6372
{% endif %}
73+
{%~ if method.responseModel and method.responseModel != 'any' ~%}
74+
expect(response, isA<models.{{method.responseModel | caseUcfirst | overrideIdentifier}}>());
75+
{% endif %}
6476

6577
});
6678

0 commit comments

Comments
 (0)