首页 > 解决方案 > 由于 json 指针,Sphinx 无法包含我的 JSON 定义文件

问题描述

我正在使用 Sphinx 记录我的 JSON Schema 以将其托管在 ReadTheDocs 上。

当我在我的主模式文件中有我的定义时,一切都很好。但我想将我的定义移动到外部 json 文件中。

我的代码从

"$ref": "#/definitions/positiveNumber"

"$ref": "./general.definitions.json#/definitions/positiveNumber"

我的general.definitions.json文件如下所示:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://raw.githubusercontent.com/andrejellema/GlobalCoffeeDataStandard/master/schema/general.definitions.json",
  "title": "General definitions",
  "definitions": {
    "percentage": {
      "title": "The percentage, 0-100",
      "description": "The percentage, from 0 to 100 with decimals allowed",
      "$comment": "Duplicate in /productionCosts.json",
      "type": "number",
      "minimum": 0,
      "maximum": 100
    },
    "positiveNumber": {
      "title": "A positive number > 0",
      "description": "A positive number starting at 0 with decimals allowed",
      "type": "number",
      "minimum": 0
    },
    "greaterThanZero": {
      "title": "The positive number, greater than 0",
      "description": "A positive number starting at greater than 0 with decimals allowed",
      "type": "number",
      "exclusiveMinimum": 0
    },
    "yesNo": {
      "title": "Yes-No enumeration",
      "type": "string",
      "enum": [
        "Yes",
        "No"
      ]
    }
  }
}

我失败的第一个内容:

.. literalinclude:: ../../schema/general.definitions.json#/definitions/positiveNumber
   :language: json
   :linenos:
   :caption: Object description

我的第一个有效内容:

.. literalinclude:: ../../schema/global-unique-id.json
   :language: json
   :linenos:
   :caption: Object description

当我打电话时,make html我收到此错误:

[...]\docs\source\explanation.rst:1360: WARNING: Include file '[...]\\schema\\general.definitions.json#\\definitions\\positiveNumber' not found or reading it failed

该文件存在于该位置。似乎 Sphinx 没有正确处理 JSON 指针。

我能做些什么来解决这个问题?

标签: jsonpython-sphinxjsonschemajsonpointer

解决方案


Sphinx 不理解 JSON 指针语法。

为了突出显示包含的 JSON 文件中的某一行,您可以使用该:emphasize-lines:选项。例子:

.. literalinclude:: ./general.definitions.json
   :language: json
   :linenos:
   :emphasize-lines: 14
   :caption: Object description

推荐阅读