From 7f8d0440a03d547f7e719ac8c4ff155e01118c3d Mon Sep 17 00:00:00 2001 From: RENAUDIN David Date: Mon, 9 Jul 2018 15:39:17 +0200 Subject: [PATCH] Fix the render of raml2html with the update of the template from raml2html repo. --- raml2html_template/examples.nunjucks | 18 ++ raml2html_template/item.nunjucks | 125 +++++++--- raml2html_template/resource.nunjucks | 343 +++++++++++++++++++++++---- 3 files changed, 398 insertions(+), 88 deletions(-) create mode 100644 raml2html_template/examples.nunjucks diff --git a/raml2html_template/examples.nunjucks b/raml2html_template/examples.nunjucks new file mode 100644 index 0000000..6d29dbe --- /dev/null +++ b/raml2html_template/examples.nunjucks @@ -0,0 +1,18 @@ +{% if parent.examples.length %} +

{{ 'Example' if parent.examples.length == 1 else 'Examples' }}:

+
+ {% for example in parent.examples %} + {% if example.displayName or example.description %} +

+ {% if example.displayName %} + {{ example.displayName }}:
+ {% endif %} + {% if example.description %} + {{ example.description }} + {% endif %} +

+ {% endif %} +
{{ example.value | escape }}
+ {% endfor %} +
+{% endif %} \ No newline at end of file diff --git a/raml2html_template/item.nunjucks b/raml2html_template/item.nunjucks index 234abdc..8a6f0be 100644 --- a/raml2html_template/item.nunjucks +++ b/raml2html_template/item.nunjucks @@ -1,47 +1,100 @@
  • - {% if item.displayName %} - {{ item.displayName }}: - {% else %} - {{ key }}: - {% endif %} + {{ item.key }}{% if item.type !== nil %}: + + {% if not item.structuredValue %} + + {%- if item.required -%}required {% endif -%} + ( + {%- if item.enum -%} + {%- if item.enum.length === 1 -%} + {{ item.enum.join(', ') }} + {%- else -%} + one of {{ item.enum.join(', ') }} + {%- endif -%} + {%- else -%} + {%- if item.type === 'array' and item.items -%} + array of {{ item.items.originalType | d(item.items.type) }} + {%- elif item.type === 'union' and item.anyOf.length -%} + union of + {% for alt in item.anyOf -%} + {{ alt.originalType | d(alt.displayName) | d(alt.type) }} + {%- if not loop.last %} or {% endif -%} + {%- endfor -%} + {%- else -%} + {{ item.type }} + {%- endif -%} + {%- endif -%} - - {%- if item.required -%}required {% endif -%} - ( - {%- if item.enum -%} - one of {{ item.enum.join(', ') }} - {%- else -%} - {{ item.type }} - {%- endif -%} - - {%- if item.default or item.default == 0 or item.default == false %} - default: {{ item.default }}{%- endif -%} - {%- if item.repeat %} - repeat: {{ item.repeat }}{%- endif -%} - {%- if item.type == 'string' -%} - {%- if item.minLength or item.minLength == 0 %} - minLength: {{ item.minLength }}{%- endif -%} - {%- if item.maxLength or item.maxLength == 0 %} - maxLength: {{ item.maxLength }}{%- endif -%} - {%- else -%} - {%- if item.minimum or item.minimum == 0 %} - minimum: {{ item.minimum }}{%- endif -%} - {%- if item.maximum or item.maximum == 0 %} - maximum: {{ item.maximum }}{%- endif -%} - {%- endif -%} - {%- if item.pattern %} - pattern: {{ item.pattern }}{%- endif -%} - ) - + {%- if item.default or item.default == 0 or item.default == false %} - default: {{ item.default }}{%- endif -%} + {%- if item.repeat %} - repeat: {{ item.repeat }}{%- endif -%} + {%- if item.type == 'string' -%} + {%- if item.minLength or item.minLength == 0 %} - minLength: {{ item.minLength }}{%- endif -%} + {%- if item.maxLength or item.maxLength == 0 %} - maxLength: {{ item.maxLength }}{%- endif -%} + {%- else -%} + {%- if item.minItems or item.minItems == 0 %} - minItems: {{ item.minItems }}{%- endif -%} + {%- if item.maxItems or item.maxItems == 0 %} - maxItems: {{ item.maxItems }}{%- endif -%} + {%- if item.minimum or item.minimum == 0 %} - minimum: {{ item.minimum }}{%- endif -%} + {%- if item.maximum or item.maximum == 0 %} - maximum: {{ item.maximum }}{%- endif -%} + {%- endif -%} + {%- if item.pattern %} - pattern: {{ item.pattern }}{%- endif -%} + ) + + {% endif %} + {% endif %} {% markdown %} {{ item.description }} {% endmarkdown %} - {% if item.schema %} -

    Schema:

    -
    {{ item.schema | escape }}
    + {% if item.annotations.length %} +

    Annotations

    + {% endif %} - {% if item.example %} -

    Example:

    - {% if item.type == 'string' %} -
    {{ item.example| escape }}
    - {% else %} -
    {{ item.example | escape }}
    + {% if item.items and item.items.properties %} + {% if isStandardType(item.items) %} +

    Items: {{ item.items }}

    + {% endif %} + + {% if not isStandardType(item.items) %} +

    Items: {{ item.items.displayName }}

    + + {% if item.items.properties or item.items.examples.length %} +
    + {% if item.items.properties %} +
      + {% for item in item.items.properties %} + {% include "./item.nunjucks" %} + {% endfor %} +
    + {% endif %} + + {# Sub-item Examples #} + {% set parent = item.items %} + {% include "./examples.nunjucks" %} +
    + {% endif %} {% endif %} {% endif %} -
  • \ No newline at end of file + + {% if item.properties %} + + {% endif %} + + {# Item Examples #} + {% set parent = item %} + {% include "./examples.nunjucks" %} + + {% if item.structuredValue %} +
    {{ item.structuredValue | dump }}
    + {% endif %} + + diff --git a/raml2html_template/resource.nunjucks b/raml2html_template/resource.nunjucks index 778780a..2a02060 100644 --- a/raml2html_template/resource.nunjucks +++ b/raml2html_template/resource.nunjucks @@ -1,5 +1,5 @@ {% if (resource.methods or (resource.description and resource.parentUrl)) %} -
    +