我正在使用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指针。
我该怎么做才能解决这个问题?
Sphinx不了解JSON Pointer语法。
为了突出显示包含的JSON文件中的某一行,您可以使用:emphasize-lines:
选项。例:
.. literalinclude:: ./general.definitions.json
:language: json
:linenos:
:emphasize-lines: 14
:caption: Object description