Skip to content

Commit b96813f

Browse files
committed
Recursively display response model attributes for graphql examples
1 parent a13ad2a commit b96813f

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

templates/graphql/docs/example.md.twig

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
{% macro getProperty(definitions, responseModel, depth) %}
2+
{%~ for definition in definitions %}
3+
{%~ if definition.name == responseModel %}
4+
{%~ for property in definition.properties | filter(p => p.required) %}
5+
{{ ("% " ~ depth * 4 ~ "s") |format("") }}{{ property.name | replace({'$': '_'}) }}{%~ if property.sub_schema %} {{ '{' }}
6+
{{- '\n' -}}
7+
{{- _self.getProperty(definitions, property.sub_schema, depth + 1) -}}
8+
{{ ("% " ~ depth * 4 ~ "s") |format("") }}{{ ' }' }}
9+
{%~ else %}
10+
{{- '\n' -}}
11+
{%~ endif %}
12+
{%~ endfor %}
13+
{%~ if definition.additionalProperties %}
14+
{{ ("% " ~ depth * 4 ~ "s") |format("") }}data
15+
{%~ endif %}
16+
{%~ endif %}
17+
{%~ endfor %}
18+
{% endmacro %}
119
{% for key,header in method.headers %}
220
{% if header == 'multipart/form-data' %}
321
{% set boundary = 'cec8e8123c05ba25' %}
@@ -55,16 +73,7 @@ mutation {
5573
{%~ if method.responseModel == 'none' or method.responseModel == '' %}
5674
status
5775
{%~ else %}
58-
{%~ for definition in spec.definitions %}
59-
{%~ if definition.name == method.responseModel %}
60-
{%~ for property in definition.properties | filter(p => p.required) %}
61-
{{ property.name | replace({'$': '_'}) }}
62-
{%~ endfor %}
63-
{%~ if definition.additionalProperties %}
64-
data
65-
{%~ endif %}
66-
{%~ endif %}
67-
{%~ endfor %}
76+
{{- _self.getProperty(spec.definitions, method.responseModel, 0) -}}
6877
{%~ endif %}
6978
}
7079
}

0 commit comments

Comments
 (0)