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.
-
Install dependencies.
cd nodejs/webapi && npm install
-
Install dependencies.
cd nodejs/webapi && npm install
-
Run the sample app.
npm start
Navigate to http://localhost:3030/api-docs/swagger to view the Swagger UI page.
-
Navigate to http://localhost:3030/api-docs/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
nodejs/webapi/app.js
,-
Find the following code block:
// route to serve basic/ improved JSON app.get("/api-docs/swagger.json", (req, res) => { // res.send(swaggerSpecs.improved); res.send(swaggerSpecs.basic); });
-
Uncomment the line
res.send(swaggerSpecs.improved);
-
Comment out the line
res.send(swaggerSpecs.basic);
// route to serve basic/ improved JSON app.get("/api-docs/swagger.json", (req, res) => { res.send(swaggerSpecs.improved); // res.send(swaggerSpecs.basic); });
-
-
Then find the following code block:
// setupSwaggerUi(app, swaggerSpecs.improved, "/api-docs/swagger"); setupSwaggerUi(app, swaggerSpecs.basic, '/api-docs/swagger');
-
Uncomment the line
// setupSwaggerUi(app, swaggerSpecs.improved, "/api-docs/swagger");
-
Comment out the line
setupSwaggerUi(app, swaggerSpecs.basic, '/api-docs/swagger');
setupSwaggerUi(app, swaggerSpecs.improved, "/api-docs/swagger"); // setupSwaggerUi(app, swaggerSpecs.basic, '/api-docs/swagger');
-
-
Run the sample app again. Ensure you are still in
nodejs/webapi
npm start
You'll see the following Swagger UI page.
-
Navigate to http://localhost:3030/api-docs/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 in the API Center.
-
Check the warnings 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 in the API Center.
-
Check the warnings in the API Center.