Skip to content
Merged
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
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>

<PropertyGroup>
<VersionPrefix>2.33.0</VersionPrefix>
<PackageValidationBaselineVersion>2.32.0</PackageValidationBaselineVersion>
<VersionPrefix>2.34.0</VersionPrefix>
<PackageValidationBaselineVersion>2.33.0</PackageValidationBaselineVersion>
<LangVersion>13.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
4 changes: 4 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## 2.34.0

* Add `--no-http` command-line option to `fsdgencsharp` to omit HTTP code generation.

## 2.33.0

* Add `DeepClone` to `ServiceDto<T>`. It uses JSON serialization to create a deep copy of the object, though it can be overidden (code-generated DTOs may eventually do so).
Expand Down
34 changes: 22 additions & 12 deletions src/Facility.CodeGen.CSharp/CSharpGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public static int GenerateCSharp(CSharpGeneratorSettings settings) =>
/// <remarks>Use <c>true</c> to omit the <c>#if</c>.</remarks>
public string? JsonSourceGenerationCondition { get; set; }

/// <summary>
/// True if HTTP documentation should be omitted.
/// </summary>
public bool NoHttp { get; set; }

/// <summary>
/// Generates the C# output.
/// </summary>
Expand Down Expand Up @@ -103,28 +108,32 @@ public override CodeGenOutput GenerateOutput(ServiceInfo service)

var httpServiceInfo = HttpServiceInfo.Create(service);

foreach (var httpErrorSetInfo in httpServiceInfo.ErrorSets)
outputFiles.Add(GenerateHttpErrors(httpErrorSetInfo, context));

if (httpServiceInfo.AllMethods.Count != 0)
if (!NoHttp)
{
outputFiles.Add(GenerateHttpMapping(httpServiceInfo, context));
outputFiles.Add(GenerateHttpClient(httpServiceInfo, context));
outputFiles.Add(GenerateHttpHandler(httpServiceInfo, context));
foreach (var httpErrorSetInfo in httpServiceInfo.ErrorSets)
outputFiles.Add(GenerateHttpErrors(httpErrorSetInfo, context));

if (ShouldGenerateJsonSource)
if (httpServiceInfo.AllMethods.Count != 0)
{
outputFiles.Add(GenerateJsonSerializerContext(service, httpServiceInfo, context));
outputFiles.Add(GenerateJsonSerializer(service, context));
outputFiles.Add(GenerateHttpMapping(httpServiceInfo, context));
outputFiles.Add(GenerateHttpClient(httpServiceInfo, context));
outputFiles.Add(GenerateHttpHandler(httpServiceInfo, context));

if (ShouldGenerateJsonSource)
{
outputFiles.Add(GenerateJsonSerializerContext(service, httpServiceInfo, context));
outputFiles.Add(GenerateJsonSerializer(service, context));
}
}
}

var codeGenComment = CodeGenUtility.GetCodeGenComment(context.GeneratorName);
var patternsToClean = new[]
var patternsToClean = new List<CodeGenPattern>
{
new CodeGenPattern("*.g.cs", codeGenComment),
new CodeGenPattern("Http/*.g.cs", codeGenComment),
};
if (!NoHttp)
patternsToClean.Add(new CodeGenPattern("Http/*.g.cs", codeGenComment));
return new CodeGenOutput(outputFiles, patternsToClean);
}

Expand All @@ -142,6 +151,7 @@ public override void ApplySettings(FileGeneratorSettings settings)
SupportMessagePack = csharpSettings.SupportMessagePack;
SupportJsonSourceGeneration = csharpSettings.SupportJsonSourceGeneration;
JsonSourceGenerationCondition = csharpSettings.JsonSourceGenerationCondition;
NoHttp = csharpSettings.NoHttp;
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Facility.CodeGen.CSharp/CSharpGeneratorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ public sealed class CSharpGeneratorSettings : FileGeneratorSettings
/// </summary>
/// <remarks>Use <c>true</c> to omit the <c>#if</c>.</remarks>
public string? JsonSourceGenerationCondition { get; set; }

/// <summary>
/// True if HTTP documentation should be omitted.
/// </summary>
public bool NoHttp { get; set; }
}
3 changes: 3 additions & 0 deletions src/fsdgencsharp/FsdGenCSharpApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ internal sealed class FsdGenCSharpApp : CodeGeneratorApp
" Support JSON source generation.",
" --json-source-gen-if <condition>",
" The #if condition to use around generated JSON source.",
" --no-http",
" Omit HTTP code generation.",
];

protected override ServiceParser CreateParser() => new FsdParser(new FsdParserSettings { SupportsEvents = true });
Expand All @@ -50,5 +52,6 @@ protected override FileGeneratorSettings CreateSettings(ArgsReader args) =>
SupportMessagePack = args.ReadFlag("msgpack"),
SupportJsonSourceGeneration = args.ReadFlag("json-source-gen"),
JsonSourceGenerationCondition = args.ReadOption("json-source-gen-if"),
NoHttp = args.ReadFlag("no-http"),
};
}
34 changes: 34 additions & 0 deletions tests/Facility.CodeGen.CSharp.UnitTests/CSharpGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,40 @@ public void OverrideServiceNamespace()
}
}

[Test]
public void RespectsNoHttpOption()
{
var definition = "service TestApi { method foo {}: {} data Bar { prop: string; } }";
var parser = CreateParser();
var service = parser.ParseDefinition(new ServiceDefinitionText("TestApi.fsd", definition));
var generator = new CSharpGenerator { GeneratorName = nameof(CSharpGeneratorTests), NoHttp = true };
var output = generator.GenerateOutput(service);

var generatedFiles = output.Files.Select(x => x.Name).ToList();
var httpRelatedFiles = new List<string>
{
"Http/HttpClientTestApi.g.cs",
"Http/TestApiHttpHandler.g.cs",
"Http/TestApiHttpMapping.g.cs",
};

var expectedFiles = new List<string>
{
"BarDto.g.cs",
"ITestApi.g.cs",
"FooRequestDto.g.cs",
"FooResponseDto.g.cs",
"TestApiMethods.g.cs",
"DelegatingTestApi.g.cs",
};

foreach (var httpRelatedFile in httpRelatedFiles)
Assert.That(generatedFiles, Does.Not.Contain(httpRelatedFile));

foreach (var expectedFile in expectedFiles)
Assert.That(generatedFiles, Does.Contain(expectedFile));
}

[Test]
public void GenerateEnumStringConstants()
{
Expand Down
Loading