diff --git a/data/ListSample.json b/data/ListSample.json new file mode 100644 index 000000000..f72bb43df --- /dev/null +++ b/data/ListSample.json @@ -0,0 +1,15 @@ +{ + "Author": "John Doe", + "Description": "A sample list to filter out advertisements.", + "DescriptionSourceUrl": "https://mysample.list", + "DonateUrl": "https://mysample.list/donate/", + "Email": "contact@mysample.list", + "ForumUrl": "https://mysample.list/forum/", + "HomeUrl": "https://mysample.list/", + "IssuesUrl": "https://github.com/mysamplelist/issues", + "Name": "My Sample List", + "ViewUrl": "https://mysample.list/list.txt", + "Id": 0, + "AddedDateUtc": "0001-01-01T00:00:00", + "ModifiedDateUtc": null +} \ No newline at end of file diff --git a/data/ListSchema.json b/data/ListSchema.json index 43ad2d309..9486ab2ad 100644 --- a/data/ListSchema.json +++ b/data/ListSchema.json @@ -1,31 +1,14 @@ { "type": "object", "properties": { - "Name": { - "description": "The name of the list as stated by the list maintainer(s) in title case.", + "Author": { + "description": "The author (person or group) who maintains the list.", "type": [ "string", "null" ], "maxLength": 126 }, - "ViewUrl": { - "description": "The URL to the list in raw text format. zip files and other formats are acceptable if no text format is available.", - "type": "string", - "minLength": 6, - "maxLength": 2083, - "format": "uri" - }, - "HomeUrl": { - "description": "The URL to the list's home page. Preferably, this is stated in the header of the list. Alternatively, it could be a custom domain, GitHub page, blog post, forum post, etc. that serves as a primary source of information for the list.", - "type": [ - "string", - "null" - ], - "minLength": 6, - "maxLength": 2083, - "format": "uri" - }, "Description": { "description": "A brief description of the list's functionality. Preferably, this is quoted (if non-English, translate to English via translator or Google Translate for consistency) from the list's documentation or composed by a maintainer of the list. If neither are available, a generic description should be composed by the FilterLists contributor.", "type": [ @@ -44,12 +27,23 @@ "maxLength": 2083, "format": "uri" }, - "Author": { - "description": "The author (person or group) who maintains the list.", + "DonateUrl": { + "description": "The URL to the list's donation page. This could be a custom PayPal or similar link, or a link to a web page discussing various donation options. Pull requests that include changes to this link will undergo further verification to prevent fraud.", "type": [ "string", "null" ], + "minLength": 6, + "maxLength": 2083, + "format": "uri" + }, + "Email": { + "description": "The email address of the list's maintainer(s) if publicly available.", + "type": [ + "string", + "null" + ], + "minLength": 7, "maxLength": 126 }, "ForumUrl": { @@ -62,6 +56,16 @@ "maxLength": 2083, "format": "uri" }, + "HomeUrl": { + "description": "The URL to the list's home page. Preferably, this is stated in the header of the list. Alternatively, it could be a custom domain, GitHub page, blog post, forum post, etc. that serves as a primary source of information for the list.", + "type": [ + "string", + "null" + ], + "minLength": 6, + "maxLength": 2083, + "format": "uri" + }, "IssuesUrl": { "description": "The URL to the list's GitHub Issues.", "type": [ @@ -72,21 +76,17 @@ "maxLength": 2083, "format": "uri" }, - "Email": { - "description": "The email address of the list's maintainer(s) if publicly available.", + "Name": { + "description": "The name of the list as stated by the list maintainer(s) in title case.", "type": [ "string", "null" ], - "minLength": 7, "maxLength": 126 }, - "DonateUrl": { - "description": "The URL to the list's donation page. This could be a custom PayPal or similar link, or a link to a web page discussing various donation options. Pull requests that include changes to this link will undergo further verification to prevent fraud.", - "type": [ - "string", - "null" - ], + "ViewUrl": { + "description": "The URL to the list in raw text format. zip files and other formats are acceptable if no text format is available.", + "type": "string", "minLength": 6, "maxLength": 2083, "format": "uri" @@ -108,16 +108,16 @@ } }, "required": [ - "Name", - "ViewUrl", - "HomeUrl", + "Author", "Description", "DescriptionSourceUrl", - "Author", - "ForumUrl", - "IssuesUrl", - "Email", "DonateUrl", + "Email", + "ForumUrl", + "HomeUrl", + "IssuesUrl", + "Name", + "ViewUrl", "Id", "AddedDateUtc", "ModifiedDateUtc" diff --git a/src/FilterLists.Api/Program.cs b/src/FilterLists.Api/Program.cs index b345e41ce..9bf656fc9 100644 --- a/src/FilterLists.Api/Program.cs +++ b/src/FilterLists.Api/Program.cs @@ -1,4 +1,4 @@ -using FilterLists.Data.Schema; +using FilterLists.Data.Json; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; @@ -8,7 +8,8 @@ public class Program { public static void Main(string[] args) { - JsonSchemaGenerator.WriteSchemaToFiles(); + JsonSchemaGenerator.WriteSchemaToFile(); + JsonSampleGenerator.WriteSampleToFile(); BuildWebHost(args).Run(); } diff --git a/src/FilterLists.Data/Json/JsonSampleGenerator.cs b/src/FilterLists.Data/Json/JsonSampleGenerator.cs new file mode 100644 index 000000000..e8fa13232 --- /dev/null +++ b/src/FilterLists.Data/Json/JsonSampleGenerator.cs @@ -0,0 +1,29 @@ +using System; +using System.IO; +using FilterLists.Data.Models.Implementations; +using Newtonsoft.Json.Linq; + +namespace FilterLists.Data.Json +{ + public static class JsonSampleGenerator + { + public static void WriteSampleToFile() + { + File.WriteAllText( + Path.GetFullPath(Path.Combine(AppContext.BaseDirectory + @"\", @"..\..\..\..\..\data\")) + + "ListSample.json", ((JObject) JToken.FromObject(new List + { + Author = "John Doe", + Description = "A sample list to filter out advertisements.", + DescriptionSourceUrl = "https://mysample.list", + DonateUrl = "https://mysample.list/donate/", + Email = "contact@mysample.list", + ForumUrl = "https://mysample.list/forum/", + HomeUrl = "https://mysample.list/", + IssuesUrl = "https://github.com/mysamplelist/issues", + Name = "My Sample List", + ViewUrl = "https://mysample.list/list.txt" + })).ToString()); + } + } +} \ No newline at end of file diff --git a/src/FilterLists.Data/Json/JsonSchemaGenerator.cs b/src/FilterLists.Data/Json/JsonSchemaGenerator.cs new file mode 100644 index 000000000..3d95038a9 --- /dev/null +++ b/src/FilterLists.Data/Json/JsonSchemaGenerator.cs @@ -0,0 +1,17 @@ +using System; +using System.IO; +using FilterLists.Data.Models.Implementations; +using Newtonsoft.Json.Schema.Generation; + +namespace FilterLists.Data.Json +{ + public static class JsonSchemaGenerator + { + public static void WriteSchemaToFile() + { + File.WriteAllText( + Path.GetFullPath(Path.Combine(AppContext.BaseDirectory + @"\", @"..\..\..\..\..\data\")) + + "ListSchema.json", new JSchemaGenerator().Generate(typeof(List)).ToString()); + } + } +} \ No newline at end of file diff --git a/src/FilterLists.Data/Models/Contracts/IList.cs b/src/FilterLists.Data/Models/Contracts/IList.cs index caefb1472..b98686343 100644 --- a/src/FilterLists.Data/Models/Contracts/IList.cs +++ b/src/FilterLists.Data/Models/Contracts/IList.cs @@ -4,16 +4,16 @@ namespace FilterLists.Data.Models.Contracts { public interface IList { - string Name { get; set; } - string ViewUrl { get; set; } - string HomeUrl { get; set; } + string Author { get; set; } string Description { get; set; } string DescriptionSourceUrl { get; set; } - string Author { get; set; } - string ForumUrl { get; set; } - string IssuesUrl { get; set; } - string Email { get; set; } string DonateUrl { get; set; } + string Email { get; set; } + string ForumUrl { get; set; } + string HomeUrl { get; set; } + string IssuesUrl { get; set; } + string Name { get; set; } + string ViewUrl { get; set; } long Id { get; set; } DateTime AddedDateUtc { get; set; } DateTime? ModifiedDateUtc { get; set; } diff --git a/src/FilterLists.Data/Models/Implementations/List.cs b/src/FilterLists.Data/Models/Implementations/List.cs index 1da5f8d27..22b0e7e6a 100644 --- a/src/FilterLists.Data/Models/Implementations/List.cs +++ b/src/FilterLists.Data/Models/Implementations/List.cs @@ -6,6 +6,49 @@ namespace FilterLists.Data.Models.Implementations { public class List : BaseEntity, IList { + [Description(@"The author (person or group) who maintains the list.")] + [MaxLength(126)] + public string Author { get; set; } + + [Description(@"A brief description of the list's functionality. Preferably, this is quoted (if non-English, translate to English via translator or Google Translate for consistency) from the list's documentation or composed by a maintainer of the list. If neither are available, a generic description should be composed by the FilterLists contributor.")] + [MaxLength(1022)] + public string Description { get; set; } + + [Description(@"The URL to the list's documentation page from which the description was quoted if applicable.")] + [Url] + [MaxLength(2083)] + [MinLength(6)] + public string DescriptionSourceUrl { get; set; } + + [Description(@"The URL to the list's donation page. This could be a custom PayPal or similar link, or a link to a web page discussing various donation options. Pull requests that include changes to this link will undergo further verification to prevent fraud.")] + [Url] + [MaxLength(2083)] + [MinLength(6)] + public string DonateUrl { get; set; } + + [Description(@"The email address of the list's maintainer(s) if publicly available.")] + [MaxLength(126)] + [MinLength(7)] + public string Email { get; set; } + + [Description(@"The URL to the list's forum where issues, change requests, etc. are discussed.")] + [Url] + [MaxLength(2083)] + [MinLength(6)] + public string ForumUrl { get; set; } + + [Description(@"The URL to the list's home page. Preferably, this is stated in the header of the list. Alternatively, it could be a custom domain, GitHub page, blog post, forum post, etc. that serves as a primary source of information for the list.")] + [Url] + [MaxLength(2083)] + [MinLength(6)] + public string HomeUrl { get; set; } + + [Description(@"The URL to the list's GitHub Issues.")] + [Url] + [MaxLength(2083)] + [MinLength(6)] + public string IssuesUrl { get; set; } + [Description(@"The name of the list as stated by the list maintainer(s) in title case.")] [MaxLength(126)] public string Name { get; set; } @@ -16,48 +59,5 @@ public class List : BaseEntity, IList [MaxLength(2083)] [MinLength(6)] public string ViewUrl { get; set; } - - [Description(@"The URL to the list's home page. Preferably, this is stated in the header of the list. Alternatively, it could be a custom domain, GitHub page, blog post, forum post, etc. that serves as a primary source of information for the list.")] - [Url] - [MaxLength(2083)] - [MinLength(6)] - public string HomeUrl { get; set; } - - [Description(@"A brief description of the list's functionality. Preferably, this is quoted (if non-English, translate to English via translator or Google Translate for consistency) from the list's documentation or composed by a maintainer of the list. If neither are available, a generic description should be composed by the FilterLists contributor.")] - [MaxLength(1022)] - public string Description { get; set; } - - [Description(@"The URL to the list's documentation page from which the description was quoted if applicable.")] - [Url] - [MaxLength(2083)] - [MinLength(6)] - public string DescriptionSourceUrl { get; set; } - - [Description(@"The author (person or group) who maintains the list.")] - [MaxLength(126)] - public string Author { get; set; } - - [Description(@"The URL to the list's forum where issues, change requests, etc. are discussed.")] - [Url] - [MaxLength(2083)] - [MinLength(6)] - public string ForumUrl { get; set; } - - [Description(@"The URL to the list's GitHub Issues.")] - [Url] - [MaxLength(2083)] - [MinLength(6)] - public string IssuesUrl { get; set; } - - [Description(@"The email address of the list's maintainer(s) if publicly available.")] - [MaxLength(126)] - [MinLength(7)] - public string Email { get; set; } - - [Description(@"The URL to the list's donation page. This could be a custom PayPal or similar link, or a link to a web page discussing various donation options. Pull requests that include changes to this link will undergo further verification to prevent fraud.")] - [Url] - [MaxLength(2083)] - [MinLength(6)] - public string DonateUrl { get; set; } } } \ No newline at end of file diff --git a/src/FilterLists.Data/Schema/JsonSchemaGenerator.cs b/src/FilterLists.Data/Schema/JsonSchemaGenerator.cs deleted file mode 100644 index bd503b6f4..000000000 --- a/src/FilterLists.Data/Schema/JsonSchemaGenerator.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.IO; -using FilterLists.Data.Models.Implementations; -using Newtonsoft.Json.Schema.Generation; - -namespace FilterLists.Data.Schema -{ - public static class JsonSchemaGenerator - { - public static void WriteSchemaToFiles() - { - WriteSchemaToFile(typeof(List)); - } - - private static void WriteSchemaToFile(Type type) - { - File.WriteAllText( - Path.GetFullPath(Path.Combine(AppContext.BaseDirectory + @"\", @"..\..\..\..\..\data\")) + type.Name + - "Schema.json", new JSchemaGenerator().Generate(type).ToString()); - } - } -} \ No newline at end of file