Skip to content

Commit

Permalink
Allow specifying the schema path as a URL
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Mar 11, 2024
1 parent cb8d14c commit 87d92b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Bonsai.Sgen/Bonsai.Sgen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<PackageId>Bonsai.Sgen</PackageId>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<VersionPrefix>0.3.0</VersionPrefix>
<VersionPrefix>0.4.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
9 changes: 6 additions & 3 deletions Bonsai.Sgen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ static async Task Main(string[] args)
{
var schemaPath = new Option<FileInfo>(
name: "--schema",
description: "Generates serialization classes for data types in the specified schema file.")
description: "Specifies the URL or path to the JSON schema describing the data types " +
"for which to generate serialization classes.")
{ IsRequired = !Console.IsInputRedirected };
var generatorNamespace = new Option<string?>(
name: "--namespace",
Expand Down Expand Up @@ -42,7 +43,7 @@ static async Task Main(string[] args)
rootCommand.AddOption(generatorTypeName);
rootCommand.AddOption(outputPath);
rootCommand.AddOption(serializerLibraries);
rootCommand.SetHandler(async (filePath, generatorNamespace, generatorTypeName, outputFilePath, serializerLibraries) =>
rootCommand.SetHandler(async (schemaPath, generatorNamespace, generatorTypeName, outputFilePath, serializerLibraries) =>
{
JsonSchema schema;
if (Console.IsInputRedirected)
Expand All @@ -52,7 +53,9 @@ static async Task Main(string[] args)
}
else
{
schema = await JsonSchema.FromFileAsync(filePath.FullName);
schema = Uri.IsWellFormedUriString(schemaPath.FullName, UriKind.Absolute)
? await JsonSchema.FromUrlAsync(schemaPath.FullName)
: await JsonSchema.FromFileAsync(schemaPath.FullName);
}
if (string.IsNullOrEmpty(generatorTypeName))
Expand Down

0 comments on commit 87d92b3

Please sign in to comment.