This commit is contained in:
Justin Yoo 2021-04-02 17:59:20 +09:00 коммит произвёл GitHub
Родитель ee89ea3461
Коммит 2a58b606a5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
63 изменённых файлов: 375 добавлений и 257 удалений

Просмотреть файл

@ -1,4 +1,4 @@
# Azure Functions Open API Extension [![](https://img.shields.io/nuget/dt/Microsoft.Azure.WebJobs.Extensions.OpenApi.svg)](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi/) [![](https://img.shields.io/nuget/v/Microsoft.Azure.WebJobs.Extensions.OpenApi.svg)](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi/) #
# Azure Functions OpenAPI Extension [![](https://img.shields.io/nuget/dt/Microsoft.Azure.WebJobs.Extensions.OpenApi.svg)](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi/) [![](https://img.shields.io/nuget/v/Microsoft.Azure.WebJobs.Extensions.OpenApi.svg)](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi/) #
## Acknowledgement ##
@ -7,16 +7,16 @@
## Getting Started ##
* [**Enable Open API documents to your Azure Functions HTTP Trigger (Preview)**](docs/enable-open-api-endpoints.md): This document shows how to enable Open API extension on your Azure Functions applications and render Swagger UI, and Open API v2 and v3 documents on-the-fly. It's currently in preview.
* [**Enable OpenAPI documents to your Azure Functions HTTP Trigger (Preview)**](docs/enable-open-api-endpoints.md): This document shows how to enable OpenAPI extension on your Azure Functions applications and render Swagger UI, and OpenAPI v2 and v3 documents on-the-fly. It's currently in preview.
* [**Microsoft.Azure.WebJobs.Extensions.OpenApi**](docs/openapi.md)
* [**Microsoft.Azure.WebJobs.Extensions.OpenApi.Core**](docs/openapi-core.md)
* [**Azure Functions v1 Support**](docs/azure-functions-v1-support.md): This document shows how to support Azure Functions v1 runtime with this Open API extension.
* [**Integrating Open API-enabled Azure Functions to Azure API Management**](docs/integrate-with-apim.md): This document shows how to integrate the Azure Functions application with [Azure API Management](https://docs.microsoft.com/azure/api-management/api-management-key-concepts?WT.mc_id=dotnet_0000_juyoo), via this Open API extension.
<!-- * [**Integrating Open API-enabled Azure Functions to Power Platform**](docs/integrate-with-powerplatform.md): This document shows how to integrate the Azure Functions application with [Power Platform](https://powerplatform.microsoft.com/?WT.mc_id=dotnet_0000_juyoo), via this Open API extension. -->
* [**Azure Functions v1 Support**](docs/azure-functions-v1-support.md): This document shows how to support Azure Functions v1 runtime with this OpenAPI extension.
* [**Integrating OpenAPI-enabled Azure Functions to Azure API Management**](docs/integrate-with-apim.md): This document shows how to integrate the Azure Functions application with [Azure API Management](https://docs.microsoft.com/azure/api-management/api-management-key-concepts?WT.mc_id=dotnet_0000_juyoo), via this OpenAPI extension.
<!-- * [**Integrating OpenAPI-enabled Azure Functions to Power Platform**](docs/integrate-with-powerplatform.md): This document shows how to integrate the Azure Functions application with [Power Platform](https://powerplatform.microsoft.com/?WT.mc_id=dotnet_0000_juyoo), via this OpenAPI extension. -->
* [**Shortening Swagger UI Page URL with `proxies.json`**](docs/shortening-swagger-ui-page-url.md): This document shows how to shorten both Swagger UI page URL and `swagger.json` document URL, using `proxies.json`.
## Sample Azure Function Apps with Open API Metadata Enabled ##
## Sample Azure Function Apps with OpenAPI Metadata Enabled ##
* [Function App v1 proxy](samples/Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V1Proxy)
* [Function App v2 static](samples/Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V2Static)

Просмотреть файл

@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Product>Azure Functions Open API Extension</Product>
<Product>Azure Functions OpenAPI Extension</Product>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageProjectUrl>https://github.com/Azure/azure-functions-openapi-extension</PackageProjectUrl>
<RepositoryUrl>https://github.com/Azure/azure-functions-openapi-extension</RepositoryUrl>

Просмотреть файл

@ -1,6 +1,6 @@
# Support Azure Functions v1 with Open API Extension #
# Support Azure Functions v1 with OpenAPI Extension #
Due to the backward compatibility issue, this Open API extension has dropped supporting Azure Functions v1 runtime. However, there are many enterprise scenarios that still need Azure Functions v1 runtime. Although there is no direct support from this Open API extension, you can still take the benefits of using this extension, using the [Azure Functions Proxy][az func proxy] feature.
Due to the backward compatibility issue, this OpenAPI extension has dropped supporting Azure Functions v1 runtime. However, there are many enterprise scenarios that still need Azure Functions v1 runtime. Although there is no direct support from this OpenAPI extension, you can still take the benefits of using this extension, using the [Azure Functions Proxy][az func proxy] feature.
## Prerequisites ##
@ -56,9 +56,9 @@ namespace MyV1FunctionAppProxy
```
## Add Open API Extension ##
## Add OpenAPI Extension ##
To enable Open API metadata, you will need to install a NuGet package, [Microsoft.Azure.WebJobs.Extensions.OpenApi][az func openapi extension].
To enable OpenAPI metadata, 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
@ -84,7 +84,7 @@ namespace MyV1FunctionAppProxy
...
```
By doing so, this Function app is now able to generate the Open API definition document on-the-fly. However, it won't work as expected because there is no business logic implemented.
By doing so, this Function app is now able to generate the OpenAPI definition document on-the-fly. However, it won't work as expected because there is no business logic implemented.
## Add Functions Proxy ##
@ -132,7 +132,7 @@ Then all your API requests to the proxy function are forwarded to the v1 Functio
## Clean-up Resources ##
When you continue to the another step, [Integrating Open API-enabled Azure Functions with Azure API Management][docs apim], you'll need to keep all your resources in place to build on what you've already done.
When you continue to the another step, [Integrating OpenAPI-enabled Azure Functions with Azure API Management][docs apim], you'll need to keep all your resources in place to build on what you've already done.
Otherwise, you can use the following steps to delete the function app and its related resources to avoid incurring any further costs.
@ -152,10 +152,10 @@ To learn more about Functions costs, see [Estimating Consumption plan costs][az
## Next Steps ##
You have got an Azure Functions app with Open API metadata enabled. In the next articles, you will be able to integrate this Open API-enabled Azure Functions app with either [Azure API Management][az apim], [Azure Logic Apps][az logapp] or [Power Platform][power platform].
You have got an Azure Functions app with OpenAPI metadata enabled. In the next articles, you will be able to integrate this OpenAPI-enabled Azure Functions app with either [Azure API Management][az apim], [Azure Logic Apps][az logapp] or [Power Platform][power platform].
* [Integrating Open API-enabled Azure Functions to Azure API Management][docs apim]
<!-- * [Integrating Open API-enabled Azure Functions to Power Platform][docs powerplatform] -->
* [Integrating OpenAPI-enabled Azure Functions to Azure API Management][docs apim]
<!-- * [Integrating OpenAPI-enabled Azure Functions to Power Platform][docs powerplatform] -->
[image-10]: images/image-10.png

Просмотреть файл

@ -1,11 +1,11 @@
# Enable Open API Endpoints on Azure Functions (Preview) #
# Enable OpenAPI Endpoints on Azure Functions (Preview) #
[Open API metadata][openapi] supports in Azure Functions is now available with this extension, [Azure Functions Open API Extension][az func openapi extension]. With this extension, you can directly let your API endpoints be discoverable.
[OpenAPI metadata][openapi] supports in Azure Functions is now available with this extension, [Azure Functions OpenAPI Extension][az func openapi extension]. With this extension, you can directly let your API endpoints be discoverable.
> [!IMPORTANT]
> This extension supports only Azure Functions v2 and onwards. If you want to get your Azure Functions v1 supported, find [this preview document][az func openapi v1 preview] or [community contribution][az func openapi community].
[Open API metadata][openapi] allows wide variety of other software and applications to consume an Azure Functions app hosting HTTP APIs. The software and applications include Microsoft products and services like [Power Platform][power platform], [API Management][az apim] and third-party tools like [Postman][postman].
[OpenAPI metadata][openapi] allows wide variety of other software and applications to consume an Azure Functions app hosting HTTP APIs. The software and applications include Microsoft products and services like [Power Platform][power platform], [API Management][az apim] and third-party tools like [Postman][postman].
## Prerequisites ##
@ -61,9 +61,9 @@ http://localhost:7071/api/MyHttpTrigger?name=OpenApi
![Azure Functions run result on a web browser][image-02]
## Enable Open API Document ##
## Enable OpenAPI Document ##
To enable Open API document, you will need to install a NuGet package, [Microsoft.Azure.WebJobs.Extensions.OpenApi][az func openapi extension].
To enable OpenAPI 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
@ -71,7 +71,7 @@ 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.
With [Visual Studio Code][vs code], open your HTTP trigger, `MyHttpTrigger`, to enable the OpenAPI metadata, and add attribute classes on top of the `FunctionName(...)` decorator.
```csharp
namespace MyOpenApiFunctionApp
@ -90,7 +90,7 @@ 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:
To generate an OpenAPI 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 OpenAPI metadata like below:
```csharp
public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
@ -98,8 +98,8 @@ 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.",
Title = "OpenAPI Document on Azure Functions",
Description = "HTTP APIs that run on Azure Functions using OpenAPI specification.",
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
Contact = new OpenApiContact()
{
@ -130,7 +130,7 @@ http://localhost:7071/api/swagger/ui
![Swagger UI for Azure Functions app on local machine][image-03]
Copy the link in the search bar at the top of the page and open it on another web browser window, and you will be able to see the Open API 2.0 document generated on-the-fly.
Copy the link in the search bar at the top of the page and open it on another web browser window, and you will be able to see the OpenAPI 2.0 document generated on-the-fly.
![swagger.json on local machine][image-04]
@ -203,7 +203,7 @@ Once logged into Azure, create a function app and related resources in your Azur
## Clean-up Resources ##
When you continue to the next step, [Integrating Open API-enabled Azure Functions with Azure API Management][docs apim], you'll need to keep all your resources in place to build on what you've already done.
When you continue to the next step, [Integrating OpenAPI-enabled Azure Functions with Azure API Management][docs apim], you'll need to keep all your resources in place to build on what you've already done.
Otherwise, you can use the following steps to delete the function app and its related resources to avoid incurring any further costs.
@ -223,11 +223,11 @@ To learn more about Functions costs, see [Estimating Consumption plan costs][az
## Next Steps ##
You have got an Azure Functions app with Open API metadata enabled. In the next articles, you will be able to integrate this Open API-enabled Azure Functions app with either [Azure API Management][az apim], [Azure Logic Apps][az logapp] or [Power Platform][power platform].
You have got an Azure Functions app with OpenAPI metadata enabled. In the next articles, you will be able to integrate this OpenAPI-enabled Azure Functions app with either [Azure API Management][az apim], [Azure Logic Apps][az logapp] or [Power Platform][power platform].
* [Support Azure Functions v1 with Open API Extension][docs v1 suppport]
* [Integrating Open API-enabled Azure Functions to Azure API Management][docs apim]
<!-- * [Integrating Open API-enabled Azure Functions to Power Platform][docs powerplatform] -->
* [Support Azure Functions v1 with OpenAPI Extension][docs v1 suppport]
* [Integrating OpenAPI-enabled Azure Functions to Azure API Management][docs apim]
<!-- * [Integrating OpenAPI-enabled Azure Functions to Power Platform][docs powerplatform] -->
[image-01]: images/image-01.png

Просмотреть файл

@ -1,6 +1,6 @@
# Integrating Open API-enabled Azure Functions with Azure API Management #
# Integrating OpenAPI-enabled Azure Functions with Azure API Management #
[Azure API Management][az apim] provides HTTP API consumers with a consistent way of using API gateway features for back-end API services. You can integrate your Azure Function app with Azure API Management by [directly importing the Function app][az apim azfunc import]. But you can also make use of this Open API extension so that everything will be set up at one go.
[Azure API Management][az apim] provides HTTP API consumers with a consistent way of using API gateway features for back-end API services. You can integrate your Azure Function app with Azure API Management by [directly importing the Function app][az apim azfunc import]. But you can also make use of this OpenAPI extension so that everything will be set up at one go.
## Prerequisites ##
@ -31,7 +31,7 @@ az apim create \
## Create Azure Function App ##
Please refer to [the Azure Function app with the Open API extension enabled](docs/enable-open-api-endpoints.md). Once the Function app is deployed to Azure, make sure you can generate `swagger.json` document on-the-fly.
Please refer to [the Azure Function app with the OpenAPI extension enabled](docs/enable-open-api-endpoints.md). Once the Function app is deployed to Azure, make sure you can generate `swagger.json` document on-the-fly.
![swagger.json on Azure][image-11]
@ -57,7 +57,7 @@ Azure Functions API is now successfully imported.
## Test API Endpoint through Azure API Management ##
To test the imported API endpoint, go to the newly imported API by clicking the `APIs` blade, clicking the `Open API Sample on Azure...` tab and choosing one of API endpoints, and selecting the `Test` tab.
To test the imported API endpoint, go to the newly imported API by clicking the `APIs` blade, clicking the `OpenAPI Sample on Azure...` tab and choosing one of API endpoints, and selecting the `Test` tab.
![Testing imported API endpoint][image-15]
@ -72,7 +72,7 @@ Confirm the test has been successfully performed.
## Clean-up Resources ##
When you continue to the another step, [Support Azure Functions v1 with Open API Extension][docs v1 suppport], you'll need to keep all your resources in place to build on what you've already done.
When you continue to the another step, [Support Azure Functions v1 with OpenAPI Extension][docs v1 suppport], you'll need to keep all your resources in place to build on what you've already done.
Otherwise, you can use the following steps to delete the function app and its related resources to avoid incurring any further costs.
@ -92,10 +92,10 @@ To learn more about Functions costs, see [Estimating Consumption plan costs][az
## Next Steps ##
You have got an Azure API Management integrated with Azure Functions that implements the Open API extension. In the next articles, you will be able to support Azure Functions v1 runtime or integrate this Open API-enabled Azure Functions app with either [Azure Logic Apps][az logapp] or [Power Platform][power platform].
You have got an Azure API Management integrated with Azure Functions that implements the OpenAPI extension. In the next articles, you will be able to support Azure Functions v1 runtime or integrate this OpenAPI-enabled Azure Functions app with either [Azure Logic Apps][az logapp] or [Power Platform][power platform].
* [Support Azure Functions v1 with Open API Extension][docs v1 support]
<!-- * [Integrating Open API-enabled Azure Functions to Power Platform][docs powerplatform] -->
* [Support Azure Functions v1 with OpenAPI Extension][docs v1 support]
<!-- * [Integrating OpenAPI-enabled Azure Functions to Power Platform][docs powerplatform] -->
[image-10]: images/image-10.png

Просмотреть файл

@ -1,3 +1,3 @@
# Integrating Open API-enabled Azure Functions with Power Platform #
# Integrating OpenAPI-enabled Azure Functions with Power Platform #
TBD

Просмотреть файл

@ -2,9 +2,9 @@
![Build and Test](https://github.com/Azure/azure-functions-openapi-extension/workflows/Build%20and%20Test/badge.svg) [![](https://img.shields.io/static/v1?label=tag&message=cli-*&color=brightgreen)](https://github.com/Azure/azure-functions-openapi-extension/releases) [![](https://img.shields.io/static/v1?label=tag&message=cli-*&color=brightgreen)](https://github.com/Azure/azure-functions-openapi-extension/releases)
This generates Open API document through command-line without having to run the Azure Functions instance. The more details around this CLI can be found on this [blog post](https://devkimchi.com/2020/07/08/generating-open-api-doc-for-azure-functions-in-command-line/).
This generates OpenAPI document through command-line without having to run the Azure Functions instance. The more details around this CLI can be found on this [blog post](https://devkimchi.com/2020/07/08/generating-open-api-doc-for-azure-functions-in-command-line/).
> **NOTE**: This CLI supports both [Open API 2.0 (aka Swagger)](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) and [Open API 3.0.1](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md) spec.
> **NOTE**: This CLI supports both [OpenAPI 2.0 (aka Swagger)](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) and [OpenAPI 3.0.1](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md) spec.
## Issues? ##
@ -23,9 +23,9 @@ The CLI is available for download at [GitHub](https://github.com/Azure/azure-fun
* Windows: `azfuncopenapi-v<version>-netcoreapp3.1-win-x64.zip`
### Generating Open API Document ###
### Generating OpenAPI Document ###
Once you have an Azure Functions instance with [Azure Functions Open API extension](openapi.md) enabled, then you are ready to run this CLI.
Once you have an Azure Functions instance with [Azure Functions OpenAPI extension](openapi.md) enabled, then you are ready to run this CLI.
For Windows:
@ -60,14 +60,14 @@ Here are options:
* `-p|--project`: Project path. It can be a fully qualified project path including `.csproj` or project directory. Default is the current directory.
* `-c|--configuration`: Configuration value. It can be either `Debug`, `Release` or something else. Default is `Debug`.
* `-t|--target`: Target framework. It should be `netcoreapp2.x` for Azure Functions v2, and `netcoreapp3.x` for Azure Functions v3. Default is `netcoreapp2.1`.
* `-v|--version`: Open API spec version. It should be either `v2` or `v3`. Default is `v2`.
* `-f|--format`: Open API document format. It should be either `json` or `yaml`. Default is `json`.
* `-o|--output`: Output directory for the generated Open API document. It can be a fully qualified directory path or relative path from `<PROJECT_ROOT>/bin/<CONFIGURATION>/<TARGET_FRAMEWORK>`. Default is `output`.
* `-v|--version`: OpenAPI spec version. It should be either `v2` or `v3`. Default is `v2`.
* `-f|--format`: OpenAPI document format. It should be either `json` or `yaml`. Default is `json`.
* `-o|--output`: Output directory for the generated OpenAPI document. It can be a fully qualified directory path or relative path from `<PROJECT_ROOT>/bin/<CONFIGURATION>/<TARGET_FRAMEWORK>`. Default is `output`.
* `--console`: Value indicating whether to display the generated document to console or not. Default is `false`.
## Roadmap ##
* Distribution through a npm package.
* Project boilerplate generation, if an Open API doc is provided.
* Project boilerplate generation, if an OpenAPI doc is provided.

Просмотреть файл

@ -2,9 +2,9 @@
![Build and Test](https://github.com/Azure/azure-functions-openapi-extension/workflows/Build%20and%20Test/badge.svg) [![](https://img.shields.io/nuget/dt/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.svg)](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/) [![](https://img.shields.io/nuget/v/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.svg)](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/)
This enables Azure Functions to render Open API document and Swagger UI. The more details around the Swagger UI on Azure Functions can be found on this [blog post](https://devkimchi.com/2019/02/02/introducing-swagger-ui-on-azure-functions/).
This enables Azure Functions to render OpenAPI document and Swagger UI. The more details around the Swagger UI on Azure Functions can be found on this [blog post](https://devkimchi.com/2019/02/02/introducing-swagger-ui-on-azure-functions/).
> **NOTE**: This extension supports both [Open API 2.0 (aka Swagger)](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) and [Open API 3.0.1](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md) spec.
> **NOTE**: This extension supports both [OpenAPI 2.0 (aka Swagger)](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) and [OpenAPI 3.0.1](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md) spec.
## Acknowledgement ##
@ -21,16 +21,16 @@ While using this library, if you find any issue, please raise a ticket on the [I
### Install NuGet Package ###
In order for your Azure Functions app to enable Open API capability, download the following NuGet package into your Azure Functions project.
In order for your Azure Functions app to enable OpenAPI capability, download the following NuGet package into your Azure Functions project.
```bash
dotnet add <PROJECT> package Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApi.Core
```
### Expose Endpoints to Open API Document ###
### Expose Endpoints to OpenAPI Document ###
In order to include HTTP endpoints into the Open API document, use attribute classes (decorators) like:
In order to include HTTP endpoints into the OpenAPI document, use attribute classes (decorators) like:
```csharp
[FunctionName(nameof(AddDummy))]
@ -52,18 +52,18 @@ public static async Task<IActionResult> AddDummy(
This key is only required if:
* The Function app is deployed to Azure, and
* The Open API related endpoints has the `AuthorizationLevel` value other than `Anonymous`.
* The OpenAPI related endpoints has the `AuthorizationLevel` value other than `Anonymous`.
If the above conditions are met, add the following key to your `local.settings.json` or App Settings blade on Azure.
* `OpenApi__ApiKey`: either the host key value or the master key value.
> **NOTE**: It is NOT required if your Open API related endpoints are set to the authorisation level of `Anonymous`.
> **NOTE**: It is NOT required if your OpenAPI related endpoints are set to the authorisation level of `Anonymous`.
## Open API Metadata Configuration ##
## OpenAPI 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. ***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:
To generate an OpenAPI 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 OpenAPI metadata like below:
```csharp
public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
@ -71,8 +71,8 @@ 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.",
Title = "OpenAPI Document on Azure Functions",
Description = "HTTP APIs that run on Azure Functions using OpenAPI specification.",
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
Contact = new OpenApiContact()
{
@ -106,7 +106,7 @@ public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
}
```
> **NOTE**: As this extension automatically generates the server URL, these extra URLs are only appended, not overwriting the one automatically generated. And, the API v2 (Swagger) document won't be impacted by these extra URLs, while the Open API v3 document shows all server URLs in the document, including the automatically generated one.
> **NOTE**: As this extension automatically generates the server URL, these extra URLs are only appended, not overwriting the one automatically generated. And, the API v2 (Swagger) document won't be impacted by these extra URLs, while the OpenAPI v3 document shows all server URLs in the document, including the automatically generated one.
Instead of implementing `IOpenApiConfigurationOptions`, you can inherit `DefaultOpenApiConfigurationOptions`. As both `Info` and `Servers` properties have the modifier of `virtual`, you can freely override both or leave them as default.
@ -116,8 +116,8 @@ public class MyOpenApiConfigurationOptions : DefaultOpenApiConfigurationOptions
public override 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.",
Title = "OpenAPI Document on Azure Functions",
Description = "HTTP APIs that run on Azure Functions using OpenAPI specification.",
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
Contact = new OpenApiContact()
{
@ -134,24 +134,24 @@ public class MyOpenApiConfigurationOptions : DefaultOpenApiConfigurationOptions
}
```
## Open API Response Header Customisation ##
## OpenAPI Response Header Customisation ##
Often, custom response headers need to be added. For those custom responses
## Decorators ##
In order to render Open API document, this uses attribute classes (decorators).
In order to render OpenAPI document, this uses attribute classes (decorators).
> **NOTE**: Not all Open API specs have been implemented.
> **NOTE**: Not all OpenAPI specs have been implemented.
### `OpenApiIgnoreAttribute` ###
If there is any HTTP trigger that you want to exclude from the Open API document, use this decorator. Typically this is used for the endpoints that render Open API document and Swagger UI.
If there is any HTTP trigger that you want to exclude from the OpenAPI document, use this decorator. Typically this is used for the endpoints that render OpenAPI document and Swagger UI.
```csharp
[FunctionName(nameof(RenderSwaggerDocument))]
[OpenApiIgnore] // This HTTP endpoint is excluded from the Open API document.
[OpenApiIgnore] // This HTTP endpoint is excluded from the OpenAPI document.
public static async Task<IActionResult> RenderSwaggerDocument(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "swagger.{extension}")] HttpRequest req,
string extension,
@ -211,7 +211,7 @@ public static async Task<IActionResult> GetSample(
* `Explode`: indicates whether a query parameter is used multiple times (eg. `foo=bar1&foo=bar2&foo=bar3`) or not (eg. `foo=bar1,bar2,bar3`). Default value is `false`.
* `Required`: indicates whether the parameter is required or not. Default value is `false`.
* `Visibility`: indicates how the parameter is visible in Azure Logic Apps &ndash; `important`, `advanced` or `internal`. Default value is `undefined`.
* `Deprecated`: indicates whether the parameter is deprecated or not. Default is `false`. If this is set to `true`, this parameter won't be showing up the UI and Open API document.
* `Deprecated`: indicates whether the parameter is deprecated or not. Default is `false`. If this is set to `true`, this parameter won't be showing up the UI and OpenAPI document.
### `OpenApiSecurityAttribute` ###
@ -303,7 +303,7 @@ public static async Task<IActionResult> PostSample(
* `BodyType`: defines the type of the request payload.
* `Description`: is the description of the request payload.
* `Required`: indicates whether the request payload is mandatory or not.
* `Deprecated`: indicates whether the request body is deprecated or not. Default is `false`. If this is set to `true`, this request body won't be showing up the UI and Open API document.
* `Deprecated`: indicates whether the request body is deprecated or not. Default is `false`. If this is set to `true`, this request body won't be showing up the UI and OpenAPI document.
### `OpenApiResponseWithBodyAttribute` ###
@ -340,7 +340,7 @@ public static class DummyHttpTrigger
* `BodyType`: defines the type of the response payload.
* `Summary`: is the summary of the response.
* `Description`: is the description of the response.
* `Deprecated`: indicates whether the response body is deprecated or not. Default is `false`. If this is set to `true`, this response body won't be showing up the UI and Open API document.
* `Deprecated`: indicates whether the response body is deprecated or not. Default is `false`. If this is set to `true`, this response body won't be showing up the UI and OpenAPI document.
### `OpenApiResponseWithoutBodyAttribute` ###

Просмотреть файл

@ -2,9 +2,9 @@
![Build and Test](https://github.com/Azure/azure-functions-openapi-extension/workflows/Build%20and%20Test/badge.svg) [![](https://img.shields.io/nuget/dt/Microsoft.Azure.WebJobs.Extensions.OpenApi.svg)](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi/) [![](https://img.shields.io/nuget/v/Microsoft.Azure.WebJobs.Extensions.OpenApi.svg)](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi/)
This enables Azure Functions to render Open API document and Swagger UI. The more details around the Swagger UI on Azure Functions can be found on this [blog post](https://devkimchi.com/2019/02/02/introducing-swagger-ui-on-azure-functions/).
This enables Azure Functions to render OpenAPI document and Swagger UI. The more details around the Swagger UI on Azure Functions can be found on this [blog post](https://devkimchi.com/2019/02/02/introducing-swagger-ui-on-azure-functions/).
> **NOTE**: This extension supports both [Open API 2.0 (aka Swagger)](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) and [Open API 3.0.1](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md) spec.
> **NOTE**: This extension supports both [OpenAPI 2.0 (aka Swagger)](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) and [OpenAPI 3.0.1](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md) spec.
## Acknowledgement ##
@ -21,7 +21,7 @@ While using this library, if you find any issue, please raise a ticket on the [I
### Install NuGet Package ###
In order for your Azure Functions app to enable Open API capability, download the following NuGet package into your Azure Functions project.
In order for your Azure Functions app to enable OpenAPI capability, download the following NuGet package into your Azure Functions project.
```bash
dotnet add <PROJECT> package Microsoft.Azure.WebJobs.Extensions.OpenApi
@ -30,7 +30,7 @@ dotnet add <PROJECT> package Microsoft.Azure.WebJobs.Extensions.OpenApi
### Change Authorization Level ###
As a default, all endpoints to render Swagger UI and Open API documents have the authorisation level of `AuthorizationLevel.Anonymous`.
As a default, all endpoints to render Swagger UI and OpenAPI documents have the authorisation level of `AuthorizationLevel.Anonymous`.
```csharp
@ -111,18 +111,18 @@ public static async Task<IActionResult> RenderSwaggerUI(
This key is only required if:
* The Function app is deployed to Azure, and
* The Open API related endpoints has the `AuthorizationLevel` value other than `Anonymous`.
* The OpenAPI related endpoints has the `AuthorizationLevel` value other than `Anonymous`.
If the above conditions are met, add the following key to your `local.settings.json` or App Settings blade on Azure.
* `OpenApi__ApiKey`: either the host key value or the master key value.
> **NOTE**: It is NOT required if your Open API related endpoints are set to the authorisation level of `Anonymous`.
> **NOTE**: It is NOT required if your OpenAPI related endpoints are set to the authorisation level of `Anonymous`.
## Open API Metadata Configuration ##
## OpenAPI 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. ***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:
To generate an OpenAPI 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 OpenAPI metadata like below:
```csharp
public class OpenApiConfigurationOptions : IOpenApiConfigurationOptions
@ -130,8 +130,8 @@ 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.",
Title = "OpenAPI Document on Azure Functions",
Description = "HTTP APIs that run on Azure Functions using OpenAPI specification.",
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
Contact = new OpenApiContact()
{

Просмотреть файл

@ -1,6 +1,6 @@
# Shortening Swagger UI Page URL and `swagger.json` URL with `proxies.json` #
With default implementation, Azure Functions Open API extension has the following endpoint URLs:
With default implementation, Azure Functions OpenAPI extension has the following endpoint URLs:
* `https://<your_function_name>.azurewebsites.net/api/swagger/ui`
* `https://<your_function_name>.azurewebsites.net/api/swagger.json`

Просмотреть файл

@ -10,5 +10,5 @@ Hotfix on `v0.2.0-preview`
### Fixes ###
* #33 `NullReferenceException` of `OpenApiSecurityAttribute` while rendering Open API document
* #33 `NullReferenceException` of `OpenApiSecurityAttribute` while rendering OpenAPI document

Просмотреть файл

@ -1,17 +1,17 @@
## Release Notes ##
Updated Open API metadata generation logic.
Updated OpenAPI metadata generation logic.
> **NOTE**: There is no `v0.3.0-preview` and `v0.3.1-preview`!
### Changes ###
* Removed dependencies from `host.json`, `openapisetting.json` and `local.settings.json` to generate the Open API metadata
* Removed dependencies from `host.json`, `openapisetting.json` and `local.settings.json` to generate the OpenAPI metadata
* #2 openapisettings.json not honored
* #4 null Open API metadata in host.json should be allowed with default values
* #4 null OpenAPI metadata in host.json should be allowed with default values
* #16 Configuration model support
* #28 IConfiguration Support for Open API Metadata
* #28 IConfiguration Support for OpenAPI Metadata
* Updated docs

Просмотреть файл

@ -1,11 +1,11 @@
## Release Notes ##
Implemented more Open API spec
Implemented more OpenAPI spec
### Changes ###
* Implemented Open API spec
* Implemented OpenAPI spec
* #27 Mark Deprecated to Operations, Parameters and Schemas
* [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#operationObject)
* [Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#parameterObject)

Просмотреть файл

@ -10,8 +10,8 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V1Proxy.Configu
public override 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.",
Title = "OpenAPI Sample on Azure Functions Proxy for v1",
Description = "A sample API that runs on Azure Functions 1.x using OpenAPI specification.",
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
Contact = new OpenApiContact()
{

Просмотреть файл

@ -10,8 +10,8 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V2IoC.Configura
public override 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.",
Title = "OpenAPI Sample on Azure Functions (IoC)",
Description = "A sample API that runs on Azure Functions (IoC) 3.x using OpenAPI specification.",
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
Contact = new OpenApiContact()
{

Просмотреть файл

@ -10,8 +10,8 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V2Static.Config
public override 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.",
Title = "OpenAPI Sample on Azure Functions (STATIC)",
Description = "A sample API that runs on Azure Functions (STATIC) 3.x using OpenAPI specification.",
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
Contact = new OpenApiContact()
{

Просмотреть файл

@ -10,8 +10,8 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V3IoC.Configura
public override 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.",
Title = "OpenAPI Sample on Azure Functions (IoC)",
Description = "A sample API that runs on Azure Functions (IoC) 3.x using OpenAPI specification.",
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
Contact = new OpenApiContact()
{

Просмотреть файл

@ -11,8 +11,8 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V3Static.Config
public override 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.",
Title = "OpenAPI Sample on Azure Functions (STATIC)",
Description = "A sample API that runs on Azure Functions (STATIC) 3.x using OpenAPI specification.",
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
Contact = new OpenApiContact()
{

Просмотреть файл

@ -41,10 +41,10 @@
</ItemGroup>
<!-- Uncomment this block if you want to use custom UI -->
<ItemGroup>
<!-- <ItemGroup>
<EmbeddedResource Include="dist\my-custom.css" />
<EmbeddedResource Include="dist\my-custom.js" />
</ItemGroup>
</ItemGroup> -->
<!-- Uncomment this block if you want to use custom UI -->
<!-- Comment this block if you want to use NuGet package from https://nuget.org -->

Просмотреть файл

@ -1 +1 @@
console.log("Custom UI: Open API Sample on Azure Functions (STATIC)");
console.log("Custom UI: OpenAPI Sample on Azure Functions (STATIC)");

Просмотреть файл

@ -34,21 +34,21 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.CLI
}
/// <summary>
/// Generates the Open API document.
/// Generates the OpenAPI document.
/// </summary>
/// <param name="project">Project path.</param>
/// <param name="configuration">Copile configuration.</param>
/// <param name="version">Open API version.</param>
/// <param name="format">Open API output format.</param>
/// <param name="version">OpenAPI version.</param>
/// <param name="format">OpenAPI output format.</param>
/// <param name="output">Output path.</param>
/// <param name="console">Value indicating whether to render the document on console or not.</param>
public void Generate(
[Option('p', Description = "Project path. Default is current directory")] string project = ".",
[Option('c', Description = "Configuration. Default is 'Debug'")] string configuration = "Debug",
[Option('t', Description = "Target framework. Default is 'netcoreapp2.1'")] string target = "netcoreapp2.1",
[Option('v', Description = "Open API spec version. Value can be either 'v2' or 'v3'. Default is 'v2'")] OpenApiVersionType version = OpenApiVersionType.V2,
[Option('f', Description = "Open API output format. Value can be either 'json' or 'yaml'. Default is 'yaml'")] OpenApiFormatType format = OpenApiFormatType.Json,
[Option('o', Description = "Generated Open API output location. Default is 'output'")] string output = "output",
[Option('v', Description = "OpenAPI spec version. Value can be either 'v2' or 'v3'. Default is 'v2'")] OpenApiVersionType version = OpenApiVersionType.V2,
[Option('f', Description = "OpenAPI output format. Value can be either 'json' or 'yaml'. Default is 'yaml'")] OpenApiFormatType format = OpenApiFormatType.Json,
[Option('o', Description = "Generated OpenAPI output location. Default is 'output'")] string output = "output",
bool console = false)
{
var pi = default(ProjectInfo);

Просмотреть файл

@ -4,6 +4,7 @@ using System.Linq;
using System.Reflection;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Configuration.AppSettings.Extensions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions;
using Microsoft.Extensions.Configuration;

Просмотреть файл

@ -1,7 +1,7 @@
{
"name": "azure-functions-openapi-tools",
"version": "0.8.0",
"description": "This handles Open API documents from Azure Functions without having to run the function app",
"description": "This handles OpenAPI documents from Azure Functions without having to run the function app",
"author": "Aliencube Community",
"license": "MIT",
"preferGlobal": true,

Просмотреть файл

@ -5,7 +5,7 @@ using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes
{
/// <summary>
/// This represents the attribute entity for HTTP triggers to define Open API operation.
/// This represents the attribute entity for HTTP triggers to define OpenAPI operation.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class OpenApiOperationAttribute : Attribute

Просмотреть файл

@ -7,7 +7,7 @@ using Microsoft.OpenApi.Models;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes
{
/// <summary>
/// This represents the attribute entity for HTTP triggers to define Open API parameter.
/// This represents the attribute entity for HTTP triggers to define OpenAPI parameter.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
public class OpenApiParameterAttribute : Attribute

Просмотреть файл

@ -3,7 +3,7 @@ using System;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes
{
/// <summary>
/// This represents the attribute entity for Open API model property description.
/// This represents the attribute entity for OpenAPI model property description.
/// </summary>
[AttributeUsage(AttributeTargets.Property, Inherited = false)]
public class OpenApiPropertyDescriptionAttribute : Attribute

Просмотреть файл

@ -5,7 +5,7 @@ using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes
{
/// <summary>
/// This represents the attribute entity for Open API schema visibility.
/// This represents the attribute entity for OpenAPI schema visibility.
/// </summary>
[AttributeUsage(AttributeTargets.Property, Inherited = false)]
public class OpenApiSchemaVisibilityAttribute : Attribute

Просмотреть файл

@ -7,7 +7,7 @@ using Microsoft.OpenApi.Models;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes
{
/// <summary>
/// This represents the attribute entity for HTTP triggers to define Open API operation.
/// This represents the attribute entity for HTTP triggers to define OpenAPI operation.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
public class OpenApiSecurityAttribute : Attribute
@ -15,8 +15,8 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes
/// <summary>
/// Initializes a new instance of the <see cref="OpenApiSecurityAttribute"/> class.
/// </summary>
/// <param name="schemeName">Open API security scheme name.</param>
/// <param name="schemeType">Open API security scheme type.</param>
/// <param name="schemeName">OpenAPI security scheme name.</param>
/// <param name="schemeType">OpenAPI security scheme type.</param>
public OpenApiSecurityAttribute(string schemeName, SecuritySchemeType schemeType)
{
this.SchemeName = schemeName ?? throw new ArgumentNullException(nameof(schemeName));
@ -24,17 +24,17 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes
}
/// <summary>
/// Gets the Open API security scheme name.
/// Gets the OpenAPI security scheme name.
/// </summary>
public virtual string SchemeName { get; }
/// <summary>
/// Gets the Open API security scheme type.
/// Gets the OpenAPI security scheme type.
/// </summary>
public virtual SecuritySchemeType SchemeType { get; }
/// <summary>
/// Gets or sets the Open API security scheme description.
/// Gets or sets the OpenAPI security scheme description.
/// </summary>
public virtual string Description { get; set; }

Просмотреть файл

@ -1,11 +1,12 @@
using System.Collections.Generic;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
using Microsoft.OpenApi.Models;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations
{
/// <summary>
/// This represents the options entity for Open API metadata configuration.
/// This represents the options entity for OpenAPI metadata configuration.
/// </summary>
public class DefaultOpenApiConfigurationOptions : IOpenApiConfigurationOptions
{
@ -13,7 +14,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations
public virtual OpenApiInfo Info { get; set; } = new OpenApiInfo()
{
Version = "1.0.0",
Title = "Azure Functions Open API Extension",
Title = "Azure Functions OpenAPI Extension",
};
/// <inheritdoc />

Просмотреть файл

@ -8,8 +8,7 @@ using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations
{
/// <summary>
/// Default implementation of <see cref="IOpenApiCustomUIOptions"/>, providing
/// empty replacements for custom javascript and stylesheets
/// This represents the options entity for custom UI configuration.
/// </summary>
public class DefaultOpenApiCustomUIOptions : IOpenApiCustomUIOptions
{

Просмотреть файл

@ -5,7 +5,7 @@ using Microsoft.OpenApi.Models;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations
{
/// <summary>
/// This provides interfaces to classes implementing Open API response object.
/// This provides interfaces to classes implementing OpenAPI response object.
/// </summary>
public interface IOpenApiResponseHeaderType
{

Просмотреть файл

@ -8,7 +8,7 @@ using Microsoft.OpenApi.Models;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations
{
/// <summary>
/// This represents the base settings entity from the configurations for Open API.
/// This represents the base settings entity from the configurations for OpenAPI.
/// </summary>
public abstract class OpenApiAppSettingsBase : AppSettingsBase
{
@ -34,7 +34,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations
public virtual OpenApiInfo OpenApiInfo { get; }
/// <summary>
/// Gets the Function API key for Open API document.
/// Gets the Function API key for OpenAPI document.
/// </summary>
public virtual string SwaggerAuthKey { get; }

Просмотреть файл

@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
using Microsoft.OpenApi.Models;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations
{
/// <summary>
/// This represents the settings entity for Open API metadata.
/// This represents the settings entity for OpenAPI metadata.
/// </summary>
[Obsolete("This class is obsolete from 0.5.0-preview. Use OpenApiConfigurationOptions instead", error: true)]
public sealed class OpenApiSettings : IOpenApiConfigurationOptions
@ -15,7 +16,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations
public OpenApiInfo Info { get; set; } = new OpenApiInfo()
{
Version = "1.0.0",
Title = "Azure Functions Open API Extension",
Title = "Azure Functions OpenAPI Extension",
};
/// <inheritdoc />

Просмотреть файл

@ -17,7 +17,7 @@ using Newtonsoft.Json.Serialization;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core
{
/// <summary>
/// This represents the document entity handling Open API document.
/// This represents the document entity handling OpenAPI document.
/// </summary>
public class Document : IDocument
{

Просмотреть файл

@ -3,7 +3,7 @@ using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums
{
/// <summary>
/// This specifies the Open API format.
/// This specifies the OpenAPI format.
/// </summary>
public enum OpenApiFormatType
{

Просмотреть файл

@ -1,7 +1,7 @@
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums
{
/// <summary>
/// This specifies the Open API security key location.
/// This specifies the OpenAPI security key location.
/// </summary>
public enum OpenApiSecurityLocationType
{

Просмотреть файл

@ -3,7 +3,7 @@ using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums
{
/// <summary>
/// This specifices the Open API security scheme value.
/// This specifices the OpenAPI security scheme value.
/// </summary>
public enum OpenApiSecuritySchemeType
{

Просмотреть файл

@ -3,18 +3,18 @@ using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums
{
/// <summary>
/// This specifies the version of Open API.
/// This specifies the version of OpenAPI.
/// </summary>
public enum OpenApiVersionType
{
/// <summary>
/// Identifies the Open API version 2.
/// Identifies the OpenAPI version 2.
/// </summary>
[Display("v2")]
V2 = 0,
/// <summary>
/// Identifies the Open API version 3.
/// Identifies the OpenAPI version 3.
/// </summary>
[Display("v3")]
V3 = 1

Просмотреть файл

@ -33,10 +33,10 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions
}
/// <summary>
/// Converts the <see cref="TypeCode"/> value into data type specified in Open API spec.
/// Converts the <see cref="TypeCode"/> value into data type specified in OpenAPI spec.
/// </summary>
/// <param name="type"><see cref="Type"/> value.</param>
/// <returns>Data type specified in Open API spec.</returns>
/// <returns>Data type specified in OpenAPI spec.</returns>
public static string ToDataType(this Type type)
{
var @enum = Type.GetTypeCode(type);
@ -96,10 +96,10 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions
}
/// <summary>
/// Converts the <see cref="TypeCode"/> value into data format specified in Open API spec.
/// Converts the <see cref="TypeCode"/> value into data format specified in OpenAPI spec.
/// </summary>
/// <param name="type"><see cref="Type"/> value.</param>
/// <returns>Data format specified in Open API spec.</returns>
/// <returns>Data format specified in OpenAPI spec.</returns>
public static string ToDataFormat(this Type type)
{
var @enum = Type.GetTypeCode(type);
@ -178,7 +178,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions
return "application/yaml";
default:
throw new InvalidOperationException("Invalid Open API format");
throw new InvalidOperationException("Invalid OpenAPI format");
}
}

Просмотреть файл

@ -37,7 +37,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions
return;
default:
throw new InvalidOperationException("Invalid Open API version");
throw new InvalidOperationException("Invalid OpenAPI version");
}
}
}

Просмотреть файл

@ -10,12 +10,12 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions
public static class SwaggerUIExtensions
{
/// <summary>
/// Renders the Open API UI in HTML.
/// Renders the OpenAPI UI in HTML.
/// </summary>
/// <param name="ui"><see cref="ISwaggerUI"/> instance.</param>
/// <param name="endpoint">The endpoint of the Swagger document.</param>
/// <param name="authKey">API key of the HTTP endpoint to render Open API document.</param>
/// <returns>The Open API UI in HTML.</returns>
/// <param name="authKey">API key of the HTTP endpoint to render OpenAPI document.</param>
/// <returns>The OpenAPI UI in HTML.</returns>
public static async Task<string> RenderAsync(this Task<ISwaggerUI> ui, string endpoint, string authKey = null)
{
var instance = await ui.ThrowIfNullOrDefault().ConfigureAwait(false);
@ -29,7 +29,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions
/// </summary>
/// <param name="ui"><see cref="ISwaggerUI"/> instance.</param>
/// <param name="endpoint">The endpoint of the OAuth2 Redirect page.</param>
/// <param name="authKey">API key of the HTTP endpoint to render Open API document.</param>
/// <param name="authKey">API key of the HTTP endpoint to render OpenAPI document.</param>
/// <returns>The OAuth2 Redirect page in HTML.</returns>
public static async Task<string> RenderOAuth2RedirectAsync(this Task<ISwaggerUI> ui, string endpoint, string authKey = null)
{

Просмотреть файл

@ -266,7 +266,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions
}
/// <summary>
/// Checks whether the given type is array or not, from the Open API perspective.
/// Checks whether the given type is array or not, from the OpenAPI perspective.
/// </summary>
/// <param name="type"><see cref="Type"/> instance.</param>
/// <returns>Returns <c>True</c>, if the type is identified as array; otherwise returns <c>False</c>.</returns>
@ -281,7 +281,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions
}
/// <summary>
/// Checks whether the given type is array or not, from the Open API perspective.
/// Checks whether the given type is array or not, from the OpenAPI perspective.
/// </summary>
/// <param name="type"><see cref="Type"/> instance.</param>
/// <returns>Returns <c>True</c>, if the type is identified as array; otherwise returns <c>False</c>.</returns>
@ -341,13 +341,13 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions
}
/// <summary>
/// Gets the Open API reference ID.
/// Gets the OpenAPI reference ID.
/// </summary>
/// <param name="type"><see cref="Type"/> instance.</param>
/// <param name="isDictionary">Value indicating whether the type is <see cref="Dictionary{TKey, TValue}"/> or not.</param>
/// <param name="isList">Value indicating whether the type is <see cref="List{T}"/> or not.</param>
/// <param name="namingStrategy"><see cref="NamingStrategy"/> instance.</param>
/// <returns>Returns the Open API reference ID.</returns>
/// <returns>Returns the OpenAPI reference ID.</returns>
public static string GetOpenApiReferenceId(this Type type, bool isDictionary, bool isList, NamingStrategy namingStrategy = null)
{
if (namingStrategy.IsNullOrDefault())
@ -372,10 +372,10 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions
}
/// <summary>
/// Gets the Open API root reference ID.
/// Gets the OpenAPI root reference ID.
/// </summary>
/// <param name="type"><see cref="Type"/> instance.</param>
/// <returns>Returns the Open API root reference ID.</returns>
/// <returns>Returns the OpenAPI root reference ID.</returns>
public static string GetOpenApiRootReferenceId(this Type type)
{
if (!type.IsGenericType)
@ -435,10 +435,10 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions
}
/// <summary>
/// Gets the Open API description from the given <see cref="Type"/>.
/// Gets the OpenAPI description from the given <see cref="Type"/>.
/// </summary>
/// <param name="type"><see cref="Type"/> instance.</param>
/// <returns>Returns the Open API description from the given <see cref="Type"/>.</returns>
/// <returns>Returns the OpenAPI description from the given <see cref="Type"/>.</returns>
public static string GetOpenApiDescription(this Type type)
{
if (type.IsOpenApiDictionary())

Просмотреть файл

@ -28,7 +28,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions
IDocument InitialiseDocument();
/// <summary>
/// Adds metadata to build Open API document.
/// Adds metadata to build OpenAPI document.
/// </summary>
/// <param name="info"><see cref="OpenApiInfo"/> instance.</param>
/// <returns><see cref="IDocument"/> instance.</returns>
@ -58,25 +58,25 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions
IDocument AddVisitors(VisitorCollection collection);
/// <summary>
/// Builds Open API document.
/// Builds OpenAPI document.
/// </summary>
/// <param name="assemblyPath">Assembly file path.</param>
/// <returns><see cref="IDocument"/> instance.</returns>
IDocument Build(string assemblyPath);
/// <summary>
/// Builds Open API document.
/// Builds OpenAPI document.
/// </summary>
/// <param name="assembly"><see cref="Assembly"/> instance.</param>
/// <returns><see cref="IDocument"/> instance.</returns>
IDocument Build(Assembly assembly);
/// <summary>
/// Renders Open API document.
/// Renders OpenAPI document.
/// </summary>
/// <param name="version"><see cref="OpenApiSpecVersion"/> value.</param>
/// <param name="format"><see cref="OpenApiFormat"/> value.</param>
/// <returns>Serialised Open API document.</returns>
/// <returns>Serialised OpenAPI document.</returns>
Task<string> RenderAsync(OpenApiSpecVersion version, OpenApiFormat format);
}
}

Просмотреть файл

@ -2,10 +2,10 @@ using System.Collections.Generic;
using Microsoft.OpenApi.Models;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions
{
/// <summary>
/// This provides interfaces classes implementing.
/// This provides interfaces classes implementing for OpenAPI metadata..
/// </summary>
public interface IOpenApiConfigurationOptions
{

Просмотреть файл

@ -3,8 +3,7 @@ using System.Threading.Tasks;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions
{
/// <summary>
/// Interface for a custom UI provider that can provide custom javascript
/// and CSS to be populated on a page
/// This provides interfaces classes implementing for the custom UI.
/// </summary>
public interface IOpenApiCustomUIOptions
{

Просмотреть файл

@ -1,7 +1,7 @@
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.OpenApi.Models;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions
@ -12,7 +12,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions
public interface ISwaggerUI
{
/// <summary>
/// Adds metadata to build Open API document.
/// Adds metadata to build OpenAPI document.
/// </summary>
/// <param name="info"><see cref="OpenApiInfo"/> instance.</param>
/// <returns><see cref="ISwaggerUI"/> instance.</returns>
@ -30,29 +30,31 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions
/// <summary>
/// Builds Swagger UI document.
/// </summary>
/// <param name="assembly"><see cref="Assembly"/> instance.</param>
/// <param name="options"><see cref="IOpenApiCustomUIOptions"/> instance.</param>
/// <returns><see cref="ISwaggerUI"/> instance.</returns>
Task<ISwaggerUI> BuildAsync(IOpenApiCustomUIOptions options = null);
Task<ISwaggerUI> BuildAsync(Assembly assembly, IOpenApiCustomUIOptions options = null);
/// <summary>
/// Builds OAuth2 Redirect document.
/// </summary>
/// <param name="assembly"><see cref="Assembly"/> instance.</param>
/// <returns><see cref="ISwaggerUI"/> instance.</returns>
Task<ISwaggerUI> BuildOAuth2RedirectAsync();
Task<ISwaggerUI> BuildOAuth2RedirectAsync(Assembly assembly);
/// <summary>
/// Renders Open API UI in HTML.
/// Renders OpenAPI UI in HTML.
/// </summary>
/// <param name="endpoint">The endpoint of the Swagger document.</param>
/// <param name="authKey">API key of the HTTP endpoint to render Open API document.</param>
/// <returns>Open API UI in HTML.</returns>
/// <param name="authKey">API key of the HTTP endpoint to render OpenAPI document.</param>
/// <returns>OpenAPI UI in HTML.</returns>
Task<string> RenderAsync(string endpoint, string authKey = null);
/// <summary>
/// Renders OAuth Redirect in HTML.
/// </summary>
/// <param name="endpoint">The endpoint of the OAuth2 Redirect page.</param>
/// <param name="authKey">API key of the HTTP endpoint to render Open API document.</param>
/// <param name="authKey">API key of the HTTP endpoint to render OpenAPI document.</param>
/// <returns>OAuth Redirect in HTML.</returns>
Task<string> RenderOAuth2RedirectAsync(string endpoint, string authKey = null);
}

Просмотреть файл

@ -10,8 +10,8 @@
<Version>1.0.0</Version>
<PackageId>Microsoft.Azure.WebJobs.Extensions.OpenApi.Core</PackageId>
<Title>Microsoft.Azure.WebJobs.Extensions.OpenApi.Core</Title>
<Summary>This package helps render Open API document and Swagger UI through Azure Functions endpoints.</Summary>
<Description>This package helps render Open API document and Swagger UI through Azure Functions endpoints.</Description>
<Summary>This package helps render OpenAPI document and Swagger UI through Azure Functions endpoints.</Summary>
<Description>This package helps render OpenAPI document and Swagger UI through Azure Functions endpoints.</Description>
<PackageTags>Azure-Functions, Open-API, Swagger, Swagger-UI</PackageTags>
<AssemblyName>Microsoft.Azure.WebJobs.Extensions.OpenApi.Core</AssemblyName>
<RootNamespace>Microsoft.Azure.WebJobs.Extensions.OpenApi.Core</RootNamespace>

Просмотреть файл

@ -7,12 +7,12 @@ using Microsoft.OpenApi.Writers;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core
{
/// <summary>
/// This represents the factory entity to create a write instance based on the Open API document format.
/// This represents the factory entity to create a write instance based on the OpenAPI document format.
/// </summary>
public static class OpenApiWriterFactory
{
/// <summary>
/// Creates a new instance of <see cref="IOpenApiWriter"/> based on the Open API document format.
/// Creates a new instance of <see cref="IOpenApiWriter"/> based on the OpenAPI document format.
/// </summary>
/// <param name="format"><see cref="OpenApiFormat"/> value.</param>
/// <param name="writer"><see cref="TextWriter"/> instance.</param>
@ -28,7 +28,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core
return new OpenApiYamlWriter(writer);
default:
throw new InvalidOperationException("Invalid Open API format");
throw new InvalidOperationException("Invalid OpenAPI format");
}
}
}

Просмотреть файл

@ -2,6 +2,7 @@ using System;
using System.Linq;
using System.Reflection;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions;
using Microsoft.OpenApi.Models;

Просмотреть файл

@ -5,14 +5,13 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions;
using Microsoft.OpenApi.Models;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core
{
/// <summary>
/// This represents the entity to render UI for Open API.
/// This represents the entity to render UI for OpenAPI.
/// </summary>
public class SwaggerUI : ISwaggerUI
{
@ -77,10 +76,8 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core
}
/// <inheritdoc />
public async Task<ISwaggerUI> BuildAsync(IOpenApiCustomUIOptions options = null)
public async Task<ISwaggerUI> BuildAsync(Assembly assembly, IOpenApiCustomUIOptions options = null)
{
var assembly = Assembly.GetExecutingAssembly();
if (!options.IsNullOrDefault())
{
this._swaggerUiCustomCss = await options.GetStylesheetAsync();
@ -116,10 +113,8 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core
}
/// <inheritdoc />
public async Task<ISwaggerUI> BuildOAuth2RedirectAsync()
public async Task<ISwaggerUI> BuildOAuth2RedirectAsync(Assembly assembly)
{
var assembly = Assembly.GetExecutingAssembly();
using (var stream = assembly.GetManifestResourceStream(oauth2RedirectHtml))
using (var reader = new StreamReader(stream))
{

Просмотреть файл

@ -10,8 +10,8 @@
<Version>1.0.0</Version>
<PackageId>Microsoft.Azure.WebJobs.Extensions.OpenApi</PackageId>
<Title>Microsoft.Azure.WebJobs.Extensions.OpenApi</Title>
<Summary>This package helps render Open API document and Swagger UI through Azure Functions endpoints.</Summary>
<Description>This package helps render Open API document and Swagger UI through Azure Functions endpoints.</Description>
<Summary>This package helps render OpenAPI document and Swagger UI through Azure Functions endpoints.</Summary>
<Description>This package helps render OpenAPI document and Swagger UI through Azure Functions endpoints.</Description>
<PackageTags>Azure-Functions, Open-API, Swagger, Swagger-UI</PackageTags>
<AssemblyName>Microsoft.Azure.WebJobs.Extensions.OpenApi</AssemblyName>
<RootNamespace>Microsoft.Azure.WebJobs.Extensions.OpenApi</RootNamespace>

Просмотреть файл

@ -1,13 +1,11 @@
using System.Collections.Generic;
using System;
using System.Reflection;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors;
using Microsoft.OpenApi;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json.Serialization;
@ -18,10 +16,20 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
/// </summary>
public interface IOpenApiHttpTriggerContext
{
/// <summary>
/// Gets the <see cref="Assembly"/> instance representing the Azure Functions app.
/// </summary>
Assembly ApplicationAssembly { get; }
/// <summary>
/// Gets the <see cref="Assembly"/> instance representing the Azure Functions OpenAPI Extension package.
/// </summary>
Assembly PackageAssembly { get; }
/// <summary>
/// Gets the <see cref="IOpenApiConfigurationOptions"/> instance.
/// </summary>
IOpenApiConfigurationOptions OpenApiConfiguration { get; }
IOpenApiConfigurationOptions OpenApiConfigurationOptions { get; }
/// <summary>
/// Gets the <see cref="IOpenApiCustomUIOptions"/> instance.
@ -52,6 +60,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
/// Gets the executing assembly.
/// </summary>
/// <returns>Returns the executing assembly.</returns>
[Obsolete("This method is obsolete.", error: true)]
Assembly GetExecutingAssembly();
/// <summary>
@ -63,7 +72,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
/// <summary>
/// Gets the <see cref="OpenApiSpecVersion"/> value.
/// </summary>
/// <param name="version">Open API spec version. It can be either <c>v2</c> or <c>v3</c>.</param>
/// <param name="version">OpenAPI spec version. It can be either <c>v2</c> or <c>v3</c>.</param>
/// <returns>Returns the <see cref="OpenApiSpecVersion"/> value.</returns>
OpenApiSpecVersion GetOpenApiSpecVersion(string version = "v2");
@ -77,7 +86,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
/// <summary>
/// Gets the <see cref="OpenApiFormat"/> value.
/// </summary>
/// <param name="format">Open API document format. It can be either <c>json</c> or <c>yaml</c>.</param>
/// <param name="format">OpenAPI document format. It can be either <c>json</c> or <c>yaml</c>.</param>
/// <returns>Returns the <see cref="OpenApiFormat"/> value.</returns>
OpenApiFormat GetOpenApiFormat(string format = "json");

Просмотреть файл

@ -13,7 +13,7 @@ using Microsoft.Extensions.Logging;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
{
/// <summary>
/// This represents the HTTP trigger entity for Open API documents.
/// This represents the HTTP trigger entity for OpenAPI documents.
/// </summary>
[SuppressMessage("Design", "CA1823", Justification = "")]
[SuppressMessage("Design", "MEN002", Justification = "")]
@ -31,12 +31,12 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
private readonly static IOpenApiHttpTriggerContext context = new OpenApiHttpTriggerContext();
/// <summary>
/// Invokes the HTTP trigger endpoint to get Open API document.
/// Invokes the HTTP trigger endpoint to get OpenAPI document.
/// </summary>
/// <param name="req"><see cref="HttpRequest"/> instance.</param>
/// <param name="extension">File extension representing the document format. This MUST be either "json" or "yaml".</param>
/// <param name="log"><see cref="ILogger"/> instance.</param>
/// <returns>Open API document in a format of either JSON or YAML.</returns>
/// <returns>OpenAPI document in a format of either JSON or YAML.</returns>
[FunctionName(nameof(OpenApiHttpTrigger.RenderSwaggerDocument))]
[OpenApiIgnore]
public static async Task<IActionResult> RenderSwaggerDocument(
@ -48,11 +48,11 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
var result = await context.Document
.InitialiseDocument()
.AddMetadata(context.OpenApiConfiguration.Info)
.AddServer(req, context.HttpSettings.RoutePrefix, context.OpenApiConfiguration)
.AddMetadata(context.OpenApiConfigurationOptions.Info)
.AddServer(req, context.HttpSettings.RoutePrefix, context.OpenApiConfigurationOptions)
.AddNamingStrategy(context.NamingStrategy)
.AddVisitors(context.GetVisitorCollection())
.Build(context.GetExecutingAssembly())
.Build(context.ApplicationAssembly)
.RenderAsync(context.GetOpenApiSpecVersion(V2), context.GetOpenApiFormat(extension))
.ConfigureAwait(false);
@ -67,13 +67,13 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
}
/// <summary>
/// Invokes the HTTP trigger endpoint to get Open API document.
/// Invokes the HTTP trigger endpoint to get OpenAPI document.
/// </summary>
/// <param name="req"><see cref="HttpRequest"/> instance.</param>
/// <param name="version">Open API document spec version. This MUST be either "v2" or "v3".</param>
/// <param name="version">OpenAPI document spec version. This MUST be either "v2" or "v3".</param>
/// <param name="extension">File extension representing the document format. This MUST be either "json" or "yaml".</param>
/// <param name="log"><see cref="ILogger"/> instance.</param>
/// <returns>Open API document in a format of either JSON or YAML.</returns>
/// <returns>OpenAPI document in a format of either JSON or YAML.</returns>
[FunctionName(nameof(OpenApiHttpTrigger.RenderOpenApiDocument))]
[OpenApiIgnore]
public static async Task<IActionResult> RenderOpenApiDocument(
@ -86,11 +86,11 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
var result = await context.Document
.InitialiseDocument()
.AddMetadata(context.OpenApiConfiguration.Info)
.AddServer(req, context.HttpSettings.RoutePrefix, context.OpenApiConfiguration)
.AddMetadata(context.OpenApiConfigurationOptions.Info)
.AddServer(req, context.HttpSettings.RoutePrefix, context.OpenApiConfigurationOptions)
.AddNamingStrategy(context.NamingStrategy)
.AddVisitors(context.GetVisitorCollection())
.Build(context.GetExecutingAssembly())
.Build(context.ApplicationAssembly)
.RenderAsync(context.GetOpenApiSpecVersion(version), context.GetOpenApiFormat(extension))
.ConfigureAwait(false);
@ -119,9 +119,9 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
log.LogInformation("SwaggerUI page was requested.");
var result = await context.SwaggerUI
.AddMetadata(context.OpenApiConfiguration.Info)
.AddServer(req, context.HttpSettings.RoutePrefix, context.OpenApiConfiguration)
.BuildAsync(context.OpenApiCustomUIOptions)
.AddMetadata(context.OpenApiConfigurationOptions.Info)
.AddServer(req, context.HttpSettings.RoutePrefix, context.OpenApiConfigurationOptions)
.BuildAsync(context.PackageAssembly, context.OpenApiCustomUIOptions)
.RenderAsync("swagger.json", context.GetSwaggerAuthKey())
.ConfigureAwait(false);
@ -150,8 +150,8 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
log.LogInformation("The oauth2-redirect.html page was requested.");
var result = await context.SwaggerUI
.AddServer(req, context.HttpSettings.RoutePrefix, context.OpenApiConfiguration)
.BuildOAuth2RedirectAsync()
.AddServer(req, context.HttpSettings.RoutePrefix, context.OpenApiConfigurationOptions)
.BuildOAuth2RedirectAsync(context.PackageAssembly)
.RenderOAuth2RedirectAsync("oauth2-redirect.html", context.GetSwaggerAuthKey())
.ConfigureAwait(false);

Просмотреть файл

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
@ -10,9 +9,7 @@ using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Resolvers;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors;
using Microsoft.OpenApi;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json.Serialization;
@ -34,10 +31,13 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
/// </summary>
public OpenApiHttpTriggerContext()
{
var host = HostJsonResolver.Resolve();
this.ApplicationAssembly = this.GetAssembly(this);
this.PackageAssembly = this.GetAssembly<ISwaggerUI>();
this.OpenApiConfiguration = OpenApiConfigurationResolver.Resolve(this.GetExecutingAssembly());
this.OpenApiCustomUIOptions = OpenApiCustomUIResolver.Resolve(this.GetExecutingAssembly());
this.OpenApiConfigurationOptions = OpenApiConfigurationResolver.Resolve(this.ApplicationAssembly);
this.OpenApiCustomUIOptions = OpenApiCustomUIResolver.Resolve(this.ApplicationAssembly);
var host = HostJsonResolver.Resolve();
this.HttpSettings = host.GetHttpSettings();
var filter = new RouteConstraintFilter();
@ -49,7 +49,13 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
}
/// <inheritdoc />
public virtual IOpenApiConfigurationOptions OpenApiConfiguration { get; }
public virtual Assembly ApplicationAssembly { get; }
/// <inheritdoc />
public virtual Assembly PackageAssembly { get; }
/// <inheritdoc />
public virtual IOpenApiConfigurationOptions OpenApiConfigurationOptions { get; }
/// <inheritdoc />
public virtual IOpenApiCustomUIOptions OpenApiCustomUIOptions { get; }
@ -67,9 +73,12 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
public virtual NamingStrategy NamingStrategy { get; } = new CamelCaseNamingStrategy();
/// <inheritdoc />
[Obsolete("This method is obsolete. Use GetAssembly<T>() or GetAssembly(object) instead", error: true)]
public virtual Assembly GetExecutingAssembly()
{
return Assembly.GetExecutingAssembly();
var assembly = Assembly.GetExecutingAssembly();
return assembly;
}
/// <inheritdoc />
@ -85,7 +94,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
{
var parsed = Enum.TryParse(version, true, out OpenApiVersionType output)
? output
: throw new InvalidOperationException("Invalid Open API version");
: throw new InvalidOperationException("Invalid OpenAPI version");
return this.GetOpenApiSpecVersion(parsed);
}
@ -106,7 +115,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
var parsed = Enum.TryParse(format, true, out OpenApiFormatType output)
? output
: throw new InvalidOperationException("Invalid Open API format");
: throw new InvalidOperationException("Invalid OpenAPI format");
return this.GetOpenApiFormat(parsed);
}
@ -124,5 +133,25 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi
return value ?? string.Empty;
}
/// <inheritdoc />
private Assembly GetAssembly(object instance)
{
return this.GetAssembly(instance.GetType());
}
/// <inheritdoc />
private Assembly GetAssembly<T>()
{
return this.GetAssembly(typeof(T));
}
/// <inheritdoc />
private Assembly GetAssembly(Type type)
{
var assembly = type.Assembly;
return assembly;
}
}
}

Просмотреть файл

@ -10,13 +10,13 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Configurations
public class DefaultOpenApiConfigurationOptionsTests
{
[TestMethod]
public void Given_Value_Property_Should_Return_Value()
public void Given_Type_When_Instantiated_Then_Properties_Should_Return_Value()
{
var settings = new DefaultOpenApiConfigurationOptions();
settings.Info.Should().NotBeNull();
settings.Info.Version.Should().Be("1.0.0");
settings.Info.Title.Should().Be("Azure Functions Open API Extension");
settings.Info.Title.Should().Be("Azure Functions OpenAPI Extension");
settings.Servers.Should().NotBeNull();
settings.Servers.Should().HaveCount(0);

Просмотреть файл

@ -0,0 +1,46 @@
using System.Reflection;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Configurations
{
[TestClass]
public class DefaultOpenApiCustomUIOptionsTests
{
[TestMethod]
public void Given_Type_When_Instantiated_Then_Properties_Should_Return_Result()
{
var assembly = Assembly.GetExecutingAssembly();
var options = new DefaultOpenApiCustomUIOptions(assembly);
options.CustomStylesheetPath.Should().Be("dist.custom.css");
options.CustomJavaScriptPath.Should().Be("dist.custom.js");
}
[TestMethod]
public async Task Given_Type_When_GetStylesheetAsync_Invoked_Then_It_Should_Return_Result()
{
var assembly = Assembly.GetExecutingAssembly();
var options = new DefaultOpenApiCustomUIOptions(assembly);
var result = await options.GetStylesheetAsync().ConfigureAwait(false);
result.Should().BeEmpty();
}
[TestMethod]
public async Task Given_Type_When_GetJavaScriptAsync_Invoked_Then_It_Should_Return_Result()
{
var assembly = Assembly.GetExecutingAssembly();
var options = new DefaultOpenApiCustomUIOptions(assembly);
var result = await options.GetJavaScriptAsync().ConfigureAwait(false);
result.Should().BeEmpty();
}
}
}

Просмотреть файл

@ -2,7 +2,7 @@ using System.Reflection;
using FluentAssertions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Resolvers;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Просмотреть файл

@ -1,18 +1,10 @@
{
"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 - from **host.json**.",
"termsOfService": "https://github.com/aliencube/AzureFunctions.Extensions",
"contact": {
"name": "Aliencube Community",
"email": "no-reply@aliencube.org",
"url": "https://github.com/aliencube/AzureFunctions.Extensions/issues"
},
"license": {
"name": "MIT",
"url": "http://opensource.org/licenses/MIT"
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
}

Просмотреть файл

@ -1,3 +0,0 @@
{
}

Просмотреть файл

@ -34,9 +34,6 @@
<None Update="local.settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="openapisettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -1,5 +1,8 @@
using System.Reflection;
using FluentAssertions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
using Microsoft.OpenApi;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@ -8,6 +11,63 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Tests
[TestClass]
public class OpenApiHttpTriggerContextTests
{
[TestMethod]
public void Given_Type_When_Initiated_Then_It_Should_Return_ApplicationAssembly()
{
var context = new OpenApiHttpTriggerContext();
var assembly = context.ApplicationAssembly;
assembly.DefinedTypes.Should().Contain(typeof(IOpenApiHttpTriggerContext).GetTypeInfo());
assembly.DefinedTypes.Should().Contain(typeof(OpenApiHttpTriggerContext).GetTypeInfo());
assembly.DefinedTypes.Should().Contain(typeof(OpenApiHttpTrigger).GetTypeInfo());
assembly.DefinedTypes.Should().NotContain(typeof(ISwaggerUI).GetTypeInfo());
}
[TestMethod]
public void Given_Type_When_Initiated_Then_It_Should_Return_PackageAssembly()
{
var context = new OpenApiHttpTriggerContext();
var assembly = context.PackageAssembly;
assembly.DefinedTypes.Should().Contain(typeof(ISwaggerUI).GetTypeInfo());
assembly.DefinedTypes.Should().NotContain(typeof(IOpenApiHttpTriggerContext).GetTypeInfo());
}
[TestMethod]
public void Given_Type_When_Initiated_Then_It_Should_Return_OpenApiConfigurationOptions()
{
var context = new OpenApiHttpTriggerContext();
var options = context.OpenApiConfigurationOptions;
options.Info.Version.Should().Be("1.0.0");
options.Servers.Count.Should().Be(0);
}
[TestMethod]
public void Given_Type_When_Initiated_Then_It_Should_Return_OpenApiCustomUIOptions()
{
var context = new OpenApiHttpTriggerContext();
var options = context.OpenApiCustomUIOptions;
options.CustomStylesheetPath.Should().Be("dist.custom.css");
options.CustomJavaScriptPath.Should().Be("dist.custom.js");
}
[TestMethod]
public void Given_Type_When_Initiated_Then_It_Should_Return_HttpSettings()
{
var context = new OpenApiHttpTriggerContext();
var settings = context.HttpSettings;
settings.RoutePrefix.Should().Be("api");
}
[DataTestMethod]
[DataRow("v2", OpenApiSpecVersion.OpenApi2_0)]
[DataRow("v3", OpenApiSpecVersion.OpenApi3_0)]

Просмотреть файл

@ -1,18 +1,10 @@
{
"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 - from **host.json**.",
"termsOfService": "https://github.com/aliencube/AzureFunctions.Extensions",
"contact": {
"name": "Aliencube Community",
"email": "no-reply@aliencube.org",
"url": "https://github.com/aliencube/AzureFunctions.Extensions/issues"
},
"license": {
"name": "MIT",
"url": "http://opensource.org/licenses/MIT"
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
}

Просмотреть файл

@ -1,3 +0,0 @@
{
}