Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
826 changes: 826 additions & 0 deletions specs/activity/schema/activity-protocol.schema.json

Large diffs are not rendered by default.

130 changes: 130 additions & 0 deletions specs/activity/schema/validator/csharp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
using NJsonSchema;
using NJsonSchema.Validation;
using Newtonsoft.Json.Linq;

static async Task<JsonSchema> LoadSchemaAsync(string schemaPath) => await JsonSchema.FromFileAsync(schemaPath);

string schemaFile = Path.Combine(AppContext.BaseDirectory, "activity.schema.json");
if (!File.Exists(schemaFile))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Schema file not found: {schemaFile}");
Console.ResetColor();
return;
}

// Discover example files relative to project root (navigate up to validator folder structure)
// Expect examples under ../examples/json
string? baseDir = AppContext.BaseDirectory;
// Try to locate examples directory by walking up a few levels
string? examplesDir = null;
var current = new DirectoryInfo(baseDir);
for (int i = 0; i < 6 && current != null; i++)
{
var probe = Path.Combine(current.FullName, "examples", "json");
if (Directory.Exists(probe)) { examplesDir = probe; break; }
current = current.Parent;
}

if (examplesDir == null)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Examples directory not found (expected ../examples/json). Will fall back to input.json if present.");
Console.ResetColor();
}

var schema = await LoadSchemaAsync(schemaFile);

List<(string name, JToken instance)> instances = new();

if (examplesDir != null)
{
foreach (var file in Directory.GetFiles(examplesDir, "*.json", SearchOption.TopDirectoryOnly).OrderBy(f => f))
{
try
{
var text = File.ReadAllText(file);
instances.Add((Path.GetFileName(file), JToken.Parse(text)));
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Failed to parse {file}: {ex.Message}");
Console.ResetColor();
}
}
}

// Backward compatibility: single input.json
string singleInput = Path.Combine(AppContext.BaseDirectory, "input.json");
if (File.Exists(singleInput))
{
try
{
instances.Add(("input.json", JToken.Parse(File.ReadAllText(singleInput))));
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("input.json parse error: " + ex.Message);
Console.ResetColor();
}
}

if (instances.Count == 0)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("No JSON instances found to validate.");
Console.ResetColor();
return;
}

int total = 0;
int failures = 0;

foreach (var (name, token) in instances)
{
total++;
var errors = schema.Validate(token);
if (errors.Count == 0)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"[OK] {name} ({token["type"] ?? "unknown-type"})");
Console.ResetColor();
}
else
{
failures++;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"[FAIL] {name} ({token["type"] ?? "unknown-type"}) - {errors.Count} error(s)");
Console.ResetColor();
int i = 1;
foreach (var e in errors)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($" [{i}] {e.Kind}");
Console.ResetColor();
Console.WriteLine($" Path : {(string.IsNullOrEmpty(e.Path) ? "$" : "$" + e.Path)}");
Console.WriteLine($" Detail : {e}");
if (!string.IsNullOrEmpty(e.Property))
Console.WriteLine($" Property: {e.Property}");
i++;
}
}
}

Console.WriteLine();
Console.WriteLine($"Summary: {total - failures} valid / {failures} invalid / {total} total");
if (failures == 0)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("All examples are valid.");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Some examples failed validation.");
Console.ResetColor();
Environment.ExitCode = 1;
}
14 changes: 14 additions & 0 deletions specs/activity/schema/validator/csharp/SchemaValidator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NJsonSchema" Version="11.5.0" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions specs/activity/schema/validator/csharp/SchemaValidator.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36414.22 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchemaValidator", "SchemaValidator.csproj", "{2F44ACFB-7A40-4433-8D58-476B682C7AF7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2F44ACFB-7A40-4433-8D58-476B682C7AF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F44ACFB-7A40-4433-8D58-476B682C7AF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F44ACFB-7A40-4433-8D58-476B682C7AF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F44ACFB-7A40-4433-8D58-476B682C7AF7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {833ED1E0-B359-4969-936C-1C5ED1B6803F}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36119.2 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyProject", "MyProject\MyProject.csproj", "{DC6AFA74-6604-4C88-BA06-9207526EC36D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DC6AFA74-6604-4C88-BA06-9207526EC36D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC6AFA74-6604-4C88-BA06-9207526EC36D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC6AFA74-6604-4C88-BA06-9207526EC36D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC6AFA74-6604-4C88-BA06-9207526EC36D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {55922005-71F0-4A91-A296-63361F368FE1}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace MyProject.Models
{
public class ActivityValidationResult
{
public bool IsValid { get; set; }
public List<string> Errors { get; set; } = new List<string>();
public string? ActivityType { get; set; }
public string? ValidationMessage { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Identity.Client" Version="4.73.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="4.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
</ItemGroup>

<ItemGroup>
<Content Include="activity_protocol.schema">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@MyProject_HostAddress = http://localhost:5285

GET {{MyProject_HostAddress}}/weatherforecast/
Accept: application/json

###
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:46155",
"sslPort": 44389
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5285",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7010;http://localhost:5285",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Loading