Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema file for toc? #7736

Open
klacol opened this issue Nov 29, 2021 · 5 comments
Open

Schema file for toc? #7736

klacol opened this issue Nov 29, 2021 · 5 comments
Labels
toc Navigation components like menus, TOC and breadcrumbs

Comments

@klacol
Copy link
Contributor

klacol commented Nov 29, 2021

Hi, I am using VS Code to work on my content in DocFx. Often I have to write proper toc files . In VSCode there is an inline checker against the yaml-schemas, but it looks up a wrong schema and then alle the file is red underlined.

Is there a schema file around for the toc.yml that I can configure for my toc files??

@klacol
Copy link
Contributor Author

klacol commented Nov 29, 2021

The schema file would be something like this:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://dotnet.github.io/docfx/toc.schema.json",
  "title": "Schema for DocFx Table-Of-Content Files (toc.yml)",
  "description": "Reference: https://dotnet.github.io/docfx/tutorial/intro_toc.html",
  "additionalProperties": false,
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "name": {
        "description": "Specifies the title of the TOC Item.",
        "type": "string"
      },
      "href": {
        "description": "Specifies the navigation path of the TOC Item. If href is not specified, the TOC Item serves as a container to parent its children TOC Items. If href is an absolute path, the TOC Item navigates to that specified path. If a TOC Item is linking to a relative path, there are three cases: 1. Linking to another TOC File, for example, href: examples/toc.md. 2. Linking to a folder, which means, the value of the link ends with / explicitly, for example, href: examples/ 3. Linking to some local file.",
        "type": "string"
      },
      "topicHref": {
        "description": "Specifies the topic href of the TOC Item. It is useful when href is linking to a folder or TOC file or tocHref is used.",
        "type": "string"
      },
      "topicUid": {
        "description": "Specifies the uid of the referenced file. If the value is set, it overwrites the value of topicHref.",
        "type": "string"
      }
    }
  }
}

@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented Nov 29, 2021

The schema has to be defined recursively so that TOC.yml can have any depth of nested items.

TOC.yml is read by TocHelper.LoadYamlToc, which allows either TocViewModel or TocRootViewModel. The schema document could define schemas for TocViewModel, TocRootViewModel, and TocItemViewModel, and then allow either TocViewModel or TocRootViewModel at the top level.

The documentation of topicHref mentions tocHref, which is also implemented in TocItemViewModel but does not seem to be really documented. I don't know whether it is intended to be used in TOC.yml files or generated internally. There are also other undocumented properties like includedFrom and displayName.

Untested:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "toc.yml for DocFX",
  "$defs": {
    "TocViewModel": {
      "$comment": "Microsoft.DocAsCode.DataContracts.Common.TocViewModel",
      "title": "Array of TOC Item Objects",
      "type": "array",
      "items": {
        "$ref": "#/$defs/TocItemViewModel"
      }
    },
    "TocRootViewModel": {
      "$comment": "Microsoft.DocAsCode.DataContracts.Common.TocRootViewModel",
      "title": "TOC Item Objects with metadata",
      "description": "This feature was added in <https://github.com/dotnet/docfx/pull/1731>.",
      "type": "object",
      "properties": {
        "items": {
          "$comment": "TocRootViewModel.Items",
          "$ref": "#/$defs/TocViewModel"
        }
      },
      "additionalProperties": {
        "$comment": "TocRootViewModel.Metadata"
      }
    },
    "TocItemViewModel": {
      "$comment": "Microsoft.DocAsCode.DataContracts.Common.TocItemViewModel",
      "title": "TOC Item Object",
      "description": "<https://dotnet.github.io/docfx/tutorial/intro_toc.html#toc-item-object>",
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "$comment": "TocItemViewModel.Name",
          "title": "Title of TOC item",
          "description": "Specifies the title of the TOC Item.",
          "type": "string"
        },
        "href": {
          "$comment": "TocItemViewModel.Href",
          "title": "Path of folder, file, or TOC file",
          "description": "Specifies the navigation path of the TOC Item. If \"href\" is not specified, the TOC Item serves as a container to parent its children TOC Items. If \"href\" is an absolute path, the TOC Item navigates to that specified path. If \"href\" is a relative path, see <https://dotnet.github.io/docfx/tutorial/intro_toc.html#href-in-detail> for details.",
          "type": "string"
        },
        "items": {
          "$comment": "TocItemViewModel.Items",
          "$ref": "#/$defs/TocViewModel"
        },
        "topicHref": {
          "$comment": "TocItemViewModel.TopicHref",
          "type": "string"
        },
        "topicUid": {
          "$comment": "TocItemViewModel.TopicUid",
          "type": "string"
        },
        "homepage": {
          "$comment": "TocItemViewModel.Homepage",
          "description": "Use \"topicHref\" instead.",
          "type": "string",
          "deprecated": true
        },
        "uid": {
          "$comment": "TocItemViewModel.Uid",
          "description": "Use \"topicUid\" instead.",
          "type": "string",
          "deprecated": true
        },
        "homepageUid": {
          "$comment": "TocItemViewModel.HomepageUid",
          "description": "Use \"topicUid\" instead.",
          "type": "string",
          "deprecated": true
        },
        "displayName": {
          "$comment": "TocItemViewModel.DisplayName; undocumented",
          "type": "string"
        },
        "originalHref": {
          "$comment": "TocItemViewModel.OriginalHref; undocumented",
          "type": "string"
        },
        "tocHref": {
          "$comment": "TocItemViewModel.TocHref; almost undocumented",
          "type": "string"
        },
        "originalTocHref": {
          "$comment": "TocItemViewModel.OriginalTocHref; undocumented",
          "type": "string"
        },
        "originalTopicHref": {
          "$comment": "TocItemViewModel.OriginalTopicHref; undocumented",
          "type": "string"
        },
        "includedFrom": {
          "$comment": "TocItemViewModel.IncludedFrom; undocumented",
          "type": "string"
        },
        "originallHomepage": {
          "$comment": "TocItemViewModel.OriginalHomepage; undocumented; misspelled",
          "type": "string"
        }
      },
      "patternProperties": {
        "^name\\.": {
          "$comment": "TocItemViewModel.NameInDevLangs",
          "type": "string"
        }
      },
      "additionalProperties": {
        "$comment": "TocItemViewModel.Metadata"
      },
      "dependentSchemas": {
        "topicHref": {
          "$comment": "\"topicHref\" should be used instead of the deprecated \"homepage\", not with it.",
          "properties": {
            "homepage": false
          }
        },
        "topicUid": {
          "$comment": "\"topicUid\" should be used instead of the deprecated \"uid\" and \"homepageUid\", not with them.",
          "properties": {
            "uid": false,
            "homepageUid": false
          }
        }
      }
    }
  },
  "oneOf": [
    {
      "$ref": "#/$defs/TocViewModel",
      "title": "Without metadata"
    },
    {
      "$ref": "#/$defs/TocRootViewModel",
      "title": "With metadata"
    }
  ]
}

@klacol
Copy link
Contributor Author

klacol commented Nov 30, 2021

Great. I made the property href required:

"TocItemViewModel": {
      "$comment": "Microsoft.DocAsCode.DataContracts.Common.TocItemViewModel",
      "title": "TOC Item Object",
      "description": "<https://dotnet.github.io/docfx/tutorial/intro_toc.html#toc-item-object>",
      "type": "object",
      "required": [
        "name", "href"
      ],

Then it works like a charm.

30-11-_2021_20-37-24

@klacol
Copy link
Contributor Author

klacol commented Nov 30, 2021

I made the property href required.

I was wrong. The property href is not required. TOC-items, that do not directly link zu a page, dot not require a href.

@KalleOlaviNiemitalo
Copy link

Based on

it seems that DocFX v2 deprecates uid and recommends topicUid, but v3 uses uid and does not implement topicUid:

YAML v2 v3
"name" TocItemViewModel.Name (documented) TocNode.Name (documented)
"name." + language TocItemViewModel.NameInDevLangs
"href" TocItemViewModel.Href (documented) TocNode.Href (documented)
"tocHref" TocItemViewModel.TocHref TocNode.TocHref (documented)
"topicHref" TocItemViewModel.TopicHref (documented) TocNode.TopicHref (documented)
"homepage" TocItemViewModel.Homepage (deprecated) TocNode.Homepage (undocumented)
"uid" TocItemViewModel.Uid (deprecated) TocNode.Uid (documented)
"topicUid" TocItemViewModel.TopicUid (documented)
"homepageUid" TocItemViewModel.HomepageUid (deprecated)
"items" TocItemViewModel.Items (documented) TocNode.Items (documented)
"displayName" TocItemViewModel.DisplayName (undocumented) TocNode.DisplayName (undocumented)
"originalHref" TocItemViewModel.OriginalHref (undocumented)
"originalTocHref" TocItemViewModel.OriginalTocHref (undocumented)
"originalTopicHref" TocItemViewModel.OriginalTopicHref (undocumented)
"includedFrom" TocItemViewModel.IncludedFrom (undocumented)
"originallHomepage" TocItemViewModel.OriginalHomepage (undocumented)
"landingPageType" TocNode.LandingPageType (undocumented)
"expanded" TocNode.Expanded (undocumented)
"maintainContext" TocNode.MaintainContext (undocumented)
"monikers" TocNode.Monikers (output only)
"children" TocNode.Children (output only)
other TocItemViewModel.Metadata TocNode.ExtensionData

I don't see v3 using any of the "original" properties, so those could be disallowed in the schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
toc Navigation components like menus, TOC and breadcrumbs
Projects
None yet
Development

No branches or pull requests

3 participants