diff --git a/FilterLists.sln b/FilterLists.sln index ed59961a5..a07ce0f53 100644 --- a/FilterLists.sln +++ b/FilterLists.sln @@ -2,17 +2,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27004.2005 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{E2F4C0A9-CA4D-4A11-8B10-899513E777F8}" - ProjectSection(SolutionItems) = preProject - scripts\build.sh = scripts\build.sh - scripts\deploy.sh = scripts\deploy.sh - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "deploy", "deploy", "{6EF78534-FCFD-4918-91AA-316D8AA951AA}" - ProjectSection(SolutionItems) = preProject - .travis.yml = .travis.yml - EndProjectSection -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E7590A2B-621D-47EA-B026-315793F0FE50}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FilterLists.Api", "src\FilterLists.Api\FilterLists.Api.csproj", "{57E4CE18-41F3-48F6-B142-12947FFBA86C}" @@ -70,7 +59,6 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {E2F4C0A9-CA4D-4A11-8B10-899513E777F8} = {6EF78534-FCFD-4918-91AA-316D8AA951AA} {57E4CE18-41F3-48F6-B142-12947FFBA86C} = {E7590A2B-621D-47EA-B026-315793F0FE50} {944ADE8F-18E3-4DB8-9098-6A55E026EAC1} = {E7590A2B-621D-47EA-B026-315793F0FE50} {B507EE76-B035-45D7-9D26-DF38A5013BC3} = {E7590A2B-621D-47EA-B026-315793F0FE50} diff --git a/data/List.csv b/data/data/List.csv similarity index 100% rename from data/List.csv rename to data/data/List.csv diff --git a/data/lists.json b/data/data/List.json similarity index 100% rename from data/lists.json rename to data/data/List.json diff --git a/data/schema/List.json b/data/schema/List.json new file mode 100644 index 000000000..56d7fa2b1 --- /dev/null +++ b/data/schema/List.json @@ -0,0 +1,109 @@ +{ + "type": "object", + "properties": { + "Name": { + "type": [ + "string", + "null" + ], + "maxLength": 126 + }, + "ViewUrl": { + "type": "string", + "minLength": 6, + "maxLength": 2083 + }, + "HomeUrl": { + "type": [ + "string", + "null" + ], + "minLength": 6, + "maxLength": 2083 + }, + "Description": { + "type": [ + "string", + "null" + ], + "maxLength": 1022 + }, + "DescriptionSourceUrl": { + "type": [ + "string", + "null" + ], + "minLength": 6, + "maxLength": 2083 + }, + "Author": { + "type": [ + "string", + "null" + ], + "maxLength": 126 + }, + "ForumUrl": { + "type": [ + "string", + "null" + ], + "minLength": 6, + "maxLength": 2083 + }, + "IssuesUrl": { + "type": [ + "string", + "null" + ], + "minLength": 6, + "maxLength": 2083 + }, + "Email": { + "type": [ + "string", + "null" + ], + "minLength": 7, + "maxLength": 126 + }, + "DonateUrl": { + "type": [ + "string", + "null" + ], + "minLength": 6, + "maxLength": 2083 + }, + "Id": { + "type": "integer" + }, + "AddedDateUtc": { + "type": "string", + "default": "CURRENT_TIMESTAMP", + "format": "date-time" + }, + "ModifiedDateUtc": { + "type": [ + "string", + "null" + ], + "format": "date-time" + } + }, + "required": [ + "Name", + "ViewUrl", + "HomeUrl", + "Description", + "DescriptionSourceUrl", + "Author", + "ForumUrl", + "IssuesUrl", + "Email", + "DonateUrl", + "Id", + "AddedDateUtc", + "ModifiedDateUtc" + ] +} \ No newline at end of file diff --git a/data/schema/TableCsv.json b/data/schema/TableCsv.json new file mode 100644 index 000000000..3aa18c3e4 --- /dev/null +++ b/data/schema/TableCsv.json @@ -0,0 +1,36 @@ +{ + "type": "object", + "properties": { + "Name": { + "type": "string", + "maxLength": 126 + }, + "Url": { + "type": "string", + "minLength": 6, + "maxLength": 2083 + }, + "Id": { + "type": "integer" + }, + "AddedDateUtc": { + "type": "string", + "default": "CURRENT_TIMESTAMP", + "format": "date-time" + }, + "ModifiedDateUtc": { + "type": [ + "string", + "null" + ], + "format": "date-time" + } + }, + "required": [ + "Name", + "Url", + "Id", + "AddedDateUtc", + "ModifiedDateUtc" + ] +} \ No newline at end of file diff --git a/src/FilterLists.Data/FilterLists.Data.csproj b/src/FilterLists.Data/FilterLists.Data.csproj index 4a8762212..132a5a25a 100644 --- a/src/FilterLists.Data/FilterLists.Data.csproj +++ b/src/FilterLists.Data/FilterLists.Data.csproj @@ -8,6 +8,7 @@ + diff --git a/src/FilterLists.Data/Schema/JsonSchemaGenerator.cs b/src/FilterLists.Data/Schema/JsonSchemaGenerator.cs new file mode 100644 index 000000000..d02f10d18 --- /dev/null +++ b/src/FilterLists.Data/Schema/JsonSchemaGenerator.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using FilterLists.Data.Models.Implementations; +using Newtonsoft.Json.Schema.Generation; + +namespace FilterLists.Data.Schema +{ + public static class JsonSchemaGenerator + { + public static void WriteSchemaToFiles() + { + foreach (var type in GetTypesInNamespace(Assembly.GetExecutingAssembly(), + "FilterLists.Data.Models.Implementations")) + { + if (type == typeof(BaseEntity)) continue; + WriteSchemaToFile(type); + } + } + + private static void WriteSchemaToFile(Type type) + { + File.WriteAllText( + Path.GetFullPath(Path.Combine(AppContext.BaseDirectory + @"\", @"..\..\..\..\..\data\schema\")) + + type.Name + ".json", new JSchemaGenerator().Generate(type).ToString()); + } + + private static IEnumerable GetTypesInNamespace(Assembly assembly, string @namespace) + { + return assembly.GetTypes().Where(t => string.Equals(t.Namespace, @namespace, StringComparison.Ordinal)); + } + } +} \ No newline at end of file diff --git a/src/FilterLists.DataLoad/Program.cs b/src/FilterLists.DataLoad/Program.cs index 76f6a9403..544733a6f 100644 --- a/src/FilterLists.DataLoad/Program.cs +++ b/src/FilterLists.DataLoad/Program.cs @@ -1,4 +1,5 @@ -using FilterLists.Services.Contracts; +using FilterLists.Data.Schema; +using FilterLists.Services.Contracts; using Microsoft.Extensions.DependencyInjection; namespace FilterLists.DataLoad @@ -9,10 +10,11 @@ public class Program public static void Main(string[] args) { IServiceCollection services = new ServiceCollection(); - var startup = new Startup(); - startup.ConfigureServices(services); + new Startup().ConfigureServices(services); var serviceProvider = services.BuildServiceProvider(); + JsonSchemaGenerator.WriteSchemaToFiles(); + var tableService = serviceProvider.GetService(); tableService.UpdateTables(); }