RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.78k stars 1.29k forks source link

Client Generation impossible for azure functions #3142

Open Kokujou opened 4 years ago

Kokujou commented 4 years ago

Hello~ I tried now a lot of times to generate an nswag client for typescript and c# for an azure function app. it is possible to generate a swagger documentation for function apps so it also should be possible to generate an nswag client right? sadly... it's not. there are like a very lot of problems and i will describe them now:

  1. The output format differs. My function app has the structure bin/Debug/netcoreapp3.1/bin , but i could solve this with just copying the output into the netcoreapp3.1 folder where it's expected

  2. there is not runtimeconfig generated, so i finally found out that you can solve this with addying (in the honest hope that code quotes are working like that)

        <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
        <EnableDynamicLoading>true</EnableDynamicLoading>
  3. after all that trouble the last error is now terminating:

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
    ---> System.InvalidOperationException: Unable to locate the program entry point for OrchestrationService.
     at NSwag.Commands.Generation.AspNetCore.AspNetCoreToOpenApiGeneratorCommandEntryPoint.GetServiceProvider(String applicationName) in C:\projects\nswag\src\NSwag.Commands\Commands\Generation\AspNetCore\AspNetCoreToOpenApiGeneratorCommandEntryPoint.cs:line 46
     at NSwag.Commands.Generation.AspNetCore.AspNetCoreToOpenApiGeneratorCommandEntryPoint.Process(String commandContent, String outputFile, String applicationName) in C:\projects\nswag\src\NSwag.Commands\Commands\Generation\AspNetCore\AspNetCoreToOpenApiGeneratorCommandEntryPoint.cs:line 26
     --- End of inner exception stack trace ---
     at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
     at NSwag.AspNetCore.Launcher.Program.Main(String[] args) in C:\projects\nswag\src\NSwag.AspNetCore.Launcher\Program.cs:line 170
    System.InvalidOperationException: Swagger generation failed with non-zero exit code '1'.
     at NSwag.Commands.Generation.AspNetCore.AspNetCoreToSwaggerCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in C:\projects\nswag\src\NSwag.Commands\Commands\Generation\AspNetCore\AspNetCoreToOpenApiCommand.cs:line 221
     at NSwag.Commands.NSwagDocumentBase.GenerateSwaggerDocumentAsync() in C:\projects\nswag\src\NSwag.Commands\NSwagDocumentBase.cs:line 280
     at NSwag.Commands.NSwagDocument.ExecuteAsync() in C:\projects\nswag\src\NSwag.Commands\NSwagDocument.cs:line 81
     at NSwag.Commands.Document.ExecuteDocumentCommand.ExecuteDocumentAsync(IConsoleHost host, String filePath) in C:\projects\nswag\src\NSwag.Commands\Commands\Document\ExecuteDocumentCommand.cs:line 86   
     at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in C:\projects\nswag\src\NSwag.Commands\Commands\Document\ExecuteDocumentCommand.cs:line 32     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
RicoSuter commented 4 years ago

Maybe you're looking for this? https://github.com/Jusas/NSwag.AzureFunctionsV2

Kokujou commented 4 years ago

No, probably not. i tested it out and this lead me to my problems i described here. also i'm not even sure if this package is even targetting the generation of clients. Maybe it's just swagger UI it's talking about. but i want an typescript and a c# client for my function app.

jeremyVignelles commented 4 years ago

It's not straightforward for NSwag to generate an OpenAPI definition for Azure Function projects, because it differs too much from the ASP.net core way of doing. This is why NSwag.AzureFuction exists, it should be able to generate an OpenAPI definition for your project, that you can later pass to NSwag to generate your client.

Another option would be to write your own OpenApi definition by hand, and use the new Microsoft tools that generates Azure functions projects from the definition.

Kokujou commented 4 years ago

well that i already noticed ^^ but i mean... we managed to get a swagger UI already. we just can't manage to compile the client project. if there'd be an even more basic nswag client generation tool which just excepts some kind of open api file which is probably generated somewhere alrady and only create a client using that it'd be nice but... well^^

is anyone here able to point me to something which helps? or is it just impossible?

jeremyVignelles commented 4 years ago

I think you are confused between the OpenAPI specification file (sometimes called swagger.json), which describes your API, and swaggerUI, which uses the former file to show a UI where you can try your API. By downloading the OpenApi definition (a link for that should be present in the SwaggerUI interface), you can use NSwag to generate client files from that swagger.json.

I'm under the impression that you're trying to generate your client from the project directly, which doesn't work at the moment, only asp.net core projects are supported.

Kokujou commented 4 years ago

that's true. actually i want to do it during my build process. so, okay, can you then probably tell me how to generate a client using a json file?