azure-functions-openapi-extension icon indicating copy to clipboard operation
azure-functions-openapi-extension copied to clipboard

How to access OpenApiConfigurationOptions from within the TypeVisitors

Open rockgecko-development opened this issue 3 years ago • 1 comments

For #451 , I want to be able to access the OpenApiConfigurationOptions from within the TypeVisitors. What's the best way to do that? The only way forward I can currently see is to rewire the Activator.CreateInstance calls: https://github.com/Azure/azure-functions-openapi-extension/blob/982ad226abd7f744c424a366fb93bb05d17edba6/src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Visitors/VisitorCollection.cs#L53 to pass OpenApiConfigurationOptions as a constructor param.

Should I just do that?

rockgecko-development avatar Sep 18 '22 11:09 rockgecko-development

There are two places you need to inject the IOpenApiConfigurationOptions:

https://github.com/Azure/azure-functions-openapi-extension/blob/4e81588f399f642236e354f00f64de99dccb859a/src/Microsoft.Azure.Functions.Worker.Extensions.OpenApi/OpenApiHttpTriggerContext.cs#L173-L178

https://github.com/Azure/azure-functions-openapi-extension/blob/4e81588f399f642236e354f00f64de99dccb859a/src/Microsoft.Azure.WebJobs.Extensions.OpenApi/OpenApiHttpTriggerContext.cs#L172-L177

The IOpenApiConfigurationOptions instance already exists as a private field in there.

However, there are two other places as well:

https://github.com/Azure/azure-functions-openapi-extension/blob/4e81588f399f642236e354f00f64de99dccb859a/src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Extensions/OpenApiParameterAttributeExtensions.cs#L37-L40

https://github.com/Azure/azure-functions-openapi-extension/blob/4e81588f399f642236e354f00f64de99dccb859a/src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Extensions/OpenApiPayloadAttributeExtensions.cs#L37-L40


The first two xxxContext instances look fine, but the latter two looks complicated. Can we do this for v2.0.0 release, rather than the current v1.x release?

justinyoo avatar Sep 19 '22 09:09 justinyoo