You can analyze your API documents using Visual Studio Code (Standalone) or Azure Portal (Server-Side). This section will guide you through the integration process.
To use this standalone analyzer, you need to install the API Center extension in Visual Studio Code.
-
Run the sample app.
# .NET dotnet watch run --project ./dotnet/src/ApiApp
You'll see the following Swagger UI page.
-
Click
https://localhost:5051/swagger/v1/swagger.json
to see the OpenAPI document. -
Save the OpenAPI document to
weatherforecast.json
. -
Stop the sample app by pressing Ctrl+C.
-
Open
weatherforecast.json
in Visual Studio Code. You'll see many yellow lines and red lines -
Type F1 then select "Azure API Center: Set active API Style Guide".
You will have several options to choose the styles. Choose either
Microsoft Azure REST API
orOWASP API Security Top 10
and see the analysis results. -
You can also choose the custom API style guide that reflects your organization's policies. This time choose
Select Local File
then select theresources/rulesets/oas.yaml
file. You'll still see many yellow lines and red lines. Hover your mouse and see what needs to be fixed. -
Open
dotnet/src/ApiApp/Program.cs
and find the line:// Add services to the container. builder.Services.AddOpenApiService(); //builder.Services.AddImprovedOpenApiService();
-
Comment out this line:
builder.Services.AddOpenApiService();
, and uncomment this line://builder.Services.AddImprovedOpenApiService();
. -
Find the line:
// Add endpoint to the application. app.UseWeatherForecastEndpoint(summaries); //app.UseImprovedWeatherForecastEndpoint(summaries);
-
Comment out this line:
app.UseWeatherForecastEndpoint(summaries);
, and uncomment this line://app.UseImprovedWeatherForecastEndpoint(summaries);
. -
Run the sample app again.
# .NET dotnet watch run --project ./dotnet/src/ApiApp
You'll see the following Swagger UI page.
-
Click
https://localhost:5051/swagger/v1.0.0/swagger.json
to see the OpenAPI document. -
Save the OpenAPI document to
weatherforecast-reviewed.json
. -
Stop the sample app by pressing Ctrl+C.
-
Open
weatherforecast-reviewed.json
in Visual Studio Code. You'll see all yellow lines and red lines disappeared.
To use this server-side analysis feature, you need to install the APICenter Analyzer first.
APICenter Analyzer is a tool to analyze API specifications on the server-side. If you want to integrate this server-side analysis feature, you can install it by following steps.
-
In a separate directory, say
~/apic-analyzer
, clone the APICenter Analyzer repository.azd init --template Azure/APICenter-Analyzer --branch preview
You will be asked to provide the environment name. Give it a different name from the one holding the existing API Center.
-
Copy over the ruleset to the APICenter Analyzer repository.
# Bash cp resources/rulesets/oas.yaml ~/apic-analyzer/resources/rulesets/ # PowerShell Copy-Item -Path resources/rulesets/oas.yaml -Destination ~/apic-analyzer/resources/rulesets/
-
Provision resources to Azure and deploy the app.
azd up
You will have to provide the existing API Center instance name and its resource group name for integration.
-
Register
weatherforecast.json
to API Center through Azure Portal or through this document, API Registration. -
Check the warnings and errors in the API Center.
-
Update existing API definition with
weatherforecast-reviewed.json
to API Center through Azure Portal or through this document, API Registration. -
Check the warnings and errors in the API Center.