Skip to content

Commit

Permalink
chore: add System.Text.Json attributes (#9341)
Browse files Browse the repository at this point in the history
* chore: add JsonExtensionData attribute of System.Text.Json

* chore: add JsonIgnore attribute of System.Text.Json

* chore: add JsonConstructor attribute of System.Text.Json

* chore: add Newtonsoft.Json namespace qualifier of JsonConverter

* chore: add JsonPropertyName attribute of System.Text.Json
  • Loading branch information
filzrev authored Oct 25, 2023
1 parent 0af0b34 commit 893f794
Show file tree
Hide file tree
Showing 100 changed files with 941 additions and 131 deletions.
30 changes: 29 additions & 1 deletion src/Docfx.App/Config/BuildJsonConfig.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Text.Json.Serialization;
using Docfx.Common;
using Docfx.Plugins;

Expand All @@ -18,24 +19,28 @@ internal class BuildJsonConfig
/// Contains all the files to generate documentation, including metadata yml files and conceptual md files.
/// </summary>
[JsonProperty("content")]
[JsonPropertyName("content")]
public FileMapping Content { get; set; }

/// <summary>
/// Contains all the resource files that conceptual and metadata files dependent on, e.g. image files.
/// </summary>
[JsonProperty("resource")]
[JsonPropertyName("resource")]
public FileMapping Resource { get; set; }

/// <summary>
/// Contains all the conceptual files which contains yaml header with uid and is intended to override the existing metadata yml files.
/// </summary>
[JsonProperty("overwrite")]
[JsonPropertyName("overwrite")]
public FileMapping Overwrite { get; set; }

/// <summary>
/// Specifies the urls of xrefmap used by content files. Supports local file path and HTTP/HTTPS urls.
/// </summary>
[JsonProperty("xref")]
[JsonPropertyName("xref")]
public ListWithStringFallback Xref { get; set; }

/// <summary>
Expand All @@ -44,26 +49,30 @@ internal class BuildJsonConfig
/// </summary>
[Obsolete("Use output instead.")]
[JsonProperty("dest")]
[JsonPropertyName("dest")]
public string Dest { get; set; }

/// <summary>
/// Defines the output folder of the generated build files.
/// Command line --output argument override this value.
/// </summary>
[JsonProperty("output")]
[JsonPropertyName("output")]
public string Output { get; set; }

/// <summary>
/// Contains metadata that will be applied to every file, in key-value pair format.
/// </summary>
[JsonProperty("globalMetadata")]
[JsonConverter(typeof(JObjectDictionaryToObjectDictionaryConverter))]
[JsonPropertyName("globalMetadata")]
[Newtonsoft.Json.JsonConverter(typeof(JObjectDictionaryToObjectDictionaryConverter))]
public Dictionary<string, object> GlobalMetadata { get; set; }

/// <summary>
/// Specify a list of JSON file path containing globalMetadata settings.
/// </summary>
[JsonProperty("globalMetadataFiles")]
[JsonPropertyName("globalMetadataFiles")]
public ListWithStringFallback GlobalMetadataFiles { get; set; } = new ListWithStringFallback();

/// <summary>
Expand All @@ -74,12 +83,14 @@ internal class BuildJsonConfig
/// The value is the value of the metadata.
/// </summary>
[JsonProperty("fileMetadata")]
[JsonPropertyName("fileMetadata")]
public Dictionary<string, FileMetadataPairs> FileMetadata { get; set; }

/// <summary>
/// Specify a list of JSON file path containing fileMetadata settings.
/// </summary>
[JsonProperty("fileMetadataFiles")]
[JsonPropertyName("fileMetadataFiles")]
public ListWithStringFallback FileMetadataFiles { get; set; } = new ListWithStringFallback();

/// <summary>
Expand All @@ -88,6 +99,7 @@ internal class BuildJsonConfig
/// If omitted, embedded default template will be used.
/// </summary>
[JsonProperty("template")]
[JsonPropertyName("template")]
public ListWithStringFallback Template { get; set; } = new ListWithStringFallback();

/// <summary>
Expand All @@ -98,6 +110,7 @@ internal class BuildJsonConfig
/// If omitted, no theme will be applied, the default theme inside the template will be used.
/// </summary>
[JsonProperty("theme")]
[JsonPropertyName("theme")]
public ListWithStringFallback Theme { get; set; }

/// <summary>
Expand All @@ -110,6 +123,7 @@ internal class BuildJsonConfig
/// </code>
/// </example>
[JsonProperty("postProcessors")]
[JsonPropertyName("postProcessors")]
public ListWithStringFallback PostProcessors { get; set; } = new ListWithStringFallback();

/// <summary>
Expand All @@ -118,64 +132,74 @@ internal class BuildJsonConfig
/// If not specified, it is false
/// </summary>
[JsonProperty("debug")]
[JsonPropertyName("debug")]
public bool? Debug { get; set; }

/// <summary>
/// The output folder for files generated for debugging purpose when in debug mode.
/// If not specified, it is ${TempPath}/docfx
/// </summary>
[JsonProperty("debugOutput")]
[JsonPropertyName("debugOutput")]
public string DebugOutput { get; set; }

/// <summary>
/// If set to true, data model to run template script will be extracted in .raw.model.json extension.
/// </summary>
[JsonProperty("exportRawModel")]
[JsonPropertyName("exportRawModel")]
public bool? ExportRawModel { get; set; }

/// <summary>
/// Specify the output folder for the raw model.
/// If not set, the raw model will be generated to the same folder as the output documentation.
/// </summary>
[JsonProperty("rawModelOutputFolder")]
[JsonPropertyName("rawModelOutputFolder")]
public string RawModelOutputFolder { get; set; }

/// <summary>
/// If set to true, data model to apply template will be extracted in .view.model.json extension.
/// </summary>
[JsonProperty("exportViewModel")]
[JsonPropertyName("exportViewModel")]
public bool? ExportViewModel { get; set; }

/// <summary>
/// Specify the output folder for the view model.
/// If not set, the view model will be generated to the same folder as the output documentation.
/// </summary>
[JsonProperty("viewModelOutputFolder")]
[JsonPropertyName("viewModelOutputFolder")]
public string ViewModelOutputFolder { get; set; }

/// <summary>
/// If set to true, template will not be actually applied to the documents.
/// This option is always used with --exportRawModel or --exportViewModel is set so that only raw model files or view model files are generated.
/// </summary>
[JsonProperty("dryRun")]
[JsonPropertyName("dryRun")]
public bool? DryRun { get; set; }

/// <summary>
/// Set the max parallelism, 0 is auto.
/// </summary>
[JsonProperty("maxParallelism")]
[JsonPropertyName("maxParallelism")]
public int? MaxParallelism { get; set; }

/// <summary>
/// Set the parameters for markdown engine, value should be a JSON string.
/// </summary>
[JsonProperty("markdownEngineProperties")]
[JsonPropertyName("markdownEngineProperties")]
public MarkdownServiceProperties MarkdownEngineProperties { get; set; }

/// <summary>
/// Set the name of ICustomHrefGenerator derived class.
/// </summary>
[JsonProperty("customLinkResolver")]
[JsonPropertyName("customLinkResolver")]
public string CustomLinkResolver { get; set; }

/// <summary>
Expand All @@ -192,25 +216,29 @@ internal class BuildJsonConfig
/// </code>
/// </example>
[JsonProperty("groups")]
[JsonPropertyName("groups")]
public Dictionary<string, GroupConfig> Groups { get; set; }

/// <summary>
/// If set to true, docfx does not dereference (aka. copy) file to the output folder.
/// Instead, it saves a link_to_path property inside manifest.json to indicate the physical location of that file.
/// </summary>
[JsonProperty("keepFileLink")]
[JsonPropertyName("keepFileLink")]
public bool KeepFileLink { get; set; }

/// <summary>
/// Specifies the options for the sitemap.xml file.
/// </summary>
[JsonProperty("sitemap")]
[JsonPropertyName("sitemap")]
public SitemapOptions Sitemap { get; set; }

/// <summary>
/// Disable fetching Git related information for articles.
/// By default it is enabled and may have side effect on performance when the repo is large.
/// </summary>
[JsonProperty("disableGitFeatures")]
[JsonPropertyName("disableGitFeatures")]
public bool DisableGitFeatures { get; set; }
}
2 changes: 1 addition & 1 deletion src/Docfx.App/Config/FileMetadataPairs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Docfx;
/// </summary>
/// <see cref="BuildJsonConfig.FileMetadata"/>
/// <see cref="MergeJsonItemConfig.FileMetadata"/>
[JsonConverter(typeof(FileMetadataPairsConverter))]
[Newtonsoft.Json.JsonConverter(typeof(FileMetadataPairsConverter))]
internal class FileMetadataPairs
{
// Order matters, the latter one overrides the former one
Expand Down
5 changes: 4 additions & 1 deletion src/Docfx.App/Config/GroupConfig.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace Docfx;
Expand All @@ -14,11 +15,13 @@ internal class GroupConfig
/// Defines the output folder of the generated build files.
/// </summary>
[JsonProperty("dest")]
[JsonPropertyName("dest")]
public string Destination { get; set; }

/// <summary>
/// Extension metadata.
/// </summary>
[JsonExtensionData]
[Newtonsoft.Json.JsonExtensionData]
[System.Text.Json.Serialization.JsonExtensionData]
public Dictionary<string, object> Metadata { get; set; } = new Dictionary<string, object>();
}
2 changes: 1 addition & 1 deletion src/Docfx.App/Config/ListWithStringFallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Docfx;
/// <summary>
/// ListWithStringFallback.
/// </summary>
[JsonConverter(typeof(ListWithStringFallbackConverter))]
[Newtonsoft.Json.JsonConverter(typeof(ListWithStringFallbackConverter))]
internal class ListWithStringFallback : List<string>
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.App/Config/MergeJsonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Docfx;
/// <summary>
/// MergeJsonConfig.
/// </summary>
[JsonConverter(typeof(MergeJsonConfigConverter))]
[Newtonsoft.Json.JsonConverter(typeof(MergeJsonConfigConverter))]
internal class MergeJsonConfig : List<MergeJsonItemConfig>
{
/// <summary>
Expand Down
8 changes: 7 additions & 1 deletion src/Docfx.App/Config/MergeJsonItemConfig.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Text.Json.Serialization;
using Docfx.Common;

using Newtonsoft.Json;
Expand All @@ -16,19 +17,22 @@ internal class MergeJsonItemConfig
/// Defines the files to merge.
/// </summary>
[JsonProperty("content")]
[JsonPropertyName("content")]
public FileMapping Content { get; set; }

/// <summary>
/// Defines the output folder of the generated merge files.
/// </summary>
[JsonProperty("dest")]
[JsonPropertyName("dest")]
public string Destination { get; set; }

/// <summary>
/// Contains metadata that will be applied to every file, in key-value pair format.
/// </summary>
[JsonProperty("globalMetadata")]
[JsonConverter(typeof(JObjectDictionaryToObjectDictionaryConverter))]
[JsonPropertyName("globalMetadata")]
[Newtonsoft.Json.JsonConverter(typeof(JObjectDictionaryToObjectDictionaryConverter))]
public Dictionary<string, object> GlobalMetadata { get; set; }

/// <summary>
Expand All @@ -39,11 +43,13 @@ internal class MergeJsonItemConfig
/// The value is the value of the metadata.
/// </summary>
[JsonProperty("fileMetadata")]
[JsonPropertyName("fileMetadata")]
public Dictionary<string, FileMetadataPairs> FileMetadata { get; set; }

/// <summary>
/// Metadata that applies to toc files.
/// </summary>
[JsonProperty("tocMetadata")]
[JsonPropertyName("tocMetadata")]
public ListWithStringFallback TocMetadata { get; set; }
}
Loading

0 comments on commit 893f794

Please sign in to comment.