Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoRest Option Page #62

Merged
merged 17 commits into from
Oct 21, 2019
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
3 changes: 2 additions & 1 deletion src/ApiClientCodeGen.Tests/ApiClientCodeGen.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Converters\CSharpToVisualBasicLanguageConverterTests.cs" />
<None Include="Converters\CSharpToVisualBasicLanguageConverterTests.cs" />
<Compile Include="CustomTool\SingleFileCodeGeneratorTests.cs" />
<Compile Include="CustomTool\TestSingleFileCodeGenerator.cs" />
<Compile Include="Extensions\GetDependenciesTests.cs" />
Expand Down Expand Up @@ -381,6 +381,7 @@
<Compile Include="Options\CustomPathOptionsTests.cs" />
<Compile Include="Options\JavaPathProviderTests.cs" />
<Compile Include="Options\NSwagCSharpOptionsNullOptionsTests.cs" />
<Compile Include="Options\AutoRestOptionsTests.cs" />
<Compile Include="Options\NSwagCSharpOptionsTests.cs" />
<Compile Include="Options\NSwagStudioOptionsNullOptionsTests.cs" />
<Compile Include="Options\NSwagStudioOptionsTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Generators.OpenApi;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Generators.Swagger;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.AutoRest;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.General;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.NSwag;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand All @@ -26,6 +29,9 @@ public void Init()
mockFactory
.Setup(c => c.Create<IGeneralOptions, GeneralOptionPage>())
.Returns(Test.CreateDummy<IGeneralOptions>());
mockFactory
.Setup(c => c.Create<IAutoRestOptions, AutoRestOptionsPage>())
.Returns(Test.CreateDummy<IAutoRestOptions>());

sut = new CodeGeneratorFactory(mockFactory.Object);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using AutoFixture;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Generators.NSwag;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.NSwag;
using FluentAssertions;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Generators.NSwag;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.NSwag;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using Moq;
using System.IO;
using System.Threading.Tasks;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.NSwag;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.NSwagStudio;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Windows;

namespace ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Tests.Generators.NSwagStudio
{
Expand All @@ -20,8 +23,7 @@ public async Task InitAsync()
mock = new Mock<INSwagStudioOptions>();

await NSwagStudioFileHelper.CreateNSwagStudioFileAsync(
File.ReadAllText("Swagger.json"),
"https://petstore.swagger.io/v2/swagger.json",
new EnterOpenApiSpecDialogResult(File.ReadAllText("Swagger.json"), "Swagger", "https://petstore.swagger.io/v2/swagger.json"),
mock.Object);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AutoFixture;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Generators.OpenApi;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.General;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AutoFixture;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Generators.Swagger;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.General;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand Down
59 changes: 59 additions & 0 deletions src/ApiClientCodeGen.Tests/Options/AutoRestOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.AutoRest;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Tests.Options
{
[TestClass]
public class AutoRestOptionsTests
{
private IAutoRestOptions options;

[TestInitialize]
public void Init()
=> options = new Mock<IAutoRestOptions>().Object;

[TestMethod]
public void Reads_AddCredentials_From_Options()
=> new AutoRestOptions(options)
.AddCredentials
.Should()
.Be(options.AddCredentials);

[TestMethod]
public void Reads_ClientSideValidation_From_Options()
=> new AutoRestOptions(options)
.ClientSideValidation
.Should()
.Be(options.ClientSideValidation);

[TestMethod]
public void Reads_SyncMethods_From_Options()
=> new AutoRestOptions(options)
.SyncMethods
.Should()
.Be(options.SyncMethods);

[TestMethod]
public void Reads_UseDateTimeOffset_From_Options()
=> new AutoRestOptions(options)
.UseDateTimeOffset
.Should()
.Be(options.UseDateTimeOffset);

[TestMethod]
public void Reads_UseInternalConstructors_From_Options()
=> new AutoRestOptions(options)
.UseInternalConstructors
.Should()
.Be(options.UseInternalConstructors);

[TestMethod]
public void Reads_OverrideClientName_From_Options()
=> new AutoRestOptions(options)
.OverrideClientName
.Should()
.Be(options.OverrideClientName);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using AutoFixture;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.General;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AutoFixture;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.General;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AutoFixture;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.General;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.NSwag;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NJsonSchema.CodeGeneration.CSharp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.NSwag;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.NSwag;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.NSwagStudio;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NJsonSchema.CodeGeneration.CSharp;
Expand All @@ -9,10 +11,10 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Tests.Options
public class NSwagStudioOptionsNullOptionsTests
{
[TestMethod]
public void Extends_NSwagCSharpOptions()
public void Implements_INSwagStudioOptions()
=> typeof(NSwagStudioOptions)
.Should()
.BeAssignableTo<NSwagCSharpOptions>();
.BeAssignableTo<INSwagStudioOptions>();

[TestMethod]
public void Reads_InjectHttpClient_From_Options()
Expand Down
7 changes: 3 additions & 4 deletions src/ApiClientCodeGen.Tests/Options/NSwagStudioOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AutoFixture;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.NSwagStudio;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand All @@ -19,10 +18,10 @@ public void Init()
}

[TestMethod]
public void Extends_NSwagCSharpOptions()
public void Implements_INSwagStudioOptions()
=> typeof(NSwagStudioOptions)
.Should()
.BeAssignableTo<NSwagCSharpOptions>();
.BeAssignableTo<INSwagStudioOptions>();

[TestMethod]
public void Reads_InjectHttpClient_From_Options()
Expand Down
1 change: 1 addition & 0 deletions src/ApiClientCodeGen.Tests/Options/PathProviderTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.IO;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.General;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down
29 changes: 18 additions & 11 deletions src/ApiClientCodeGen.VSIX/ApiClientCodeGen.VSIX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,38 @@
<Compile Include="Generators\NSwag\NSwagCSharpCodeGenerator.cs" />
<Compile Include="Generators\NSwag\OpenApiDocumentFactory.cs" />
<Compile Include="NuGet\PackageDependencies.cs" />
<Compile Include="Options\CustomPathOptions.cs" />
<Compile Include="Options\IGeneralOptions.cs" />
<Compile Include="Options\INSwagOption.cs" />
<Compile Include="Options\INSwagStudioOptions.cs" />
<Compile Include="Options\AutoRest\AutoRestOptions.cs" />
<Compile Include="Options\AutoRest\AutoRestOptionsPage.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Options\AutoRest\IAutoRestOptions.cs" />
<Compile Include="Options\OptionsBase.cs" />
<Compile Include="Options\AutoRest\SyncMethodOptions.cs" />
<Compile Include="Options\General\CustomPathOptions.cs" />
<Compile Include="Options\General\IGeneralOptions.cs" />
<Compile Include="Options\NSwag\INSwagOption.cs" />
<Compile Include="Options\NSwagStudio\INSwagStudioOptions.cs" />
<Compile Include="Options\IOptionsFactory.cs" />
<Compile Include="Options\JavaPathProvider.cs" />
<Compile Include="Options\NSwagStudioOptions.cs" />
<Compile Include="Options\NSwagCSharpOptions.cs" />
<Compile Include="Options\General\JavaPathProvider.cs" />
<Compile Include="Options\NSwagStudio\NSwagStudioOptions.cs" />
<Compile Include="Options\NSwag\NSwagCSharpOptions.cs" />
<Compile Include="Generators\OpenApi\OpenApiCSharpCodeGenerator.cs" />
<Compile Include="Generators\ProcessHelper.cs" />
<Compile Include="Generators\Swagger\SwaggerCSharpCodeGenerator.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="NuGet\PackageDependency.cs" />
<Compile Include="NuGet\PackageDependencyListProvider.cs" />
<Compile Include="Options\NSwagOptionsPage.cs">
<Compile Include="Options\NSwag\NSwagOptionsPage.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Options\NSwagStudioOptionsPage.cs">
<Compile Include="Options\NSwagStudio\NSwagStudioOptionsPage.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Options\OptionsFactory.cs" />
<Compile Include="Options\GeneralOptionPage.cs">
<Compile Include="Options\General\GeneralOptionPage.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Options\PathProvider.cs" />
<Compile Include="Options\General\PathProvider.cs" />
<Compile Include="Utility\OutputWindow.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utility\OutputWindowTraceListener.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Extensions;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Generators.NSwagStudio;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.General;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.NSwag;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.NSwagStudio;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Windows;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
Expand Down Expand Up @@ -51,8 +54,7 @@ private async Task OnExecuteAsync(DTE dte, AsyncPackage package)
{
var outputNamespace = ProjectExtensions.GetActiveProject(dte)?.GetTopLevelNamespace();
contents = await NSwagStudioFileHelper.CreateNSwagStudioFileAsync(
result.OpenApiSpecification,
result.Url,
result,
new NSwagStudioOptions(),
outputNamespace);
filename = filename.Replace(".json", ".nswag");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Extensions;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Generators.NSwagStudio;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Options.General;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;
Expand Down
24 changes: 21 additions & 3 deletions src/ApiClientCodeGen.VSIX/Extensions/OpenApiDocumentExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
using System.Linq;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using NSwag;

namespace ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Extensions
{
public static class OpenApiDocumentExtensions
{
public static string GenerateClassName(this OpenApiDocument document)
=> string.IsNullOrWhiteSpace(document.Info?.Title)
public static string GenerateClassName(this OpenApiDocument document, bool useDocumentTitle = true)
{
try
{
if (!useDocumentTitle)
return new FileInfo(document.DocumentPath)
.Name
.Replace(".json", string.Empty);
}
catch (Exception e)
{
Trace.WriteLine("Unable to extract class name from document path: " + document.DocumentPath);
Trace.WriteLine(e);
}

return string.IsNullOrWhiteSpace(document.Info?.Title)
? "ApiClient"
: $"{GetSanitizeTitle(document)}Client";
}

public static string GetSanitizeTitle(this OpenApiDocument document)
=> RemoveCharacters(
Expand Down
Loading