小编G A*_*ini的帖子

使用字符串在Hugo中按键查找数据

我正在尝试创建一个基于HUGO的API文档站点,该站点读取JSON模式,并以HTML格式打印它们.

我几乎就在那里,但我很难知道如何传递我想要的部分数据.

给定标准JSON模式文件,如下所示:

{"paths": {
  "/auth/login": {
    "get": {
    "operationId": "login",
    "responses": {
      "200": {
        "description": "",
        "schema": {
          "ref": "#/definitions/loginResponse"
        }
      }
    }
  },
},
"definitions": {
  "loginResponse": {
    "type": "object"
  }
}}
Run Code Online (Sandbox Code Playgroud)

我想显示该路径的详细信息,然后使用"ref"中的模式定义渲染部分.我找到了一种方法来读取该参数,并将其解析为定义的引用.下面的"目标"看起来像:

目标:.definitions.loginResponse

{{ range $path, $methods := .paths }}
  <h4>{{ $path }}</h4>

  {{ range $method, $items := $methods }}
    <h5>{{ $method }}</h5>
    <ul>
      {{ range $status, $info := .responses }}
        <li>
          <div>{{ $status }}</div>
          <h6>Ref: {{ $info.schema.ref }}</h6>
          <p>Target: {{ $target := (printf ".definitions.%s" (index (findRE …
Run Code Online (Sandbox Code Playgroud)

schema templates json go hugo

14
推荐指数
1
解决办法
871
查看次数

标签 统计

go ×1

hugo ×1

json ×1

schema ×1

templates ×1