Skip to content

Commit

Permalink
1) Update dependencies: add support for "NSwag.Commands v13.4.0";
Browse files Browse the repository at this point in the history
2) Add feature: Add option to set "Genereated file name" on the first wizard page;
3) Disable some fields when updating.
  • Loading branch information
unchase committed Apr 16, 2020
1 parent 0abeddd commit 9b72c24
Show file tree
Hide file tree
Showing 17 changed files with 1,539 additions and 766 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@

These are the changes to each version that has been released on the official [Visual Studio extension gallery](https://marketplace.visualstudio.com/items?itemName=unchase.UnchaseOpenAPIConnectedService).

## v1.4.4 `(2020-04-16)`

- [x] Update dependencies: add support for [NSwag.Commands v13.4.0](https://github.com/RicoSuter/NSwag/pull/2799)
- [x] [New option: define a base interface for C# client interfaces.](https://github.com/RicoSuter/NSwag/pull/2775)
- [x] [Use enums value (underlying type) rather than enum name](https://github.com/RicoSuter/NSwag/pull/2758)
- [x] Inline param refs if AllowReferencesWithProperties is set
- [x] Removed .NET Core 1.0, 1.1 and 2.0 support.
- [x] Add feature: Add option to set `Genereated file name` on the first wizard page
- [x] Disable some fields when updating

## v1.4.3 `(2020-04-10)`

- [x] Fix [issue #18](https://github.com/unchase/Unchase.OpenAPI.Connectedservice/issues/18)
Expand Down
18 changes: 11 additions & 7 deletions src/CodeGeneration/NSwagCodeGenDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ internal async Task<string> GenerateCodeAsync(ConnectedServiceHandlerContext con
var rootFolder = context.HandlerHelper.GetServiceArtifactsRootFolder();
var folderPath = context.ProjectHierarchy.GetProject().GetServiceFolderPath(rootFolder, serviceFolder);

var nswagFilePath = Path.Combine(folderPath, $"{serviceFolder}.nswag");
var nswagFilePath = Path.Combine(folderPath, $"{instance.ServiceConfig.GeneratedFileName}.nswag");
var document = await NSwagDocument.LoadWithTransformationsAsync(nswagFilePath, instance.ServiceConfig.Variables);
document.Runtime = instance.ServiceConfig.Runtime;

Expand Down Expand Up @@ -246,7 +246,7 @@ internal async Task<string> GenerateNswagFileAsync(ConnectedServiceHandlerContex
var document = NSwagDocument.Create();
if (instance.ServiceConfig.GenerateCSharpClient)
{
instance.ServiceConfig.OpenApiToCSharpClientCommand.OutputFilePath = $"{serviceFolder}Client.Generated.cs";
instance.ServiceConfig.OpenApiToCSharpClientCommand.OutputFilePath = $"{instance.ServiceConfig.GeneratedFileName}.cs";
if (string.IsNullOrWhiteSpace(instance.ServiceConfig.OpenApiToCSharpClientCommand.Namespace))
{
instance.ServiceConfig.OpenApiToCSharpClientCommand.Namespace = $"{nameSpace}.{serviceFolder}";
Expand All @@ -255,28 +255,32 @@ internal async Task<string> GenerateNswagFileAsync(ConnectedServiceHandlerContex
}
if (instance.ServiceConfig.GenerateTypeScriptClient)
{
instance.ServiceConfig.OpenApiToTypeScriptClientCommand.OutputFilePath = $"{serviceFolder}Client.Generated.ts";
instance.ServiceConfig.OpenApiToTypeScriptClientCommand.OutputFilePath = $"{instance.ServiceConfig.GeneratedFileName}.ts";
document.CodeGenerators.OpenApiToTypeScriptClientCommand = instance.ServiceConfig.OpenApiToTypeScriptClientCommand;
}
if (instance.ServiceConfig.GenerateCSharpController)
{
instance.ServiceConfig.OpenApiToCSharpControllerCommand.OutputFilePath = $"{serviceFolder}Controller.Generated.cs";
instance.ServiceConfig.OpenApiToCSharpControllerCommand.OutputFilePath =
instance.ServiceConfig.GenerateCSharpClient
? $"{instance.ServiceConfig.GeneratedFileName}Controller.cs"
: $"{instance.ServiceConfig.GeneratedFileName}.cs";

if (string.IsNullOrWhiteSpace(instance.ServiceConfig.OpenApiToCSharpControllerCommand.Namespace))
instance.ServiceConfig.OpenApiToCSharpControllerCommand.Namespace = $"{nameSpace}.{serviceFolder}";
document.CodeGenerators.OpenApiToCSharpControllerCommand = instance.ServiceConfig.OpenApiToCSharpControllerCommand;
}

document.SelectedSwaggerGenerator = new FromDocumentCommand
{
OutputFilePath = $"{serviceFolder}.nswag.json",
OutputFilePath = $"{instance.ServiceConfig.GeneratedFileName}.nswag.json",
Url = serviceUrl,
Json = instance.ServiceConfig.CopySpecification ? File.ReadAllText(instance.SpecificationTempPath) : null
};

var json = document.ToJson();
var tempFileName = Path.GetTempFileName();
File.WriteAllText(tempFileName, json);
var targetPath = Path.Combine(rootFolder, serviceFolder, $"{serviceFolder}.nswag");
var targetPath = Path.Combine(rootFolder, serviceFolder, $"{instance.ServiceConfig.GeneratedFileName}.nswag");
var nswagFilePath = await context.HandlerHelper.AddFileAsync(tempFileName, targetPath);
if (File.Exists(tempFileName))
File.Delete(tempFileName);
Expand All @@ -291,7 +295,7 @@ internal async Task<string> ReGenerateCSharpFileAsync(ConnectedServiceHandlerCon
var rootFolder = context.HandlerHelper.GetServiceArtifactsRootFolder();
var folderPath = context.ProjectHierarchy.GetProject().GetServiceFolderPath(rootFolder, serviceFolder);

var nswagFilePath = Path.Combine(folderPath, $"{serviceFolder}.nswag");
var nswagFilePath = Path.Combine(folderPath, $"{instance.ServiceConfig.GeneratedFileName}.nswag");
var document = await NSwagDocument.LoadWithTransformationsAsync(nswagFilePath, instance.ServiceConfig.Variables);
document.Runtime = instance.ServiceConfig.Runtime;
await document.ExecuteAsync();
Expand Down
1 change: 1 addition & 0 deletions src/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static class Constants

public const string NuGetOnlineRepository = "https://www.nuget.org/api/v2/";
public const string DefaultServiceName = "OpenAPIService";
public const string DefaultGeneratedFileName = "OpenAPI";

public const string NewtonsoftJsonNuGetPackage = "Newtonsoft.Json";
public const string SystemNetHttpNuGetPackage = "System.Net.Http";
Expand Down
2 changes: 2 additions & 0 deletions src/Models/ServiceConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ internal class ServiceConfiguration
#region Properties
public string ServiceName { get; set; }

public string GeneratedFileName { get; set; }

public string Endpoint { get; set; }

public string GeneratedFileNamePrefix { get; set; }
Expand Down
4 changes: 4 additions & 0 deletions src/Models/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ internal class UserSettings
[DataMember]
public string ServiceName { get; set; }

[DataMember]
public string GeneratedFileName { get; set; }

[DataMember]
public bool OpenGeneratedFilesOnComplete { get; set; } = false;

Expand Down Expand Up @@ -77,6 +80,7 @@ internal void SetFromServiceConfiguration(ServiceConfiguration serviceConfigurat
this.OpenGeneratedFilesOnComplete = serviceConfiguration.OpenGeneratedFilesOnComplete;
this.Runtime = serviceConfiguration.Runtime;
this.ServiceName = serviceConfiguration.ServiceName;
this.GeneratedFileName = serviceConfiguration.GeneratedFileName;
this.UseRelativePath = serviceConfiguration.UseRelativePath;
this.Variables = serviceConfiguration.Variables;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.2.*")]
[assembly: AssemblyVersion("1.4.3")]
[assembly: AssemblyFileVersion("1.4.3.0")]
[assembly: AssemblyVersion("1.4.4")]
[assembly: AssemblyFileVersion("1.4.4.0")]
[assembly: NeutralResourcesLanguage("en-US")]

44 changes: 22 additions & 22 deletions src/Unchase.OpenAPI.ConnectedService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -462,38 +462,38 @@
<Reference Include="NJsonSchema.Yaml, Version=10.1.11.0, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102, processorArchitecture=MSIL">
<HintPath>packages\NJsonSchema.Yaml.10.1.11\lib\net45\NJsonSchema.Yaml.dll</HintPath>
</Reference>
<Reference Include="NSwag.Annotations, Version=13.3.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.Annotations.13.3.0\lib\net45\NSwag.Annotations.dll</HintPath>
<Reference Include="NSwag.Annotations, Version=13.4.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.Annotations.13.4.0\lib\net45\NSwag.Annotations.dll</HintPath>
</Reference>
<Reference Include="NSwag.AssemblyLoader, Version=13.3.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.AssemblyLoader.13.3.0\lib\net451\NSwag.AssemblyLoader.dll</HintPath>
<Reference Include="NSwag.AssemblyLoader, Version=13.4.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.AssemblyLoader.13.4.0\lib\net451\NSwag.AssemblyLoader.dll</HintPath>
</Reference>
<Reference Include="NSwag.CodeGeneration, Version=13.3.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.CodeGeneration.13.3.0\lib\net451\NSwag.CodeGeneration.dll</HintPath>
<Reference Include="NSwag.CodeGeneration, Version=13.4.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.CodeGeneration.13.4.0\lib\net451\NSwag.CodeGeneration.dll</HintPath>
</Reference>
<Reference Include="NSwag.CodeGeneration.CSharp, Version=13.3.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.CodeGeneration.CSharp.13.3.0\lib\net451\NSwag.CodeGeneration.CSharp.dll</HintPath>
<Reference Include="NSwag.CodeGeneration.CSharp, Version=13.4.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.CodeGeneration.CSharp.13.4.0\lib\net451\NSwag.CodeGeneration.CSharp.dll</HintPath>
</Reference>
<Reference Include="NSwag.CodeGeneration.TypeScript, Version=13.3.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.CodeGeneration.TypeScript.13.3.0\lib\net451\NSwag.CodeGeneration.TypeScript.dll</HintPath>
<Reference Include="NSwag.CodeGeneration.TypeScript, Version=13.4.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.CodeGeneration.TypeScript.13.4.0\lib\net451\NSwag.CodeGeneration.TypeScript.dll</HintPath>
</Reference>
<Reference Include="NSwag.Commands, Version=13.3.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.Commands.13.3.0\lib\net461\NSwag.Commands.dll</HintPath>
<Reference Include="NSwag.Commands, Version=13.4.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.Commands.13.4.0\lib\net461\NSwag.Commands.dll</HintPath>
</Reference>
<Reference Include="NSwag.Core, Version=13.3.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.Core.13.3.0\lib\net45\NSwag.Core.dll</HintPath>
<Reference Include="NSwag.Core, Version=13.4.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.Core.13.4.0\lib\net45\NSwag.Core.dll</HintPath>
</Reference>
<Reference Include="NSwag.Core.Yaml, Version=13.3.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.Core.Yaml.13.3.0\lib\net45\NSwag.Core.Yaml.dll</HintPath>
<Reference Include="NSwag.Core.Yaml, Version=13.4.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.Core.Yaml.13.4.0\lib\net45\NSwag.Core.Yaml.dll</HintPath>
</Reference>
<Reference Include="NSwag.Generation, Version=13.3.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.Generation.13.3.0\lib\net45\NSwag.Generation.dll</HintPath>
<Reference Include="NSwag.Generation, Version=13.4.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.Generation.13.4.0\lib\net45\NSwag.Generation.dll</HintPath>
</Reference>
<Reference Include="NSwag.Generation.AspNetCore, Version=13.3.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.Generation.AspNetCore.13.3.0\lib\net451\NSwag.Generation.AspNetCore.dll</HintPath>
<Reference Include="NSwag.Generation.AspNetCore, Version=13.4.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.Generation.AspNetCore.13.4.0\lib\net451\NSwag.Generation.AspNetCore.dll</HintPath>
</Reference>
<Reference Include="NSwag.Generation.WebApi, Version=13.3.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.Generation.WebApi.13.3.0\lib\net45\NSwag.Generation.WebApi.dll</HintPath>
<Reference Include="NSwag.Generation.WebApi, Version=13.4.0.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.Generation.WebApi.13.4.0\lib\net45\NSwag.Generation.WebApi.dll</HintPath>
</Reference>
<Reference Include="NSwag.SwaggerGeneration, Version=12.3.1.0, Culture=neutral, PublicKeyToken=c2d88086e098d109, processorArchitecture=MSIL">
<HintPath>packages\NSwag.SwaggerGeneration.12.3.1\lib\net45\NSwag.SwaggerGeneration.dll</HintPath>
Expand Down
3 changes: 3 additions & 0 deletions src/ViewModels/ConfigOpenApiEndpointViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ internal class ConfigOpenApiEndpointViewModel : ConnectedServiceWizardPage

public string ServiceName { get; set; }

public string GeneratedFileName { get; set; }

public string SpecificationTempPath { get; set; }

public UserSettings UserSettings { get; }
Expand Down Expand Up @@ -66,6 +68,7 @@ public ConfigOpenApiEndpointViewModel(UserSettings userSettings, Wizard wizard)
this.View = new ConfigOpenApiEndpoint(this.InternalWizard) {DataContext = this};
this.UserSettings = userSettings;
this.ServiceName = string.IsNullOrWhiteSpace(userSettings.ServiceName) ? Constants.DefaultServiceName : userSettings.ServiceName;
this.GeneratedFileName = string.IsNullOrWhiteSpace(userSettings.GeneratedFileName) ? Constants.DefaultGeneratedFileName : userSettings.GeneratedFileName;
this.Endpoint = userSettings.Endpoint;
this.UseNetworkCredentials = false;
this.UseWebProxy = false;
Expand Down
39 changes: 23 additions & 16 deletions src/Views/CSharpClientExcludedClasses.xaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<Window x:Class="Unchase.OpenAPI.ConnectedService.Views.CSharpClientExcludedClasses"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Title="Exclude types from generation"
mc:Ignorable="d"
Width="400"
Height="370"
MaxHeight="370"
MaxWidth="400"
WindowStartupLocation="CenterOwner"
d:DesignHeight="370" d:DesignWidth="400">
<Window
x:Class="Unchase.OpenAPI.ConnectedService.Views.CSharpClientExcludedClasses"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="Exclude types from generation"
Width="400"
Height="370"
MaxWidth="400"
MaxHeight="370"
d:DesignHeight="370"
d:DesignWidth="400"
WindowStartupLocation="CenterOwner"
mc:Ignorable="d">
<StackPanel>
<TextBlock Margin="5" Text="Choose types to exclude from generation : "/>
<TextBlock Margin="5" Text="Choose types to exclude from generation : " />
<ListBox
x:Name="ExcludedClassesListBox"
MinHeight="275"
Expand All @@ -39,8 +41,13 @@
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button x:Name="ApplyButton" Margin="5" Width="100" HorizontalAlignment="Right" Click="ApplyButton_Click">
<TextBlock Text="Apply"/>
<Button
x:Name="ApplyButton"
Width="100"
Margin="5"
HorizontalAlignment="Right"
Click="ApplyButton_Click">
<TextBlock Text="Apply" />
</Button>
</StackPanel>
</Window>
Loading

0 comments on commit 9b72c24

Please sign in to comment.