0

I am attempting to use NSwag to automate my typescript client code generation. I installed the tool using npm and set up an npm script. This is the script I am running:

nswag openapi2tsclient /input:https://localhost:5001/swagger/v1/swagger.json /output:out.ts

I'm not sure what I'm doing, but I get an error message which just doesn't make sense to me considering that the uri works (I can download the swagger.json file on my machine).

NSwag NPM CLI NSwag
command line tool for .NET Core NetCore21, toolchain v13.2.3.0 (NJsonSchema v10.1.5.0 (Newtonsoft.Json v11.0.0.0))
Visit http://NSwag.org for more information.
NSwag bin directory: /home/vscode/.nvm/versions/node/v12.16.1/lib/node_modules/nswag/bin/binaries/NetCore21
System.Net.Http.HttpRequestException: Cannot assign requested address ---> System.Net.Sockets.SocketException: Cannot assign requested address at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.AuthenticationHelper.SendWithAuthAsync(HttpRequestMessage request, Uri authUri, ICredentials credentials, Boolean preAuthenticate, Boolean isProxyAuth, Boolean doRequestAuth, HttpConnectionPool pool, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at NJsonSchema.Infrastructure.DynamicApis.HttpGetAsync(String url)
at NSwag.OpenApiDocument.FromUrlAsync(String url) in C:\projects\nswag\src\NSwag.Core\OpenApiDocument.cs:line 219
at NSwag.Commands.OutputCommandBase.ReadSwaggerDocumentAsync(String input) in C:\projects\nswag\src\NSwag.Commands\Commands\OutputCommandBase.cs:line 37
at NSwag.Commands.InputOutputCommandBase.GetInputSwaggerDocument() in C:\projects\nswag\src\NSwag.Commands\Commands\InputOutputCommandBase.cs:line 46
at NSwag.Commands.CodeGeneration.SwaggerToTypeScriptClientCommand.b__147_0() in C:\projects\nswag\src\NSwag.Commands\Commands\CodeGeneration\OpenApiToTypeScriptClientCommand.cs:line 388
at NSwag.Commands.CodeGeneration.SwaggerToTypeScriptClientCommand.RunAsync() in C:\projects\nswag\src\NSwag.Commands\Commands\CodeGeneration\OpenApiToTypeScriptClientCommand.cs:line 378
at NSwag.Commands.CodeGeneration.SwaggerToTypeScriptClientCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in C:\projects\nswag\src\NSwag.Commands\Commands\CodeGeneration\OpenApiToTypeScriptClientCommand.cs:line 371
at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
at NConsole.CommandLineProcessor.Process(String[] args, Object input)
at NSwag.Commands.NSwagCommandProcessor.Process(String[] args) in C:\projects\nswag\src\NSwag.Commands\NSwagCommandProcessor.cs:line 56 child_process.js:669
throw err;

michael
  • 787
  • 2
  • 6
  • 12
  • 1
    Can you post your `swagger.json` let's see what's inside... if it's too long or contains copyrighted data please create a minimal that reproduces your issue – Helder Sepulveda Mar 09 '20 at 14:18
  • Unfortunately it is way too long and proprietary to post, and creating a minified version would not likely help. Oddly enough, if I download the `swagger.json` and use the folder path to the file instead of a uri, it works. It just seems to fail with a uri. – michael Mar 10 '20 at 21:04

0 Answers0