Skip to content

Commit ef82155

Browse files
Json schema generator (#50)
* add json schema generator * add props & targets, cli tool * fix incorrect type check in attribute factory implement enum hints * update pipeline * undo namespace cleanup * fix formatting * move from InternalsVisibleTo to public types * clean test app * do not delete schemata dir in cli tool * set tfm for publish project reference target to net9 * remove obsolete test app * add readme
1 parent 0dd1269 commit ef82155

File tree

16 files changed

+1122
-74
lines changed

16 files changed

+1122
-74
lines changed

JsonSchemaGenerator.Cli/JsonSchemaGenerator.Cli.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<RollForward>major</RollForward>

JsonSchemaGenerator.Cli/MainService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
5454
{
5555
stoppingToken.ThrowIfCancellationRequested();
5656

57-
if(Directory.Exists(settings.SchemataPath))
57+
if(!Directory.Exists(settings.SchemataPath))
5858
{
59-
Directory.Delete(settings.SchemataPath, recursive: true);
6059
_ = Directory.CreateDirectory(settings.SchemataPath);
6160
}
6261

JsonSchemaGenerator.NugetTestApp/JsonSchemaGenerator.NugetTestApp.csproj

Lines changed: 0 additions & 10 deletions
This file was deleted.

JsonSchemaGenerator.NugetTestApp/Program.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
namespace HelloWorld.MyNamespace;
2+
3+
using RhoMicro.CodeAnalysis;
4+
5+
[JsonSchema]
6+
class Foo15
7+
{
8+
public required Library.LibraryNamespace.Foo FooProperty { get; set; }
9+
}
10+
11+
[JsonSchema]
12+
class Foo14
13+
{
14+
public Double DoubleProperty { get; set; }
15+
public required String[] StringArrayProperty { get; set; }
16+
}
17+
18+
[JsonSchema]
19+
class Foo13
20+
{
21+
public Foo12 PocoReferenceProperty { get; set; } = new();
22+
}
23+
24+
class Foo12;
25+
26+
[JsonSchema]
27+
class Foo11
28+
{
29+
public Foo10 SchemaReferenceProperty { get; set; } = new();
30+
}
31+
32+
[JsonSchema]
33+
class Foo10;
34+
35+
enum MyEnum
36+
{
37+
None,
38+
First,
39+
Second = 42
40+
}
41+
42+
[JsonSchema]
43+
class Foo9
44+
{
45+
public MyEnum EnumProperty { get; set; }
46+
}
47+
48+
[JsonSchema]
49+
class Foo8
50+
{
51+
public required Object RequiredObjectProperty { get; set; }
52+
}
53+
54+
[JsonSchema]
55+
class Foo7
56+
{
57+
public Object? NullableObjectProperty { get; set; }
58+
}
59+
60+
[JsonSchema]
61+
class Foo6
62+
{
63+
public Int32? NullableInt32Property { get; set; }
64+
}
65+
66+
[JsonSchema]
67+
class Foo5
68+
{
69+
public DateTime DateTimeProperty { get; set; }
70+
public TimeSpan TimeSpanProperty { get; set; }
71+
public TimeOnly TimeOnlyProperty { get; set; }
72+
public DateOnly DateOnlyProperty { get; set; }
73+
public DateTimeOffset DateTimeOffsetProperty { get; set; }
74+
}
75+
76+
[JsonSchema]
77+
class Foo4
78+
{
79+
public Single SingleProperty { get; set; }
80+
public Double DoubleProperty { get; set; }
81+
public Decimal DecimalProperty { get; set; }
82+
public SByte SByteProperty { get; set; }
83+
public Int16 Int16Property { get; set; }
84+
public Int32 Int32Property { get; set; }
85+
public Int64 Int64Property { get; set; }
86+
public Byte ByteProperty { get; set; }
87+
public UInt16 UInt16Property { get; set; }
88+
public UInt32 UInt32Property { get; set; }
89+
public UInt64 UInt64Property { get; set; }
90+
public Boolean BooleanProperty { get; set; }
91+
public String StringProperty { get; set; } = String.Empty;
92+
public Object ObjectProperty { get; set; } = new();
93+
}
94+
95+
[JsonSchema]
96+
class Foo3
97+
{
98+
public IDictionary<String, Int32> IDictionaryProperty { get; set; } = new Dictionary<String, Int32>();
99+
public IReadOnlyDictionary<String, Int32> IReadOnlyDictionaryProperty { get; set; } = new Dictionary<String, Int32>();
100+
public Dictionary<String, Int32> DictionaryProperty { get; set; } = [];
101+
}
102+
103+
[JsonSchema]
104+
class Foo2
105+
{
106+
public Int32[] ArrayProperty { get; set; } = [];
107+
public ISet<Int32> ISetProperty { get; set; } = new HashSet<Int32>();
108+
public IReadOnlySet<Int32> IReadOnlySetProperty { get; set; } = new HashSet<Int32>();
109+
public HashSet<Int32> HashSetProperty { get; set; } = [];
110+
public List<Int32> ListProperty { get; set; } = [];
111+
}
112+
113+
[JsonSchema]
114+
class Foo1
115+
{
116+
public Int32 Int32Property { get; set; }
117+
}

JsonSchemaGenerator.Tests/NuGetTests/HelloWorld/HelloWorld.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<ImportDirectoryBuildProps>false</ImportDirectoryBuildProps>

JsonSchemaGenerator.Tests/NuGetTests/HelloWorld/Settings.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
{
2-
"$schema": "./appsettings.schema.json",
3-
"Settings": {
4-
"Prop":{
5-
"Prop": "ds"
6-
}
7-
}
2+
"$schema": "./appsettings.schema.json"
83
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"properties": {
3-
"Settings": {
4-
"$ref": "./bin/Debug/net6.0/JsonSchemata/HelloWorld/HelloWorldConfiguration/Settings.json"
3+
"Foo": {
4+
"$ref": "./bin/Debug/net9.0/JsonSchemata/HelloWorld/HelloWorld/MyNamespace/Foo14.json"
55
}
66
}
77
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma warning disable
2+
namespace Library.LibraryNamespace;
3+
4+
using RhoMicro.CodeAnalysis;
5+
6+
[JsonSchema]
7+
public class Foo
8+
{
9+
public Int32 Int32Property { get; set; }
10+
}

0 commit comments

Comments
 (0)