Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Multiple Azure Function Apps projects in one solution - in-process solution #612

Open
DawidKuzminski opened this issue Sep 11, 2023 · 10 comments

Comments

@DawidKuzminski
Copy link

DawidKuzminski commented Sep 11, 2023

Hello, I would like to request assistance with using OpenAPI for a solution where I have multiple Azure Functions Apps projects. My solution has one common Startup file added to each of the projects as a Project Reference. I am using .NET 6.

I have installed Microsoft.Azure.WebJobs.Extensions.OpenApi for all Azure Function App projects and the project with the Startup file (the Startup project contains only this class + configuration).

When I run a single function locally, the documentation is generated. However, when I run my entire local server, I receive an error: "Could not load file or assembly 'Microsoft.Azure.WebJobs'" - I also have this package installed.

Is it possible to generate documentation for my scenario? Do I need to add any additional configuration?
Sample solution structure:
Server

  • AzFuncApp1
    -- Function11
    -- Function12
  • AzFuncApp2
    -- Function21
    -- Function22
  • StartupProject
    -- StartupClass

For the functions I'm interested in, I have added:

[OpenApiOperation(operationId: "AddTags")]
[OpenApiSecurity("function_key", SecuritySchemeType.ApiKey, Name = "code", In = OpenApiSecurityLocationType.Query)]
[OpenApiRequestBody("application/json", typeof(IReadOnlyList<InsertTagRequest>),
	Description = "JSON request body containing { hours, capacity}")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(StatusResponse),
	Description = "Statuses:\n\r - 0 - Ok status,\n\r - 1 - test")]

Is it possible to generate documentation for my scenario? Do I need to add any additional configuration?

Best regards,
Dawid

@DawidKuzminski
Copy link
Author

Please let me know if you need a better description or scenario step by step.

@justinyoo
Copy link
Contributor

@DawidKuzminski Do you have a sample repo for me to reproduce? I have multiple azfunc app projects in one solution but no issue at all.

@DawidKuzminski
Copy link
Author

Thank you for your reply.
I will provide some examples for Thursday.

@DawidKuzminski
Copy link
Author

@justinyoo
OK, so one of my problems is solved after analyzing it with my teammate.
I didn't have the newest version of the framework which allows us to run the Azure function on a local PC (azure-functions-core-tools@4)

My current wall is that on a local PC, swagger generated endpoints only for one project.
On the server side, I can see only an empty page without any endpoints - App Insights shows that the page is generated without any issues.
I call: serverUel/api/swagger/ui

Could you please hint to me if I need any configuration on startup.cs per project?
I watched a lot of videos (also yours) but most of them are related to simple scenarios with one project.

at this moment I added that configuration to my startup class:

builder.Services.AddSingleton<IOpenApiConfigurationOptions>(_ =>
{
	var options = new OpenApiConfigurationOptions()
	{
		Info = new OpenApiInfo()
		{
			Version = "1.0.0",
			Title = "Swagger Petstore",
			Description = "This is a sample server Petstore API designed by [http://swagger.io](http://swagger.io).",
			TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
			Contact = new OpenApiContact()
			{
				Name = "Enquiry",
				Email = "azfunc-openapi@microsoft.com",
				Url = new Uri("https://github.com/Azure/azure-functions-openapi-extension/issues"),
			},
			License = new OpenApiLicense()
			{
				Name = "MIT",
				Url = new Uri("http://opensource.org/licenses/MIT"),
			}
		},
		Servers = DefaultOpenApiConfigurationOptions.GetHostNames(),
		OpenApiVersion = OpenApiVersionType.V3,
		IncludeRequestingHostName = true,
		ForceHttps = true,
		ForceHttp = false,
	};

	return options;
});

@DawidKuzminski
Copy link
Author

DawidKuzminski commented Sep 27, 2023

Hello @justinyoo
I created a repo with an example project:
https://github.com/DawidKuzminski/SwaggerInMultipleAzureProjectsInProcess/tree/master

Requirements:

  • .NET 6
  • azure-functions-core-tools@4

To reproduce:

  1. Restore nuggets
  2. Rebuild solution
  • folder InternalAPIFunctionsBin should be created if not exist
  1. In PowerShell run copyAllFunctions.ps1 from the project repo level (if error occured run: Set-ExecutionPolicy RemoteSigned or Set-ExecutionPolicy Unrestricted)
  • Azure Functions dll and others should be copied to InternalAPIFunctionsBin
  1. Run server_start.cmd from the project repo level
  2. go to https://localhost:7002/api/swagger/ui

In my case, only one function is shown.

lauchSettings for both function in VS are set to port 7000

@DawidKuzminski
Copy link
Author

Is there a chance for me to solve my problem? :)

@DawidKuzminski
Copy link
Author

@justinyoo could you please give me a hint, on how you configure your project with multiple Azure Function Projects in one solution?
and do you also publish all of your projects to one Azure Function App on cloud?

@DawidKuzminski
Copy link
Author

ping

1 similar comment
@DawidKuzminski
Copy link
Author

ping

@CarlosMontanaFraktal
Copy link

did you manage to do it? can you share the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants