mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
add json schema and schema generator
This commit is contained in:
parent
db13f68846
commit
c5bf1157f6
8 changed files with 186 additions and 15 deletions
|
|
@ -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}
|
||||
|
|
|
|||
109
data/schema/List.json
Normal file
109
data/schema/List.json
Normal file
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
36
data/schema/TableCsv.json
Normal file
36
data/schema/TableCsv.json
Normal file
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.4" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
35
src/FilterLists.Data/Schema/JsonSchemaGenerator.cs
Normal file
35
src/FilterLists.Data/Schema/JsonSchemaGenerator.cs
Normal file
|
|
@ -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<Type> GetTypesInNamespace(Assembly assembly, string @namespace)
|
||||
{
|
||||
return assembly.GetTypes().Where(t => string.Equals(t.Namespace, @namespace, StringComparison.Ordinal));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<ITableService>();
|
||||
tableService.UpdateTables();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue