Skip to content

Commit

Permalink
Merge pull request #995 from christianhelle/renovate/refitter.core-1.x
Browse files Browse the repository at this point in the history
Update dependency Refitter.Core to 1.3.2
  • Loading branch information
christianhelle authored Sep 30, 2024
2 parents 4aeaa97 + 0885ae0 commit c6af0a6
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 33 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The output file is the result of merging all the files generated using the Swagg
- ***AutoRestCodeGenerator*** - Generates a single file C# REST API Client using **AutoRest v3.0.0-beta.20210504.2** for OpenAPI v3 and **AutoRest v2.0.4417** for OpenAPI v2. The resulting file is the equivalent of using the AutoRest CLI tool with:
`--csharp --input-file=[swagger file] --output-file=[output file] --namespace=[default namespace] --add-credentials`

- ***RefitterCodeGenerator*** - Generates a single file C# REST API Client inteface for [Refit](https://github.com/reactiveui/refit) using [Refitter.Core](https://github.com/christianhelle/refitter) [nuget package](https://www.nuget.org/packages/Refitter.Core/) **v1.3.0**.
- ***RefitterCodeGenerator*** - Generates a single file C# REST API Client inteface for [Refit](https://github.com/reactiveui/refit) using [Refitter.Core](https://github.com/christianhelle/refitter) [nuget package](https://www.nuget.org/packages/Refitter.Core/) **v1.3.2**.
The output file contains a Refit interface generated by [Refitter](https://github.com/christianhelle/refitter) and contracts generated using [NSwag.CodeGeneration.CSharp](https://github.com/RSuter/NSwag/wiki/CSharpClientGenerator) [nuget package](https://www.nuget.org/packages/NSwag.CodeGeneration.CSharp/)

### Dependencies
Expand Down Expand Up @@ -309,7 +309,7 @@ Commands:
kiota Microsoft Kiota (v1.18.0)
nswag NSwag (v14.1.0)
openapi OpenAPI Generator (v7.8.0)
refitter Refitter (v1.3.0)
refitter Refitter (v1.3.2)
swagger Swagger Codegen CLI (v3.0.34)
Run 'csharp [command] -?|-h|--help' for more information about a command.
Expand Down
2 changes: 1 addition & 1 deletion docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Commands:
kiota Microsoft Kiota (v1.18.0)
nswag NSwag (v14.1.0)
openapi OpenAPI Generator (v7.8.0)
refitter Refitter (v1.3.0)
refitter Refitter (v1.3.2)
swagger Swagger Codegen CLI (v3.0.34)

Run 'csharp [command] -?|-h|--help' for more information about a command.
Expand Down
2 changes: 1 addition & 1 deletion docs/Marketplace.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The output file is the result of merging all the files generated using the Swagg
- ***AutoRestCodeGenerator*** - Generates a single file C# REST API Client using **AutoRest v3.0.0-beta.20210504.2** for OpenAPI v3 and **AutoRest v2.0.4417** for OpenAPI v2. The resulting file is the equivalent of using the AutoRest CLI tool with:
`--csharp --input-file=[swagger file] --output-file=[output file] --namespace=[default namespace] --add-credentials`

- ***RefitterCodeGenerator*** - Generates a single file C# REST API Client inteface for [Refit](https://github.com/reactiveui/refit) using [Refitter.Core](https://github.com/christianhelle/refitter) [nuget package](https://www.nuget.org/packages/Refitter.Core/) **v1.3.0**.
- ***RefitterCodeGenerator*** - Generates a single file C# REST API Client inteface for [Refit](https://github.com/reactiveui/refit) using [Refitter.Core](https://github.com/christianhelle/refitter) [nuget package](https://www.nuget.org/packages/Refitter.Core/) **v1.3.2**.
The output file contains a Refit interface generated by [Refitter](https://github.com/christianhelle/refitter) and contracts generated using [NSwag.CodeGeneration.CSharp](https://github.com/RSuter/NSwag/wiki/CSharpClientGenerator) [nuget package](https://www.nuget.org/packages/NSwag.CodeGeneration.CSharp/)

### Dependencies
Expand Down
2 changes: 1 addition & 1 deletion docs/Marketplace2022.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The output file is the result of merging all the files generated using the Swagg
- ***AutoRestCodeGenerator*** - Generates a single file C# REST API Client using **AutoRest v3.0.0-beta.20210504.2** for OpenAPI v3 and **AutoRest v2.0.4417** for OpenAPI v2. The resulting file is the equivalent of using the AutoRest CLI tool with:
`--csharp --input-file=[swagger file] --output-file=[output file] --namespace=[default namespace] --add-credentials`

- ***RefitterCodeGenerator*** - Generates a single file C# REST API Client inteface for [Refit](https://github.com/reactiveui/refit) using [Refitter.Core](https://github.com/christianhelle/refitter) [nuget package](https://www.nuget.org/packages/Refitter.Core/) **v1.3.0**.
- ***RefitterCodeGenerator*** - Generates a single file C# REST API Client inteface for [Refit](https://github.com/reactiveui/refit) using [Refitter.Core](https://github.com/christianhelle/refitter) [nuget package](https://www.nuget.org/packages/Refitter.Core/) **v1.3.2**.
The output file contains a Refit interface generated by [Refitter](https://github.com/christianhelle/refitter) and contracts generated using [NSwag.CodeGeneration.CSharp](https://github.com/RSuter/NSwag/wiki/CSharpClientGenerator) [nuget package](https://www.nuget.org/packages/NSwag.CodeGeneration.CSharp/)

### Dependencies
Expand Down
2 changes: 1 addition & 1 deletion docs/VisualStudioForMac.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The output file is the result of merging all the files generated using the Swagg
The resulting file is the equivalent of using the AutoRest CLI tool with:+
`--csharp --input-file=[swagger file] --output-file=[output file] --namespace=[default namespace] --add-credentials`

- ***RefitterCodeGenerator*** - Generates a single file C# REST API Client inteface for [Refit](https://github.com/reactiveui/refit) using [Refitter.Core](https://github.com/christianhelle/refitter) [nuget package](https://www.nuget.org/packages/Refitter.Core/) **v1.3.0**.
- ***RefitterCodeGenerator*** - Generates a single file C# REST API Client inteface for [Refit](https://github.com/reactiveui/refit) using [Refitter.Core](https://github.com/christianhelle/refitter) [nuget package](https://www.nuget.org/packages/Refitter.Core/) **v1.3.2**.
The output file contains a Refit interface generated by [Refitter](https://github.com/christianhelle/refitter) and contracts generated using [NSwag.CodeGeneration.CSharp](https://github.com/RSuter/NSwag/wiki/CSharpClientGenerator) [nuget package](https://www.nuget.org/packages/NSwag.CodeGeneration.CSharp/)

### Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Rapicgen.CLI.Commands.CSharp;

[Command("refitter", Description = "Refitter (v1.3.0)")]
[Command("refitter", Description = "Refitter (v1.3.2)")]
public class RefitterCommand : CodeGeneratorCommand
{
private readonly IRefitterCodeGeneratorFactory factory;
Expand Down Expand Up @@ -86,4 +86,11 @@ public bool NoOperationHeaders
get => !options.GenerateHeaderParameters;
set => options.GenerateHeaderParameters = !value;
}

[Option(ShortName = "mf", LongName = "multiple-files", Description = "Generate multiple files")]
public bool GenerateMultipleFiles
{
get => options.GenerateMultipleFiles;
set => options.GenerateMultipleFiles = value;
}
}
6 changes: 6 additions & 0 deletions src/CLI/ApiClientCodeGen.CLI/Commands/CodeGeneratorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public int OnExecute()

var generator = CreateGenerator();
var code = generator.GenerateCode(progressReporter);
if (string.IsNullOrWhiteSpace(code))
{
console.WriteSignature();
return ResultCodes.Success;
}

File.WriteAllText(OutputFile, code);

var fileInfo = new FileInfo(OutputFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PackageReference Include="NSwag.Core.Yaml" Version="14.1.0" />
<PackageReference Include="NSwag.CodeGeneration.CSharp" Version="14.1.0" />
<PackageReference Include="Polly" Version="8.4.2" />
<PackageReference Include="Refitter.Core" Version="1.3.0" />
<PackageReference Include="Refitter.Core" Version="1.3.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public string GenerateCode(IProgressReporter? pGenerateProgress)
var refitterFile = fileInfo.Name.Replace(fileInfo.Extension, ".refitter");
if (File.Exists(refitterFile))
{
settings = Serializer
.Deserialize<RefitGeneratorSettings>(
File.ReadAllText(refitterFile));
settings = Serializer.Deserialize<RefitGeneratorSettings>(
File.ReadAllText(refitterFile)
);
}
else
{
Expand All @@ -60,7 +60,8 @@ public string GenerateCode(IProgressReporter? pGenerateProgress)
GenerateXmlDocCodeComments = options.GenerateXmlDocCodeComments,
ReturnIApiResponse = options.ReturnIApiResponse,
UseCancellationTokens = options.UseCancellationTokens,
GenerateOperationHeaders = options.GenerateHeaderParameters
GenerateOperationHeaders = options.GenerateHeaderParameters,
GenerateMultipleFiles = options.GenerateMultipleFiles
};

File.WriteAllText(
Expand All @@ -82,16 +83,8 @@ public string GenerateCode(IProgressReporter? pGenerateProgress)

pGenerateProgress?.Progress(50);
using var context = new DependencyContext("Refitter", Serialize(settings));
var code = generator.Generate();
context.Succeeded();

pGenerateProgress?.Progress(90);
var output = GeneratedCode.PrefixAutogeneratedCodeHeader(
code,
"Refitter",
"v1.3.0");

if (inputFile.EndsWith(".refitter"))
if (settings.GenerateMultipleFiles)
{
var fileInfo = new FileInfo(inputFile);
var outputFolder = fileInfo.Directory.FullName;
Expand All @@ -104,14 +97,43 @@ public string GenerateCode(IProgressReporter? pGenerateProgress)
}
}

File.WriteAllText(
Path.Combine(
outputFolder,
fileInfo.Name.Replace(fileInfo.Extension, ".cs")),
output);
var results = generator.GenerateMultipleFiles();
foreach (var file in results.Files)
{
File.WriteAllText(Path.Combine(outputFolder, file.Filename), file.Content);
}

return string.Empty;
}
else
{
var code = generator.Generate();
context.Succeeded();

pGenerateProgress?.Progress(90);
var output = GeneratedCode.PrefixAutogeneratedCodeHeader(code, "Refitter", "v1.3.2");

return output;
if (inputFile.EndsWith(".refitter"))
{
var fileInfo = new FileInfo(inputFile);
var outputFolder = fileInfo.Directory.FullName;
if (settings.OutputFolder != RefitGeneratorSettings.DefaultOutputFolder)
{
outputFolder = Path.Combine(outputFolder, settings.OutputFolder);
if (!Directory.Exists(outputFolder))
{
Directory.CreateDirectory(outputFolder);
}
}

File.WriteAllText(
Path.Combine(outputFolder, fileInfo.Name.Replace(fileInfo.Extension, ".cs")),
output
);
}

return output;
}
}

private static string Serialize(RefitGeneratorSettings settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public class DefaultRefitterOptions : IRefitterOptions
public bool GenerateInternalTypes { get; set; }
public bool UseCancellationTokens { get; set; }
public bool GenerateHeaderParameters { get; set; } = true;
public bool GenerateMultipleFiles { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public interface IRefitterOptions
bool GenerateInternalTypes { get; set; }
bool UseCancellationTokens { get; set; }
bool GenerateHeaderParameters { get; set; }
bool GenerateMultipleFiles { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/VSIX/ApiClientCodeGen.VSIX.Dev17/VSCommandTable.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</Button>
<Button guid="guidPackageCmdSet" id="RefitterCodeGeneratorCustomToolSetter" priority="0x0105" type="Button">
<Strings>
<ButtonText>Generate with Refitter (v1.3.0)</ButtonText>
<ButtonText>Generate with Refitter (v1.3.2)</ButtonText>
</Strings>
</Button>

Expand Down Expand Up @@ -119,7 +119,7 @@
</Button>
<Button guid="guidNewRestApiClientCmdSet" id="GenerateWithRefitter" priority="0x0106" type="Button">
<Strings>
<ButtonText>Generate with Refitter (v1.3.0)</ButtonText>
<ButtonText>Generate with Refitter (v1.3.2)</ButtonText>
</Strings>
</Button>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public RefitterOptions(IRefitterOptions? options = null)
GenerateInternalTypes = options.GenerateInternalTypes;
UseCancellationTokens = options.UseCancellationTokens;
GenerateHeaderParameters = options.GenerateHeaderParameters;
GenerateMultipleFiles = options.GenerateMultipleFiles;
}
catch (Exception e)
{
Expand All @@ -40,5 +41,6 @@ public RefitterOptions(IRefitterOptions? options = null)
public bool GenerateInternalTypes { get; set; }
public bool UseCancellationTokens { get; set; }
public bool GenerateHeaderParameters { get; set; }
public bool GenerateMultipleFiles { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@ public class RefitterOptionsPage : DialogPage, IRefitterOptions
[DisplayName("Generate Header Parameters")]
[Description("Set this to TRUE to generate [Header] parameters (default: TRUE)")]
public bool GenerateHeaderParameters { get; set; } = true;

[Category(Name)]
[DisplayName("Generate Multiple Files")]
[Description("Set this to TRUE to generate multiple files (default: FALSE)")]
public bool GenerateMultipleFiles { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/VSIX/ApiClientCodeGen.VSIX/VSCommandTable.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</Button>
<Button guid="guidPackageCmdSet" id="RefitterCodeGeneratorCustomToolSetter" priority="0x0105" type="Button">
<Strings>
<ButtonText>Generate with Refitter (v1.3.0)</ButtonText>
<ButtonText>Generate with Refitter (v1.3.2)</ButtonText>
</Strings>
</Button>

Expand Down Expand Up @@ -119,7 +119,7 @@
</Button>
<Button guid="guidNewRestApiClientCmdSet" id="GenerateWithRefitter" priority="0x0106" type="Button">
<Strings>
<ButtonText>Generate with Refitter (v1.3.0)</ButtonText>
<ButtonText>Generate with Refitter (v1.3.2)</ButtonText>
</Strings>
</Button>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
defaultHandler="ApiClientCodeGen.VSMac.Commands.Handlers.AddNewKiotaCommandHandler" />

<Command id = "ApiClientCodeGen.VSMac.Commands.AddToProject.Refitter"
_label = "Generate with Refitter (v1.3.0)"
_label = "Generate with Refitter (v1.3.2)"
defaultHandler="ApiClientCodeGen.VSMac.Commands.Handlers.AddNewRefitterCommandHandler" />

<Command id = "ApiClientCodeGen.VSMac.Commands.AddToProject.Swagger"
Expand Down Expand Up @@ -72,7 +72,7 @@
defaultHandler="ApiClientCodeGen.VSMac.Commands.Handlers.GenerateKiotaCommandHandler" />

<Command id = "ApiClientCodeGen.VSMac.Commands.GenerateCode.Refitter"
_label = "Generate with Refitter (v1.3.0)"
_label = "Generate with Refitter (v1.3.2)"
defaultHandler="ApiClientCodeGen.VSMac.Commands.Handlers.GenerateRefitterCommandHandler" />

<Command id = "ApiClientCodeGen.VSMac.Commands.GenerateCode.Swagger"
Expand Down

0 comments on commit c6af0a6

Please sign in to comment.