Skip to content

Commit

Permalink
1) Added: in the first page of wizard added checkbox for open generat…
Browse files Browse the repository at this point in the history
…ed files on complete;

2) Fix: add `TextWrapping` for correct display checkboxes text in wizard pages;
3) Fix bug: now generated client (controller) code files add into the project.
  • Loading branch information
unchase committed Apr 11, 2019
1 parent 99ced46 commit 5ac4e82
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 65 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

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.1.6 `(2019-04-11)`

- [x] Added: in the first page of wizard added checkbox for open generated files on complete
- [x] Fix: add `TextWrapping` for correct display checkboxes text in wizard pages
- [x] Fix bug: now generated client (controller) code files add into the project

## v1.1.5 `(2019-04-10)`

- [x] Small fixes
Expand Down
49 changes: 29 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
# Unchase.OpenAPI.ConnectedService
[![Build status](https://ci.appveyor.com/api/projects/status/90oewanfh32fjcr6?svg=true)](https://ci.appveyor.com/project/unchase/unchase.openapi.connectedservice)
#
![Unchase OpenAPI (Swagger) Connected Service Logo](img/Unchase-OpenAPI-Swagger-Connected-Service-Logo.png)

[Unchase OpenAPI (Swagger) Connected Service](https://marketplace.visualstudio.com/items?itemName=Unchase.unchaseOpenAPIConnectedService) is a Visual Studio extension to generate `C#` (`TypeScript`) `HttpClient` (`Controller`) code for `OpenAPI` (formerly [`Swagger API`](https://swagger.io/docs/specification/about/)) web service with [NSwag](https://github.com/RSuter/NSwag).

[![GitHub release](https://img.shields.io/github/release/unchase/Unchase.OpenAPI.Connectedservice.svg)](https://github.com/unchase/Unchase.OpenAPI.Connectedservice/releases/latest) [![Github Releases](https://img.shields.io/github/downloads/unchase/Unchase.OpenAPI.Connectedservice/total.svg)](https://github.com/unchase/Unchase.OpenAPI.Connectedservice/releases/latest) [![GitHub Release Date](https://img.shields.io/github/release-date/unchase/Unchase.OpenAPI.Connectedservice.svg)](https://github.com/unchase/Unchase.OpenAPI.Connectedservice/releases/latest)
> The project is developed and maintained by [Nikolay Chebotov (**Unchase**)](https://github.com/unchase).
The project is developed and maintained by [Nikolay Chebotov (**Unchase**)](https://github.com/unchase).
## Builds status
|Status|Value|
|:----|:---:|
|Build|[![Build status](https://ci.appveyor.com/api/projects/status/90oewanfh32fjcr6?svg=true)](https://ci.appveyor.com/project/unchase/unchase.openapi.connectedservice)
|GitHub Release|[![GitHub release](https://img.shields.io/github/release/unchase/Unchase.OpenAPI.Connectedservice.svg)](https://github.com/unchase/Unchase.OpenAPI.Connectedservice/releases/latest)
|GitHub Release Date|[![GitHub Release Date](https://img.shields.io/github/release-date/unchase/Unchase.OpenAPI.Connectedservice.svg)](https://github.com/unchase/Unchase.OpenAPI.Connectedservice/releases/latest)
|GitHub Release Downloads|[![Github Releases](https://img.shields.io/github/downloads/unchase/Unchase.OpenAPI.Connectedservice/total.svg)](https://github.com/unchase/Unchase.OpenAPI.Connectedservice/releases/latest)
|VS Marketplace|[![VS Marketplace](http://vsmarketplacebadge.apphb.com/version-short/unchase.UnchaseOpenAPIConnectedService.svg)](https://marketplace.visualstudio.com/items?itemName=unchase.unchaseOpenAPIConnectedService)
|VS Marketplace Downloads|[![VS Marketplace Downloads](http://vsmarketplacebadge.apphb.com/downloads-short/unchase.UnchaseOpenAPIConnectedService.svg)](https://marketplace.visualstudio.com/items?itemName=unchase.unchaseOpenAPIConnectedService)
|VS Marketplace Installs|[![VS Marketplace Installs](http://vsmarketplacebadge.apphb.com/installs-short/unchase.UnchaseOpenAPIConnectedService.svg)](https://marketplace.visualstudio.com/items?itemName=unchase.unchaseOpenAPIConnectedService)

# Features
## Features
- Generate `C#` or `TypeScript` clients/proxies (client code) from Swagger 2.0 and OpenAPI 3.0 specifications from C# ASP.NET (Core) controllers
- Generate `C#` Controller from Swagger 2.0 and OpenAPI 3.0 specifications
- Generate `.nswag` file for using in [`NSwagStudio`](https://github.com/NSwag/NSwag/wiki/NSwagStudio) (no need to install for generating)
Expand All @@ -28,65 +37,65 @@ The project is developed and maintained by [Nikolay Chebotov (**Unchase**)](http
1. Microsoft.AspNetCore.Mvc ([NuGet](https://www.nuget.org/packages/Microsoft.AspNetCore.MVC))
- Storage of the last 10 endpoints (json-specification path)

# Getting Started
## Getting Started

[![VS Marketplace](http://vsmarketplacebadge.apphb.com/version-short/unchase.UnchaseOpenAPIConnectedService.svg)](https://marketplace.visualstudio.com/items?itemName=unchase.unchaseOpenAPIConnectedService) [![VS Marketplace Installs](http://vsmarketplacebadge.apphb.com/installs-short/unchase.UnchaseOpenAPIConnectedService.svg)](https://marketplace.visualstudio.com/items?itemName=unchase.unchaseOpenAPIConnectedService) [![VS Marketplace Downloads](http://vsmarketplacebadge.apphb.com/downloads-short/unchase.UnchaseOpenAPIConnectedService.svg)](https://marketplace.visualstudio.com/items?itemName=unchase.unchaseOpenAPIConnectedService)

Install from `Tools -> Extensions and Updates` menu inside [Visual Studio](https://visualstudio.microsoft.com/vs/) (including 2019) or [download](http://vsixgallery.com/extensions/Unchase.OpenAPI.ConnectedService.63199638-6211-4285-ba8f-75b1f0326c2a/extension.vsix) as `VSIX` package from VSGallery or [download](https://marketplace.visualstudio.com/items?itemName=unchase.unchaseOpenAPIConnectedService) as `VSIX` package from Visual Studio Marketplace:

![Adding Unchase OpenAPI (Swagger) Connected Service in Visual Studio](img/Unchase-OpenAPI-Swagger-Connected-Service.gif)


# Settings Meaning
## Settings Meaning

Meaning of the Unchase [OpenAPI (Swagger) Connected Service](https://marketplace.visualstudio.com/items?itemName=unchase.unchaseOpenAPIConnectedService) settings according to [NSWagStudio](https://github.com/NSwag/NSwag/wiki/NSwagStudio):

![Unchase OpenAPI (Swagger) Connected Service settings meaning](img/Unchase-OpenAPI-Swagger-Connected-Service-Settings-Meaning.png)

# Open in NSwagStudio Command
## Open in NSwagStudio Command

Since *v1.1.** was added menu command embedded in Visual Studio Solution Explorer context menu lets you open generated `.nswag` and `.nswag.json` files in [NSWagStudio](https://github.com/NSwag/NSwag/wiki/NSwagStudio).

This extension is for those times where you generate `.nswag` and `.nswag.json` files and you want to be able to quickly open it in [NSWagStudio](https://github.com/NSwag/NSwag/wiki/NSwagStudio).

## Prerequisite
### Prerequisite

In order to use this extension, you must have [Visual Studio](https://visualstudio.microsoft.com/vs/) 2017/2019, this connected service as well as [NSWagStudio](https://github.com/NSwag/NSwag/wiki/NSwagStudio) installed.
> In order to use this extension, you must have [Visual Studio](https://visualstudio.microsoft.com/vs/) 2017/2019, this connected service as well as [NSWagStudio](https://github.com/NSwag/NSwag/wiki/NSwagStudio) installed.
## Solution Explorer
### Solution Explorer

You can open `.nswag` and `.nswag.json` files in NSwagStudio by simply right-clicking it in Solution Explorer and select **Open in NSwagStudio**:

![Open in NSwagStudio menu command](img/OpenWithNSwagCommandMenu.png)

## Path to NSwagStudio.exe
### Path to NSwagStudio.exe

If you installed [NSWagStudio](https://github.com/NSwag/NSwag/wiki/NSwagStudio) at a non-default location, a prompt will ask for the path to `NSwagStudio.exe`.

You can always change the location in *Tools -> Options -> Web -> Unchase OpenAPI (Swagger) Connected Service*:

![Open in NSwagStudio Option](img/OpenWithNSwagCommandOptions.png)

# HowTos
## HowTos
- [ ] Add HowTos in a future
- [ ] ... [request for HowTo you need](https://github.com/unchase/Unchase.OpenAPI.Connectedservice/issues/new?title=DOC)

# Troubleshooting
## Can't open .nswag file in NSwagStudio
## Troubleshooting
### Can't open .nswag file in NSwagStudio
- You can use **Open in NSwagStudio** menu command
- If generated code corrupted, try to open `.nswag` file in [`NSwagStudio`](https://github.com/RSuter/NSwag/wiki/NSwagStudio) (Windows GUI for editing .*nswag files)
- If it doesn't open, try to create new `.nswag` file in [`NSwagStudio`](https://github.com/RSuter/NSwag/wiki/NSwagStudio) for the same API service link and check the differences

## Installation completes but I can't see the Service in the list of connected services (Visual Studio 2019)
### Installation completes but I can't see the Service in the list of connected services (Visual Studio 2019)
- Relevant [bug report](https://developercommunity.visualstudio.com/content/problem/468751/vs2019-preview-cannot-install-connected-service-ex.html). Connected Services will be restored in the first update to [Visual Studio](https://visualstudio.microsoft.com/vs/) 2019 (version 16.1).

# Roadmap
## Roadmap
See the [changelog](CHANGELOG.md) for the further development plans and version history.

# Feedback
## Feedback
Please feel free to add your [review](https://marketplace.visualstudio.com/items?itemName=unchase.unchaseOpenAPIConnectedService&ssr=false#review-details), [request a feature](https://github.com/unchase/Unchase.OpenAPI.Connectedservice/issues/new?title=FEATURE), [report a bug](https://github.com/unchase/Unchase.OpenAPI.Connectedservice/issues/new?title=BUG) or [ask a question](https://marketplace.visualstudio.com/items?itemName=unchase.unchaseOpenAPIConnectedService&ssr=false#qna). Thank you in advance!

# Thank me!
## Thank me!
If you like what I am doing and you would like to thank me, please consider [buying me a coffee](https://www.buymeacoffee.com/nikolaychebotov). Thank you for your support!

----------
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 48 additions & 2 deletions src/CodeGeneration/NSwagCodeGenDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//-----------------------------------------------------------------------

using System;
using System.CodeDom.Compiler;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -142,8 +143,53 @@ internal async Task<string> GenerateCodeAsync(ConnectedServiceHandlerContext con
var nswagFilePath = Path.Combine(folderPath, $"{serviceFolder}.nswag");
var document = await NSwagDocument.LoadWithTransformationsAsync(nswagFilePath, instance.ServiceConfig.Variables);
document.Runtime = instance.ServiceConfig.Runtime;
await document.ExecuteAsync();
return document.SelectedSwaggerGenerator.OutputFilePath;

var nswagJsonTempFileName = Path.GetTempFileName();
var csharpClientTempFileName = Path.GetTempFileName();
var typeScriptClientTempFileName = Path.GetTempFileName();
var controllerTempFileName = Path.GetTempFileName();
var nswagJsonOutputPath = document.SelectedSwaggerGenerator.OutputFilePath;
try
{
var csharpClientOutputPath = document.CodeGenerators?.SwaggerToCSharpClientCommand?.OutputFilePath;
var typeScriptClientOutputPath = document.CodeGenerators?.SwaggerToTypeScriptClientCommand?.OutputFilePath;
var controllerOutputPath = document.CodeGenerators?.SwaggerToCSharpControllerCommand?.OutputFilePath;

document.SelectedSwaggerGenerator.OutputFilePath = nswagJsonTempFileName;
if (document.CodeGenerators?.SwaggerToCSharpClientCommand != null)
document.CodeGenerators.SwaggerToCSharpClientCommand.OutputFilePath = csharpClientTempFileName;
if (document.CodeGenerators?.SwaggerToTypeScriptClientCommand != null)
document.CodeGenerators.SwaggerToTypeScriptClientCommand.OutputFilePath = typeScriptClientTempFileName;
if (document.CodeGenerators?.SwaggerToCSharpControllerCommand != null)
document.CodeGenerators.SwaggerToCSharpControllerCommand.OutputFilePath = controllerTempFileName;

await document.ExecuteAsync();

nswagJsonOutputPath = await context.HandlerHelper.AddFileAsync(nswagJsonTempFileName, nswagJsonOutputPath, new AddFileOptions { OpenOnComplete = instance.ServiceConfig.OpenGeneratedFilesOnComplete });
if (document.CodeGenerators?.SwaggerToCSharpClientCommand != null)
await context.HandlerHelper.AddFileAsync(csharpClientTempFileName, csharpClientOutputPath, new AddFileOptions { OpenOnComplete = instance.ServiceConfig.OpenGeneratedFilesOnComplete });
if (document.CodeGenerators?.SwaggerToTypeScriptClientCommand != null)
await context.HandlerHelper.AddFileAsync(typeScriptClientTempFileName, typeScriptClientOutputPath, new AddFileOptions { OpenOnComplete = instance.ServiceConfig.OpenGeneratedFilesOnComplete });
if (document.CodeGenerators?.SwaggerToCSharpControllerCommand != null)
await context.HandlerHelper.AddFileAsync(controllerTempFileName, controllerOutputPath, new AddFileOptions { OpenOnComplete = instance.ServiceConfig.OpenGeneratedFilesOnComplete });
}
catch (Exception ex)
{
await this.Context.Logger.WriteMessageAsync(LoggerMessageCategory.Warning, $"Error: {ex.Message}.");
}
finally
{
if (File.Exists(nswagJsonTempFileName))
File.Delete(nswagJsonTempFileName);
if (File.Exists(csharpClientTempFileName))
File.Delete(csharpClientTempFileName);
if (File.Exists(typeScriptClientTempFileName))
File.Delete(typeScriptClientTempFileName);
if (File.Exists(controllerTempFileName))
File.Delete(controllerTempFileName);
}

return nswagJsonOutputPath;
}

internal async Task<string> GenerateNswagFileAsync(ConnectedServiceHandlerContext context, Instance instance)
Expand Down
6 changes: 6 additions & 0 deletions src/Models/ServiceConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ namespace Unchase.OpenAPI.ConnectedService.Models
internal class ServiceConfiguration
{
public string ServiceName { get; set; }

public string Endpoint { get; set; }

public string GeneratedFileNamePrefix { get; set; }

public bool GenerateCSharpClient { get; set; } = false;

public bool GenerateTypeScriptClient { get; set; } = false;

public bool GenerateCSharpController { get; set; } = false;

public SwaggerToCSharpClientCommand SwaggerToCSharpClientCommand { get; set; }
Expand All @@ -25,6 +29,8 @@ internal class ServiceConfiguration

public bool CopySpecification { get; set; }

public bool OpenGeneratedFilesOnComplete { get; set; }

#region Network Credentials
public bool UseNetworkCredentials { get; set; }
public string NetworkCredentialsUserName { get; set; }
Expand Down
12 changes: 12 additions & 0 deletions src/Models/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ namespace Unchase.OpenAPI.ConnectedService.Models
[DataContract]
internal class UserSettings
{
#region Private
private const string Name = "Settings";

private const int MaxMruEntries = 10;

private ConnectedServiceLogger _logger;
#endregion

#region Public properties
[DataMember]
public ObservableCollection<string> MruEndpoints { get; private set; }

Expand Down Expand Up @@ -42,11 +46,18 @@ internal class UserSettings
[DataMember]
public string ServiceName { get; set; }

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

#region Constructors
private UserSettings()
{
this.MruEndpoints = new ObservableCollection<string>();
}
#endregion

#region Public methods
public void Save()
{
UserSettingsPersistenceHelper.Save(this, Constants.ProviderId, UserSettings.Name, null, this._logger);
Expand Down Expand Up @@ -87,5 +98,6 @@ public static void AddToTopOfMruList<T>(ObservableCollection<T> mruList, T item)
mruList.Insert(0, item);
}
}
#endregion
}
}
10 changes: 6 additions & 4 deletions src/Views/CSharpClientSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@

<CheckBox IsChecked="{Binding Command.GenerateOptionalParameters, Mode=TwoWay}"
ToolTip="GenerateOptionalParameters"
Content="Generate optional parameters (reorder parameters (required first, optional at the end) and generate optional parameters)."
HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="0, 5, 10, 5"/>
HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="0, 5, 10, 5">
<TextBlock TextWrapping="Wrap" Text="Generate optional parameters (reorder parameters (required first, optional at the end) and generate optional parameters)."/>
</CheckBox>

<TextBlock TextWrapping="WrapWithOverflow" Text="Excluded Parameter Names (comma separated) :" FontWeight="Bold" Margin="0, 5, 0, 0"/>
<TextBox ToolTip="ExcludedParameterNames"
Expand Down Expand Up @@ -187,10 +188,11 @@

<CheckBox IsChecked="{Binding Command.SerializeTypeInformation, Mode=TwoWay}"
ToolTip="SerializeTypeInformation"
Content="Serialize the type information in a $type property (not recommended, also sets TypeNameHandling = Auto)."
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
Margin="0, 5, 10, 5"/>
Margin="0, 5, 10, 5">
<TextBlock TextWrapping="Wrap" Text="Serialize the type information in a $type property (not recommended, also sets TypeNameHandling = Auto)."/>
</CheckBox>

<TextBlock TextWrapping="WrapWithOverflow" Text="Http Client Type :" FontWeight="Bold" Margin="0, 5, 0, 0"/>
<TextBox Text="{Binding Command.HttpClientType, Mode=TwoWay}"
Expand Down
5 changes: 3 additions & 2 deletions src/Views/CSharpControllerSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@
Margin="0, 5, 10, 5" />

<CheckBox IsChecked="{Binding Command.GenerateOptionalParameters, Mode=TwoWay}"
Content="Generate optional parameters (reorder parameters (required first, optional at the end) and generate optional parameters)."
Margin="0, 5, 10, 5" />
Margin="0, 5, 10, 5">
<TextBlock TextWrapping="Wrap" Text="Generate optional parameters (reorder parameters (required first, optional at the end) and generate optional parameters)."/>
</CheckBox>

<TextBlock TextWrapping="WrapWithOverflow" Text="Excluded Parameter Names (comma separated) :" FontWeight="Bold" Margin="0, 5, 10, 5" />
<TextBox ToolTip="ExcludedParameterNames"
Expand Down
Loading

0 comments on commit 5ac4e82

Please sign in to comment.