<!--

    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.

-->
{% assign api = site.data[include.api] %}
{% assign routes = api.paths %}

<div class="swagger">
  <div class="card routes">
    <div class="card-title">
      <p>Currently available routes</p>
    </div>

    <div class="card-text">
      <ul>
        {% for route in routes %}
        {% assign formatted_route = route[0] |
            prepend: api.basePath |
            replace: "/", '<span class="slash">/</span>' |
            replace: "{", '<span class="endpoint">:' |
            replace: "}", "</span>" %}
        {% assign formatted_id = route[0] |
            prepend: api.basePath |
            replace: "{", ":" |
            replace: "}", "" %}
        <li><a href="{{ formatted_id }}"><code class="highlighter-rouge">{{ formatted_route }}</code></a></li>
        {% endfor %}
      </ul>
    </div>
  </div>

  {% for route in routes %}
  {% assign formatted_route = route[0] |
      prepend: api.basePath |
      replace: "/", '<span class="slash">/</span>' |
      replace: "{", '<span class="endpoint">:' |
      replace: "}", "</span>" %}
  {% assign formatted_id = route[0] |
      prepend: api.basePath |
      replace: "{", ":" |
      replace: "}", "" %}
  <div class="card" id="{{ formatted_id }}">
    <div class="card-title">
      <h5 class="swagger-path"><code class="highlighter-rouge">{{ formatted_route }}</code></h5>
    </div>
    <div class="card-group">
        {% for method in route[1] %}{% assign method_info = method[1] %}
        <div class="card">
          <h5>
            <code class="highlighter-rouge {{ method[0] | downcase }}">{{ method[0] | upcase }}</code>
          </h5>
          <p>{{ method_info.summary }}</p>
          {% if method_info.parameters %}{% assign params = method_info.parameters %}
          <h5>URL parameters</h5>
          <table>
            <thead>
              <tr>
                <th>Name</th>
                <th>In</th>
                <th>Required</th>
                <th>Type</th>
              </tr>
            </thead>
            <tbody>
              {% for param in params %}
              <tr>
                <td><code class="highlighter-rouge">{{ param.name }}</code></td>
                <td>{{ param.in }}</td>
                <td>{{ param.required }}</td>
                <td>{{ param.type }}</td>
              </tr>
              {% endfor %} <!-- for param in parameters -->
            </tbody>
          </table>
          {% endif %} <!-- if method_info.parameters -->
          {% if method_info.responses %}{% assign responses = method_info.responses %}
          <h5>Responses</h5>
          <table>
            <thead>
              <tr>
                <th>Code</th>
                <th>Description</th>
              </tr>
            </thead>
            <tbody>
              {% for response in responses %}
              <tr>
                <td>{{ response[0] }}</td>
                <td>{{ response[1].description }}</td>
              </tr>
              {% endfor %} <!-- for param in parameters -->
            </tbody>
          </table>
          {% endif %} <!-- if method_info.responses -->
        </div>
        {% endfor %} <!-- for method in route[1] -->
      </div>
  </div>
  {% endfor %} <!-- for route in routes -->
</div>
