Definition

Assembly: Mintlify.Core.dll Namespace: Mintlify.Core Inheritance: System.Object

Syntax

Mintlify.Core.DocsJsonManager

Summary

Loads and manages Mintlify docs.json configuration files with navigation manipulation capabilities.

Remarks

This class provides comprehensive support for loading, validating, and modifying Mintlify documentation configuration files. It handles serialization using the standard Mintlify JSON options and provides APIs for navigation manipulation.

Constructors

.ctor

Initializes a new instance of the DocsJsonManager class.

Syntax

public DocsJsonManager()

.ctor

Initializes a new instance of the DocsJsonManager class with the specified file path.

Syntax

public DocsJsonManager(string filePath)

Parameters

NameTypeDescription
filePathstringThe path to the docs.json file to load.

Exceptions

ExceptionDescription
ArgumentExceptionThrown when the file path does not exist or is not a JSON file.

Properties

Configuration

Gets the loaded Mintlify documentation configuration.

Syntax

public Mintlify.Core.Models.DocsJsonConfig Configuration { get; internal set; }

Property Value

Type: Mintlify.Core.Models.DocsJsonConfig? The DocsJsonConfig instance loaded from the file system or string content. Returns null if no configuration has been loaded or if loading failed.

ConfigurationErrors

Gets the collection of configuration loading errors encountered during processing.

Syntax

public System.Collections.Generic.List<System.CodeDom.Compiler.CompilerError> ConfigurationErrors { get; private set; }

Property Value

Type: System.Collections.Generic.List<System.CodeDom.Compiler.CompilerError> A collection of CompilerError instances representing validation errors, parsing failures, or other issues encountered during configuration loading.

FilePath

Gets the file path of the loaded docs.json configuration file.

Syntax

public string FilePath { get; private set; }

Property Value

Type: string? The full path to the docs.json file that was loaded. Returns null if the configuration was loaded from string content rather than a file.

IsLoaded

Gets a value indicating whether the configuration has been successfully loaded.

Syntax

public bool IsLoaded { get; }

Property Value

Type: bool True if the configuration was loaded without errors; otherwise, false.

Methods

ApplyDefaults

Applies default values to missing configuration properties.

Syntax

public void ApplyDefaults()

Exceptions

ExceptionDescription
InvalidOperationExceptionThrown when no configuration is loaded.

ApplyUrlPrefix

Applies a URL prefix to all page references in the navigation structure.

Syntax

public void ApplyUrlPrefix(string prefix)

Parameters

NameTypeDescription
prefixstringThe prefix to apply to all URLs.

Exceptions

ExceptionDescription
ArgumentExceptionThrown when prefix is null or whitespace.
InvalidOperationExceptionThrown when no configuration is loaded.

Remarks

This method recursively traverses the entire navigation structure and prepends the specified prefix to all page URLs, href attributes, and root paths. The prefix is normalized to ensure proper URL formatting (e.g., trailing slashes are handled).

CreateDefault

Creates a default Mintlify documentation configuration with basic structure.

Syntax

public static Mintlify.Core.Models.DocsJsonConfig CreateDefault(string name, string theme = "mint")

Parameters

NameTypeDescription
namestringThe name of the documentation site.
themestringThe theme to use for the documentation site.

Returns

Type: Mintlify.Core.Models.DocsJsonConfig A new DocsJsonConfig instance with default values.

Exceptions

ExceptionDescription
ArgumentExceptionThrown when name is null or whitespace.

Load

Loads and parses the docs.json file from the file path specified in the constructor.

Syntax

public void Load()

Exceptions

ExceptionDescription
InvalidOperationExceptionThrown when no file path has been specified.

Load

Loads and parses the docs.json configuration from the specified string content.

Syntax

public void Load(string content)

Parameters

NameTypeDescription
contentstringThe JSON content to parse as a docs.json configuration.

Exceptions

ExceptionDescription
ArgumentExceptionThrown when content is null or whitespace.

Merge

Merges another docs.json configuration into the current configuration.

Syntax

public void Merge(Mintlify.Core.Models.DocsJsonConfig other, bool combineBaseProperties = true, Mintlify.Core.Models.MergeOptions options = null)

Parameters

NameTypeDescription
otherMintlify.Core.Models.DocsJsonConfigThe configuration to merge into the current one.
combineBasePropertiesboolIf true, merges base properties; if false, only merges navigation.
optionsMintlify.Core.Models.MergeOptions?Optional merge options to control merge behavior. When null, default behavior is used.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when other is null.
InvalidOperationExceptionThrown when no configuration is loaded.

Remarks

This method performs a shallow merge, with the other configuration taking precedence for non-null values. Navigation structures are combined intelligently.

MergeNavigation

Merges navigation from another NavigationConfig into the current configuration’s navigation.

Syntax

public void MergeNavigation(Mintlify.Core.Models.NavigationConfig sourceNavigation, Mintlify.Core.Models.MergeOptions options = null)

Parameters

NameTypeDescription
sourceNavigationMintlify.Core.Models.NavigationConfigThe navigation configuration to merge from.
optionsMintlify.Core.Models.MergeOptions?Optional merge options to control merge behavior.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when sourceNavigation is null.
InvalidOperationExceptionThrown when no configuration is loaded.

Remarks

This method intelligently merges navigation structures, combining groups with the same name and deduplicating page references. Use the MergeOptions parameter to control specific behaviors like how empty groups are handled.

MergeNavigation

Merges navigation from an existing docs.json file into the current configuration.

Syntax

public void MergeNavigation(string filePath, Mintlify.Core.Models.MergeOptions options = null)

Parameters

NameTypeDescription
filePathstringThe path to the docs.json file containing navigation to merge.
optionsMintlify.Core.Models.MergeOptions?Optional merge options to control merge behavior.

Exceptions

ExceptionDescription
ArgumentExceptionThrown when filePath is null or whitespace.
InvalidOperationExceptionThrown when no configuration is loaded.
FileNotFoundExceptionThrown when the specified file does not exist.

Remarks

This method loads navigation from an external docs.json file and merges it into the current configuration. Only the navigation structure is merged; other configuration properties are not affected.

PopulateNavigationFromPath

Populates the navigation structure from a directory path by scanning for MDX files.

Syntax

public void PopulateNavigationFromPath(string path, string[] fileExtensions = null)

Parameters

NameTypeDescription
pathstringThe directory path to scan for documentation files.
fileExtensionsstring[]?The file extensions to include (defaults to .mdx only).

Exceptions

ExceptionDescription
ArgumentExceptionThrown when path is null or whitespace.
InvalidOperationExceptionThrown when no configuration is loaded.
DirectoryNotFoundExceptionThrown when the specified path does not exist.

Remarks

This method scans the specified directory recursively and builds a navigation structure based on the folder hierarchy and MDX files found. The method includes several advanced features: The method preserves the directory structure in the navigation while applying these intelligent processing rules to create clean, organized documentation.

Save

Saves the current configuration to the file system using the original file path.

Syntax

public void Save()

Exceptions

ExceptionDescription
InvalidOperationExceptionThrown when no configuration is loaded or no file path is specified.

Save

Saves the current configuration to the specified file path.

Syntax

public void Save(string filePath)

Parameters

NameTypeDescription
filePathstringThe file path where the configuration should be saved.

Exceptions

ExceptionDescription
ArgumentExceptionThrown when filePath is null or whitespace.
InvalidOperationExceptionThrown when no configuration is loaded.