asyncapi / saunter

Saunter is a code-first AsyncAPI documentation generator for dotnet.
https://www.asyncapi.com/
MIT License
195 stars 55 forks source link

Support code-first generation in Azure Function Apps #152

Open NattyMojo opened 1 year ago

NattyMojo commented 1 year ago

I've been looking into ways to get AsyncApi code-first generation into my Azure Function App and gave this package a shot, but noticing that it's calling for MVC middleware, which is not available. I've seen the same thing with other packages as well. Is there a way to get this package to generate the code-first documentation (using attributes) with an Azure Function App? Is that on the roadmap, or not available/won't be available?

Relevant ticket opened on KsntServiceBus and Neuroglia

I opened a StackOverflow question seeing if anyone has tried this with Azure Function Apps before.

devlux commented 1 year ago

I think that #136 would fix your issue as its goal is to decouple the asp.net core part (hosting the schema in a web app) from the schema generation.

NattyMojo commented 1 year ago

@devlux yeah I think that's along the lines of what I was looking into. I'm playing around with doing something like that using the Neurolgia implementation around building/writing for files

drdamour commented 1 year ago

i got the most basic thing going with

public class FuncAsyncApi
{
    private readonly IAsyncApiDocumentProvider provider;
    private readonly IAsyncApiDocumentSerializer serializer;
    private readonly AsyncApiOptions options;

    public FuncAsyncApi(
        IAsyncApiDocumentProvider asyncApiDocumentProvider, 
        IAsyncApiDocumentSerializer asyncApiDocumentSerializer,
        IOptions<AsyncApiOptions> options
    )
    {
        this.provider = asyncApiDocumentProvider;
        this.serializer = asyncApiDocumentSerializer;
        this.options = options.Value;
    }

    [FunctionName("spec")]
    public IActionResult Spec(
       [HttpTrigger(AuthorizationLevel.Anonymous, Route = "/specification")] HttpRequest req
    )
    {
        var asyncApiSchema = provider.GetDocument(options, options.AsyncApi);
        return new OkObjectResult(
            serializer.Serialize(asyncApiSchema)
        );
    }
}

so don't really think there's a blocker here, could just publish a nuget azf package that other azf's could pull in

NattyMojo commented 1 year ago

@drdamour's FuncAsyncApi works perfect for generating the json at least :)