Add OpenApiConfigurationOptions for Open API Metadata and further extensibility (#34)
This commit is contained in:
Родитель
c095ebb880
Коммит
3463864170
|
@ -61,38 +61,9 @@ http://localhost:7071/api/MyHttpTrigger?name=OpenApi
|
|||
![Azure Functions run result on a web browser][image-02]
|
||||
|
||||
|
||||
## Enable Open API Metadata ##
|
||||
## Enable Open API Document ##
|
||||
|
||||
To enable Open API metadata, you will need to update `host.json` by adding the `openApi` attribute like below:
|
||||
|
||||
> **NOTE**: The `openApi` attribute is NOT officially defined in the `host.json` schema. It **MAY** be removed and implemented in a different way.
|
||||
|
||||
```json
|
||||
// host.json
|
||||
{
|
||||
...
|
||||
"openApi": {
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "Contoso Open API enabled Azure Functions App",
|
||||
"description": "This is Open API enabled Azure Functions app for Contoso.",
|
||||
"termsOfService": "https://github.com/Azure/azure-functions-openapi-extension",
|
||||
"contact": {
|
||||
"name": "Contoso",
|
||||
"email": "azfunc-openapi@contoso.com",
|
||||
"url": "https://github.com/Azure/azure-functions-openapi-extension/issues"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "http://opensource.org/licenses/MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Also, you will need to install a NuGet package, [Microsoft.Azure.WebJobs.Extensions.OpenApi][az func openapi extension].
|
||||
To enable Open API document, you will need to install a NuGet package, [Microsoft.Azure.WebJobs.Extensions.OpenApi][az func openapi extension].
|
||||
|
||||
```bash
|
||||
dotnet add package Microsoft.Azure.WebJobs.Extensions.OpenApi
|
||||
|
@ -100,7 +71,6 @@ dotnet add package Microsoft.Azure.WebJobs.Extensions.OpenApi
|
|||
|
||||
> This extension is currently in preview.
|
||||
|
||||
|
||||
With [Visual Studio Code][vs code], open your HTTP trigger, `MyHttpTrigger`, to enable the Open API metadata, and add attribute classes on top of the `FunctionName(...)` decorator.
|
||||
|
||||
```csharp
|
||||
|
@ -120,6 +90,32 @@ namespace MyOpenApiFunctionApp
|
|||
...
|
||||
```
|
||||
|
||||
To generate an Open API document, [OpenApiInfo object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#infoObject) needs to be defined. ***It's totally optional***, but if you want, you can implement the `IOpenApiConfigurationOptions` interface within your Azure Functions project to provide Open API metadata like below:
|
||||
|
||||
```csharp
|
||||
public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
|
||||
{
|
||||
public OpenApiInfo Info { get; set; } = new OpenApiInfo()
|
||||
{
|
||||
Version = "1.0.0",
|
||||
Title = "Open API Document on Azure Functions",
|
||||
Description = "HTTP APIs that run on Azure Functions using Open API specification.",
|
||||
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
|
||||
Contact = new OpenApiContact()
|
||||
{
|
||||
Name = "Contoso",
|
||||
Email = "azfunc-openapi@contoso.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"),
|
||||
}
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
Run the Function app again on your local by running the command below:
|
||||
|
||||
```bash
|
||||
|
|
|
@ -63,84 +63,33 @@ If the above conditions are met, add the following key to your `local.settings.j
|
|||
|
||||
## Open API Metadata Configuration ##
|
||||
|
||||
To generate an Open API document, [OpenApiInfo object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#infoObject) needs to be defined. This information can be declared in **ONE OF THREE** places – `host.json`, `openapisettings.json` or `local.settings.json`.
|
||||
To generate an Open API document, [OpenApiInfo object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#infoObject) needs to be defined. ***It's totally optional***, but if you want, you can implement the `IOpenApiConfigurationOptions` interface within your Azure Functions project to provide Open API metadata like below:
|
||||
|
||||
This library looks for the information in the following order:
|
||||
|
||||
1. `host.json`
|
||||
2. `openapisettings.json`
|
||||
3. `local.settings.json` or App Settings blade on Azure
|
||||
|
||||
|
||||
### `host.json` ###
|
||||
|
||||
Although it has not been officially accepted to be a part of `host.json`, the Open API metadata still can be stored in it like:
|
||||
|
||||
```json
|
||||
```csharp
|
||||
public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
|
||||
{
|
||||
...
|
||||
"openApi": {
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "Open API Sample on Azure Functions",
|
||||
"description": "A sample API that runs on Azure Functions 3.x using Open API specification - from **host. json**.",
|
||||
"termsOfService": "https://github.com/Azure/azure-functions-openapi-extension",
|
||||
"contact": {
|
||||
"name": "Azure Functions Open API",
|
||||
"email": "azfunc-openapi@microsoft.com",
|
||||
"url": "https://github.com/Azure/azure-functions-openapi-extension/issues"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "http://opensource.org/licenses/MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
...
|
||||
public OpenApiInfo Info { get; set; } = new OpenApiInfo()
|
||||
{
|
||||
Version = "1.0.0",
|
||||
Title = "Open API Document on Azure Functions",
|
||||
Description = "HTTP APIs that run on Azure Functions using Open API specification.",
|
||||
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
|
||||
Contact = new OpenApiContact()
|
||||
{
|
||||
Name = "Contoso",
|
||||
Email = "azfunc-openapi@contoso.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"),
|
||||
}
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### `openapisettings.json` ###
|
||||
|
||||
The Open API metadata can be defined in a separate file, `openapisettings.json` like:
|
||||
|
||||
```json
|
||||
{
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "Open API Sample on Azure Functions",
|
||||
"description": "A sample API that runs on Azure Functions 3.x using Open API specification - from **openapisettings.json**.",
|
||||
"termsOfService": "https://github.com/Azure/azure-functions-openapi-extension",
|
||||
"contact": {
|
||||
"name": "Azure Functions Open API",
|
||||
"email": "azfunc-openapi@microsoft.com",
|
||||
"url": "https://github.com/Azure/azure-functions-openapi-extension/issues"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "http://opensource.org/licenses/MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### `local.settings.json` or App Settings Blade ###
|
||||
|
||||
On either your `local.settings.json` or App Settings on Azure Functions instance, those details can be set up like:
|
||||
|
||||
* `OpenApi__Info__Version`: **REQUIRED** Version of Open API document. This is not the version of Open API spec. eg. 1.0.0
|
||||
* `OpenApi__Info__Title`: **REQUIRED** Title of Open API document. eg. Open API Sample on Azure Functions
|
||||
* `OpenApi__Info__Description`: Description of Open API document. eg. A sample API that runs on Azure Functions either 1.x or 2.x using Open API specification.
|
||||
* `OpenApi__Info__TermsOfService`: Terms of service URL. eg. https://github.com/aliencube/AzureFunctions.Extensions
|
||||
* `OpenApi__Info__Contact__Name`: Name of contact. eg. Aliencube Community
|
||||
* `OpenApi__Info__Contact__Email`: Email address for the contact. eg. no-reply@aliencube.org
|
||||
* `OpenApi__Info__Contact__Url`: Contact URL. eg. https://github.com/aliencube/AzureFunctions.Extensions/issues
|
||||
* `OpenApi__Info__License__Name`: **REQUIRED** License name. eg. MIT
|
||||
* `OpenApi__Info__License__Url`: License URL. eg. http://opensource.org/licenses/MIT
|
||||
|
||||
|
||||
## Decorators ##
|
||||
|
||||
In order to render Open API document, this uses attribute classes (decorators).
|
||||
|
|
|
@ -121,79 +121,28 @@ If the above conditions are met, add the following key to your `local.settings.j
|
|||
|
||||
## Open API Metadata Configuration ##
|
||||
|
||||
To generate an Open API document, [OpenApiInfo object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#infoObject) needs to be defined. This information can be declared in **ONE OF THREE** places – `host.json`, `openapisettings.json` or `local.settings.json`.
|
||||
To generate an Open API document, [OpenApiInfo object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#infoObject) needs to be defined. ***It's totally optional***, but if you want, you can implement the `IOpenApiConfigurationOptions` interface within your Azure Functions project to provide Open API metadata like below:
|
||||
|
||||
This library looks for the information in the following order:
|
||||
|
||||
1. `host.json`
|
||||
2. `openapisettings.json`
|
||||
3. `local.settings.json` or App Settings blade on Azure
|
||||
|
||||
|
||||
### `host.json` ###
|
||||
|
||||
Although it has not been officially accepted to be a part of `host.json`, the Open API metadata still can be stored in it like:
|
||||
|
||||
```json
|
||||
```csharp
|
||||
public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
|
||||
{
|
||||
...
|
||||
"openApi": {
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "Open API Sample on Azure Functions",
|
||||
"description": "A sample API that runs on Azure Functions 3.x using Open API specification - from **host. json**.",
|
||||
"termsOfService": "https://github.com/Azure/azure-functions-openapi-extension",
|
||||
"contact": {
|
||||
"name": "Azure Functions Open API",
|
||||
"email": "azfunc-openapi@microsoft.com",
|
||||
"url": "https://github.com/Azure/azure-functions-openapi-extension/issues"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "http://opensource.org/licenses/MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
...
|
||||
public OpenApiInfo Info { get; set; } = new OpenApiInfo()
|
||||
{
|
||||
Version = "1.0.0",
|
||||
Title = "Open API Document on Azure Functions",
|
||||
Description = "HTTP APIs that run on Azure Functions using Open API specification.",
|
||||
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
|
||||
Contact = new OpenApiContact()
|
||||
{
|
||||
Name = "Contoso",
|
||||
Email = "azfunc-openapi@contoso.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"),
|
||||
}
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### `openapisettings.json` ###
|
||||
|
||||
The Open API metadata can be defined in a separate file, `openapisettings.json` like:
|
||||
|
||||
```json
|
||||
{
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "Open API Sample on Azure Functions",
|
||||
"description": "A sample API that runs on Azure Functions 3.x using Open API specification - from **openapisettings.json**.",
|
||||
"termsOfService": "https://github.com/Azure/azure-functions-openapi-extension",
|
||||
"contact": {
|
||||
"name": "Azure Functions Open API",
|
||||
"email": "azfunc-openapi@microsoft.com",
|
||||
"url": "https://github.com/Azure/azure-functions-openapi-extension/issues"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "http://opensource.org/licenses/MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### `local.settings.json` or App Settings Blade ###
|
||||
|
||||
On either your `local.settings.json` or App Settings on Azure Functions instance, those details can be set up like:
|
||||
|
||||
* `OpenApi__Info__Version`: **REQUIRED** Version of Open API document. This is not the version of Open API spec. eg. 1.0.0
|
||||
* `OpenApi__Info__Title`: **REQUIRED** Title of Open API document. eg. Open API Sample on Azure Functions
|
||||
* `OpenApi__Info__Description`: Description of Open API document. eg. A sample API that runs on Azure Functions either 1.x or 2.x using Open API specification.
|
||||
* `OpenApi__Info__TermsOfService`: Terms of service URL. eg. https://github.com/aliencube/AzureFunctions.Extensions
|
||||
* `OpenApi__Info__Contact__Name`: Name of contact. eg. Aliencube Community
|
||||
* `OpenApi__Info__Contact__Email`: Email address for the contact. eg. no-reply@aliencube.org
|
||||
* `OpenApi__Info__Contact__Url`: Contact URL. eg. https://github.com/aliencube/AzureFunctions.Extensions/issues
|
||||
* `OpenApi__Info__License__Name`: **REQUIRED** License name. eg. MIT
|
||||
* `OpenApi__Info__License__Url`: License URL. eg. http://opensource.org/licenses/MIT
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V1Proxy.Configurations
|
||||
{
|
||||
public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
|
||||
{
|
||||
public OpenApiInfo Info { get; set; } = new OpenApiInfo()
|
||||
{
|
||||
Version = "1.0.0",
|
||||
Title = "Open API Sample on Azure Functions Proxy for v1",
|
||||
Description = "A sample API that runs on Azure Functions 1.x using Open API specification.",
|
||||
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
|
||||
Contact = new OpenApiContact()
|
||||
{
|
||||
Name = "Contoso",
|
||||
Email = "azfunc-openapi@contoso.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"),
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,21 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Models;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Services;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV1Proxy
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V1Proxy
|
||||
{
|
||||
public class DummyHttpTrigger
|
||||
{
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="0.2.0-preview" />
|
||||
</ItemGroup>
|
||||
<!-- <ItemGroup>
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="0.2.1-preview" />
|
||||
</ItemGroup> -->
|
||||
<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -42,11 +42,11 @@
|
|||
</ItemGroup>
|
||||
|
||||
<!-- Comment this block if you want to use NuGet package from https://nuget.org -->
|
||||
<!-- <ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\templates\OpenApiEndpoints\IOpenApiHttpTriggerContext.cs" />
|
||||
<Compile Include="..\..\templates\OpenApiEndpoints\OpenApiHttpTriggerContext.cs" />
|
||||
<Compile Include="..\..\templates\OpenApiEndpoints\OpenApiHttpTrigger.cs" />
|
||||
</ItemGroup> -->
|
||||
</ItemGroup>
|
||||
<!-- Comment this block if you want to use NuGet package from https://nuget.org -->
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,21 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Models;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Services;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV1Proxy
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V1Proxy
|
||||
{
|
||||
public class PetStoreHttpTrigger
|
||||
{
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Services;
|
||||
|
||||
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
[assembly: FunctionsStartup(typeof(Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV1Proxy.StartUp))]
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV1Proxy
|
||||
[assembly: FunctionsStartup(typeof(Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V1Proxy.StartUp))]
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V1Proxy
|
||||
{
|
||||
/// <summary>
|
||||
/// This represents the entity to be invoked during the runtime startup.
|
||||
|
|
|
@ -7,22 +7,5 @@
|
|||
"isEnabled": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"openApi": {
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "Open API Sample on Azure Functions Proxy for v1",
|
||||
"description": "A sample API that runs on Azure Functions 1.x using Open API specification.",
|
||||
"termsOfService": "https://github.com/Azure/azure-functions-openapi-extension",
|
||||
"contact": {
|
||||
"name": "Contoso",
|
||||
"email": "azfunc-openapi@contoso.com",
|
||||
"url": "https://github.com/Azure/azure-functions-openapi-extension/issues"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "http://opensource.org/licenses/MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V2IoC.Configurations
|
||||
{
|
||||
public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
|
||||
{
|
||||
public OpenApiInfo Info { get; set; } = new OpenApiInfo()
|
||||
{
|
||||
Version = "2.0.0",
|
||||
Title = "Open API Sample on Azure Functions (IoC)",
|
||||
Description = "A sample API that runs on Azure Functions (IoC) 3.x using Open API specification.",
|
||||
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
|
||||
Contact = new OpenApiContact()
|
||||
{
|
||||
Name = "Contoso",
|
||||
Email = "azfunc-openapi@contoso.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"),
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -3,19 +3,17 @@ using System.Collections.Generic;
|
|||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Models;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Services;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV2IoC
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V2IoC
|
||||
{
|
||||
public class DummyHttpTrigger
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->
|
||||
<!-- <ItemGroup>
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="0.2.0-preview" />
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="0.2.1-preview" />
|
||||
</ItemGroup> -->
|
||||
<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->
|
||||
|
||||
|
|
|
@ -3,19 +3,17 @@ using System.Collections.Generic;
|
|||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Models;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Services;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV2IoC
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V2IoC
|
||||
{
|
||||
public class PetStoreHttpTrigger
|
||||
{
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Services;
|
||||
|
||||
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
[assembly: FunctionsStartup(typeof(Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV2IoC.StartUp))]
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV2IoC
|
||||
[assembly: FunctionsStartup(typeof(Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V2IoC.StartUp))]
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V2IoC
|
||||
{
|
||||
/// <summary>
|
||||
/// This represents the entity to be invoked during the runtime startup.
|
||||
|
|
|
@ -7,22 +7,5 @@
|
|||
"isEnabled": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"openApi": {
|
||||
"info": {
|
||||
"version": "2.0.0",
|
||||
"title": "Open API Sample on Azure Functions (IoC)",
|
||||
"description": "A sample API that runs on Azure Functions (IoC) 2.x using Open API specification.",
|
||||
"termsOfService": "https://github.com/Azure/azure-functions-openapi-extension",
|
||||
"contact": {
|
||||
"name": "Contoso",
|
||||
"email": "azfunc-openapi@contoso.com",
|
||||
"url": "https://github.com/Azure/azure-functions-openapi-extension/issues"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "http://opensource.org/licenses/MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V2Static.Configurations
|
||||
{
|
||||
public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
|
||||
{
|
||||
public OpenApiInfo Info { get; set; } = new OpenApiInfo()
|
||||
{
|
||||
Version = "2.0.0",
|
||||
Title = "Open API Sample on Azure Functions (STATIC)",
|
||||
Description = "A sample API that runs on Azure Functions (STATIC) 3.x using Open API specification.",
|
||||
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
|
||||
Contact = new OpenApiContact()
|
||||
{
|
||||
Name = "Contoso",
|
||||
Email = "azfunc-openapi@contoso.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"),
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -2,18 +2,16 @@ using System.Collections.Generic;
|
|||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Models;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV2Static
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V2Static
|
||||
{
|
||||
public static class DummyHttpTrigger
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->
|
||||
<!-- <ItemGroup>
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="0.2.0-preview" />
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="0.2.1-preview" />
|
||||
</ItemGroup> -->
|
||||
<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->
|
||||
|
||||
|
|
|
@ -2,18 +2,16 @@ using System.Collections.Generic;
|
|||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Models;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV2Static
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V2Static
|
||||
{
|
||||
public static class PetStoreHttpTrigger
|
||||
{
|
||||
|
|
|
@ -7,22 +7,5 @@
|
|||
"excludedTypes": "Request"
|
||||
}
|
||||
}
|
||||
},
|
||||
"openApi": {
|
||||
"info": {
|
||||
"version": "2.0.0",
|
||||
"title": "Open API Sample on Azure Functions (STATIC)",
|
||||
"description": "A sample API that runs on Azure Functions (STATIC) 2.x using Open API specification.",
|
||||
"termsOfService": "https://github.com/Azure/azure-functions-openapi-extension",
|
||||
"contact": {
|
||||
"name": "Contoso",
|
||||
"email": "azfunc-openapi@contoso.com",
|
||||
"url": "https://github.com/Azure/azure-functions-openapi-extension/issues"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "http://opensource.org/licenses/MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V3IoC.Configurations
|
||||
{
|
||||
public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
|
||||
{
|
||||
public OpenApiInfo Info { get; set; } = new OpenApiInfo()
|
||||
{
|
||||
Version = "3.0.0",
|
||||
Title = "Open API Sample on Azure Functions (IoC)",
|
||||
Description = "A sample API that runs on Azure Functions (IoC) 3.x using Open API specification.",
|
||||
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
|
||||
Contact = new OpenApiContact()
|
||||
{
|
||||
Name = "Contoso",
|
||||
Email = "azfunc-openapi@contoso.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"),
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -3,19 +3,17 @@ using System.Collections.Generic;
|
|||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Models;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Services;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV3IoC
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V3IoC
|
||||
{
|
||||
public class DummyHttpTrigger
|
||||
{
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="0.2.0-preview" />
|
||||
</ItemGroup>
|
||||
<!-- <ItemGroup>
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="0.2.1-preview" />
|
||||
</ItemGroup> -->
|
||||
<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -39,11 +39,11 @@
|
|||
</ItemGroup>
|
||||
|
||||
<!-- Comment this block if you want to use NuGet package from https://nuget.org -->
|
||||
<!-- <ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\templates\OpenApiEndpoints\IOpenApiHttpTriggerContext.cs" />
|
||||
<Compile Include="..\..\templates\OpenApiEndpoints\OpenApiHttpTriggerContext.cs" />
|
||||
<Compile Include="..\..\templates\OpenApiEndpoints\OpenApiHttpTrigger.cs" />
|
||||
</ItemGroup> -->
|
||||
</ItemGroup>
|
||||
<!-- Comment this block if you want to use NuGet package from https://nuget.org -->
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -3,19 +3,17 @@ using System.Collections.Generic;
|
|||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Models;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Services;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV3IoC
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V3IoC
|
||||
{
|
||||
public class PetStoreHttpTrigger
|
||||
{
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Services;
|
||||
|
||||
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
[assembly: FunctionsStartup(typeof(Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV3IoC.StartUp))]
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV3IoC
|
||||
[assembly: FunctionsStartup(typeof(Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V3IoC.StartUp))]
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V3IoC
|
||||
{
|
||||
/// <summary>
|
||||
/// This represents the entity to be invoked during the runtime startup.
|
||||
|
|
|
@ -7,22 +7,5 @@
|
|||
"excludedTypes": "Request"
|
||||
}
|
||||
}
|
||||
},
|
||||
"openApi": {
|
||||
"info": {
|
||||
"version": "3.0.0",
|
||||
"title": "Open API Sample on Azure Functions (IoC)",
|
||||
"description": "A sample API that runs on Azure Functions (IoC) 3.x using Open API specification.",
|
||||
"termsOfService": "https://github.com/Azure/azure-functions-openapi-extension",
|
||||
"contact": {
|
||||
"name": "Contoso",
|
||||
"email": "azfunc-openapi@contoso.com",
|
||||
"url": "https://github.com/Azure/azure-functions-openapi-extension/issues"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "http://opensource.org/licenses/MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V3Static.Configurations
|
||||
{
|
||||
public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
|
||||
{
|
||||
public OpenApiInfo Info { get; set; } = new OpenApiInfo()
|
||||
{
|
||||
Version = "3.0.0",
|
||||
Title = "Open API Sample on Azure Functions (STATIC)",
|
||||
Description = "A sample API that runs on Azure Functions (STATIC) 3.x using Open API specification.",
|
||||
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
|
||||
Contact = new OpenApiContact()
|
||||
{
|
||||
Name = "Contoso",
|
||||
Email = "azfunc-openapi@contoso.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"),
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Models;
|
|||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV3Static
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V3Static
|
||||
{
|
||||
public static class DummyHttpTrigger
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->
|
||||
<!-- <ItemGroup>
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="0.2.0-preview" />
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="0.2.1-preview" />
|
||||
</ItemGroup> -->
|
||||
<!-- Uncomment this block if you want to use NuGet package from https://nuget.org -->
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ using Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V3Static.SecurityFl
|
|||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionAppV3Static
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V3Static
|
||||
{
|
||||
public static class PetStoreHttpTrigger
|
||||
{
|
||||
|
|
|
@ -7,48 +7,5 @@
|
|||
"excludedTypes": "Request"
|
||||
}
|
||||
}
|
||||
},
|
||||
"openApi": {
|
||||
"info": {
|
||||
"version": "3.0.0",
|
||||
"title": "Open API Sample on Azure Functions (STATIC)",
|
||||
"description": "A sample API that runs on Azure Functions (STATIC) 3.x using Open API specification.",
|
||||
"termsOfService": "https://github.com/Azure/azure-functions-openapi-extension",
|
||||
"contact": {
|
||||
"name": "Contoso",
|
||||
"email": "azfunc-openapi@contoso.com",
|
||||
"url": "https://github.com/Azure/azure-functions-openapi-extension/issues"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT",
|
||||
"url": "http://opensource.org/licenses/MIT"
|
||||
}
|
||||
// },
|
||||
// "components": {
|
||||
// "securitySchemes": {
|
||||
// "api_key": {
|
||||
// "type": "apiKey",
|
||||
// "in": "header",
|
||||
// "name": "x-functions-key"
|
||||
// },
|
||||
// "api_code": {
|
||||
// "type": "apiKey",
|
||||
// "in": "query",
|
||||
// "name": "code"
|
||||
// },
|
||||
// "petstore_auth": {
|
||||
// "type": "oauth2",
|
||||
// "flows": {
|
||||
// "implicit": {
|
||||
// "authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
|
||||
// "scopes": {
|
||||
// "write:pets": "modify pets in your account",
|
||||
// "read:pets": "read your pets"
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Configuration.AppSettings.Extensions;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
|
||||
|
@ -9,8 +9,6 @@ using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions;
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.CLI
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -156,32 +154,6 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.CLI
|
|||
/// </summary>
|
||||
public virtual HttpSettings HostJsonHttpSettings { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the fully qualified file path of local.settings.json
|
||||
/// </summary>
|
||||
public virtual string LocalSettingsJsonPath
|
||||
{
|
||||
get
|
||||
{
|
||||
this.CompiledPath.ThrowIfNullOrWhiteSpace();
|
||||
|
||||
return $"{this.CompiledPath}{directorySeparator}local.settings.json";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the fully qualified file path of openapisettings.json
|
||||
/// </summary>
|
||||
public virtual string OpenApiSettingsJsonPath
|
||||
{
|
||||
get
|
||||
{
|
||||
this.CompiledPath.ThrowIfNullOrWhiteSpace();
|
||||
|
||||
return $"{this.CompiledPath}{directorySeparator}openapisettings.json";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="OpenApiInfo"/> instance.
|
||||
/// </summary>
|
||||
|
@ -247,55 +219,21 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.CLI
|
|||
|
||||
private void SetOpenApiInfo()
|
||||
{
|
||||
this.HostSettings.ThrowIfNullOrDefault();
|
||||
this.OpenApiSettingsJsonPath.ThrowIfNullOrWhiteSpace();
|
||||
this.LocalSettingsJsonPath.ThrowIfNullOrWhiteSpace();
|
||||
var assembly = Assembly.LoadFrom(this.CompiledDllPath);
|
||||
|
||||
var openApiInfo = this.HostSettings.Get<OpenApiInfo>("openApi:info");
|
||||
if (this.IsValidOpenApiInfo(openApiInfo))
|
||||
var type = assembly.GetTypes()
|
||||
.SingleOrDefault(p => p.GetInterface("IOpenApiConfigurationOptions", ignoreCase: true).IsNullOrDefault() == false);
|
||||
if (type.IsNullOrDefault())
|
||||
{
|
||||
this.OpenApiInfo = openApiInfo;
|
||||
var settings = new OpenApiSettings();
|
||||
this.OpenApiInfo = settings.Info;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (File.Exists(this.OpenApiSettingsJsonPath))
|
||||
{
|
||||
var openapiSettings = File.ReadAllText(this.OpenApiSettingsJsonPath, Encoding.UTF8);
|
||||
openApiInfo = JsonConvert.DeserializeObject<OpenApiSettings>(openapiSettings).Info;
|
||||
if (this.IsValidOpenApiInfo(openApiInfo))
|
||||
{
|
||||
this.OpenApiInfo = openApiInfo;
|
||||
var options = Activator.CreateInstance(type);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var localSettings = new ConfigurationBuilder()
|
||||
.SetBasePath(this.LocalSettingsJsonPath.Replace("local.settings.json", ""))
|
||||
.AddJsonFile("local.settings.json")
|
||||
.Build();
|
||||
|
||||
openApiInfo = new OpenApiInfo()
|
||||
{
|
||||
Version = localSettings.GetValue<string>("Values:OpenApi__Info__Version"),
|
||||
Title = localSettings.GetValue<string>("Values:OpenApi__Info__Title"),
|
||||
Description = localSettings.GetValue<string>("Values:OpenApi__Info__Description"),
|
||||
TermsOfService = new Uri(localSettings.GetValue<string>("Values:OpenApi__Info__TermsOfService")),
|
||||
Contact = new OpenApiContact()
|
||||
{
|
||||
Name = localSettings.GetValue<string>("Values:OpenApi__Info__Contact__Name"),
|
||||
Email = localSettings.GetValue<string>("Values:OpenApi__Info__Contact__Email"),
|
||||
Url = new Uri(localSettings.GetValue<string>("Values:OpenApi__Info__Contact__Url")),
|
||||
},
|
||||
License = new OpenApiLicense()
|
||||
{
|
||||
Name = localSettings.GetValue<string>("Values:OpenApi__Info__License__Name"),
|
||||
Url = new Uri(localSettings.GetValue<string>("Values:OpenApi__Info__License__Url")),
|
||||
}
|
||||
};
|
||||
|
||||
this.OpenApiInfo = openApiInfo;
|
||||
this.OpenApiInfo = (options as IOpenApiConfigurationOptions).Info;
|
||||
}
|
||||
|
||||
private bool IsValidOpenApiInfo(OpenApiInfo openApiInfo)
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -21,10 +19,5 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations
|
|||
/// Gets or sets the <see cref="ExtensionsSettings"/> instance.
|
||||
/// </summary>
|
||||
public virtual ExtensionsSettings Extensions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="OpenApiInfo"/> instance.
|
||||
/// </summary>
|
||||
public virtual OpenApiSettings OpenApi { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations
|
||||
{
|
||||
/// <summary>
|
||||
/// This provides interfaces classes implementing.
|
||||
/// </summary>
|
||||
public interface IOpenApiConfigurationOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="OpenApiInfo"/> instance.
|
||||
/// </summary>
|
||||
OpenApiInfo Info { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
using System.Reflection;
|
||||
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Configuration.AppSettings;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Resolvers;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
|
@ -19,9 +20,8 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations
|
|||
{
|
||||
var basePath = this.GetBasePath();
|
||||
var host = HostJsonResolver.Resolve(this.Config, basePath);
|
||||
var openapi = OpenApiSettingsJsonResolver.Resolve(this.Config, basePath);
|
||||
|
||||
this.OpenApiInfo = OpenApiInfoResolver.Resolve(host, openapi, this.Config);
|
||||
this.OpenApiInfo = OpenApiInfoResolver.Resolve(Assembly.GetExecutingAssembly());
|
||||
this.SwaggerAuthKey = this.Config.GetValue<string>("OpenApi:ApiKey");
|
||||
|
||||
this.HttpSettings = host.GetHttpSettings();
|
||||
|
|
|
@ -5,18 +5,13 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations
|
|||
/// <summary>
|
||||
/// This represents the settings entity for Open API metadata.
|
||||
/// </summary>
|
||||
public class OpenApiSettings
|
||||
public sealed class OpenApiSettings : IOpenApiConfigurationOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="OpenApiInfo"/> instance.
|
||||
/// </summary>
|
||||
public virtual OpenApiInfo Info { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="OpenApiComponents"/> instance.
|
||||
/// </summary>
|
||||
public virtual OpenApiComponents Components { get; set; }
|
||||
|
||||
// public virtual OpenApiSecurityRequirement Security { get; set; }
|
||||
/// <inheritdoc />
|
||||
public OpenApiInfo Info { get; set; } = new OpenApiInfo()
|
||||
{
|
||||
Version = "1.0.0",
|
||||
Title = "Azure Functions Open API Extension",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Configuration.AppSettings.Extensions;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Configuration.AppSettings.Resolvers;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Resolvers
|
||||
|
@ -17,46 +16,22 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Resolvers
|
|||
/// <summary>
|
||||
/// Gets the <see cref="OpenApiInfo"/> instance from one of host.json, openapisettings.json and environment variables.
|
||||
/// </summary>
|
||||
/// <param name="host"><see cref="IConfiguration"/> instance representing host.json.</param>
|
||||
/// <param name="openapi"><see cref="IConfiguration"/> instance representing openapisettings.json.</param>
|
||||
/// <param name="appsettings"><see cref="IConfiguration"/> instance representing environment variables.</param>
|
||||
/// <param name="assembly">The executing assembly instance.</param>
|
||||
/// <returns>Returns <see cref="OpenApiInfo"/> instance resolved.</returns>
|
||||
public static OpenApiInfo Resolve(IConfiguration host = null, IConfiguration openapi = null, IConfiguration appsettings = null)
|
||||
public static OpenApiInfo Resolve(Assembly assembly)
|
||||
{
|
||||
if (host.IsNullOrDefault())
|
||||
var type = assembly.GetTypes()
|
||||
.SingleOrDefault(p => p.GetInterface("IOpenApiConfigurationOptions", ignoreCase: true).IsNullOrDefault() == false);
|
||||
if (type.IsNullOrDefault())
|
||||
{
|
||||
host = HostJsonResolver.Resolve();
|
||||
var settings = new OpenApiSettings();
|
||||
|
||||
return settings.Info;
|
||||
}
|
||||
|
||||
var info = host.Get<OpenApiInfo>("openApi:info");
|
||||
if (info.IsValid())
|
||||
{
|
||||
return info;
|
||||
}
|
||||
var options = Activator.CreateInstance(type);
|
||||
|
||||
if (openapi.IsNullOrDefault())
|
||||
{
|
||||
openapi = OpenApiSettingsJsonResolver.Resolve();
|
||||
}
|
||||
|
||||
info = openapi.Get<OpenApiInfo>("info");
|
||||
if (info.IsValid())
|
||||
{
|
||||
return info;
|
||||
}
|
||||
|
||||
if (appsettings.IsNullOrDefault())
|
||||
{
|
||||
appsettings = ConfigurationResolver.Resolve();
|
||||
}
|
||||
|
||||
info = appsettings.Get<OpenApiInfo>("OpenApi:Info");
|
||||
if (info.IsValid())
|
||||
{
|
||||
return info;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Open API metadata not found");
|
||||
return (options as IOpenApiConfigurationOptions).Info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
using System.IO;
|
||||
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Configuration.AppSettings.Resolvers;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Resolvers
|
||||
{
|
||||
/// <summary>
|
||||
/// This represents the resolver entity for openapisettings.json.
|
||||
/// </summary>
|
||||
public static class OpenApiSettingsJsonResolver
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IConfiguration"/> instance from openapisettings.json
|
||||
/// </summary>
|
||||
/// <param name="config"><see cref="IConfiguration"/> instance from the environment variables - either local.settings.json or App Settings blade.</param>
|
||||
/// <param name="basePath">Base path of the executing Azure Functions assembly.</param>
|
||||
public static IConfiguration Resolve(IConfiguration config = null, string basePath = null)
|
||||
{
|
||||
if (config.IsNullOrDefault())
|
||||
{
|
||||
config = ConfigurationResolver.Resolve();
|
||||
}
|
||||
|
||||
if (basePath.IsNullOrWhiteSpace())
|
||||
{
|
||||
basePath = ConfigurationResolver.GetBasePath(config);
|
||||
}
|
||||
|
||||
var builder = new ConfigurationBuilder();
|
||||
|
||||
if (!File.Exists($"{basePath.TrimEnd('/')}/openapisettings.json"))
|
||||
{
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
var openapi = builder.SetBasePath(basePath)
|
||||
.AddJsonFile("openapisettings.json")
|
||||
.Build();
|
||||
|
||||
return openapi;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,7 +35,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
|
|||
{
|
||||
var host = HostJsonResolver.Resolve();
|
||||
|
||||
this.OpenApiInfo = OpenApiInfoResolver.Resolve(host);
|
||||
this.OpenApiInfo = OpenApiInfoResolver.Resolve(this.GetExecutingAssembly());
|
||||
this.HttpSettings = host.GetHttpSettings();
|
||||
|
||||
var filter = new RouteConstraintFilter();
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
|
||||
|
||||
using FluentAssertions;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Configurations
|
||||
{
|
||||
[TestClass]
|
||||
public class OpenApiSettingsTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Given_Value_Property_Should_Return_Value()
|
||||
{
|
||||
var settings = new OpenApiSettings();
|
||||
|
||||
settings.Info.Should().NotBeNull();
|
||||
settings.Info.Version.Should().Be("1.0.0");
|
||||
settings.Info.Title.Should().Be("Azure Functions Open API Extension");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Resolvers;
|
||||
using System.Reflection;
|
||||
|
||||
using FluentAssertions;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Resolvers;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
|
@ -15,7 +15,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Resolvers
|
|||
public void Given_Type_Then_It_Should_Have_Methods()
|
||||
{
|
||||
typeof(OpenApiInfoResolver)
|
||||
.Should().HaveMethod("Resolve", new[] { typeof(IConfiguration), typeof(IConfiguration), typeof(IConfiguration) })
|
||||
.Should().HaveMethod("Resolve", new[] { typeof(Assembly) })
|
||||
.Which.Should().Return<OpenApiInfo>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Resolvers;
|
||||
|
||||
using FluentAssertions;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Moq;
|
||||
|
||||
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Resolvers
|
||||
{
|
||||
[TestClass]
|
||||
public class OpenApiSettingsJsonResolverTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Given_Parameters_When_Resolve_Invoked_Then_It_Should_Return_Result()
|
||||
{
|
||||
var section = new Mock<IConfigurationSection>();
|
||||
section.SetupGet(p => p.Value).Returns(string.Empty);
|
||||
|
||||
var env = new Mock<IConfiguration>();
|
||||
env.Setup(p => p.GetSection(It.IsAny<string>())).Returns(section.Object);
|
||||
|
||||
var result = OpenApiSettingsJsonResolver.Resolve(env.Object);
|
||||
|
||||
result.Should().NotBeNull()
|
||||
.And.BeAssignableTo<IConfiguration>();
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче