Skip to content

Commit b613797

Browse files
committed
local validation
1 parent 614f715 commit b613797

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

articles/api-center/enable-managed-api-analysis-linting.md

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Managed API linting and analysis - Azure API Center
33
description: Enable managed linting of API definitions in your API center to analyze compliance of APIs with the organization's API style guide.
44
ms.service: azure-api-center
55
ms.topic: how-to
6-
ms.date: 08/21/2024
6+
ms.date: 08/22/2024
77
ms.author: danlep
88
author: dlepow
99
ms.custom:
@@ -12,22 +12,23 @@ ms.custom:
1212

1313
# Enable API analysis in your API center - Microsoft managed
1414

15-
This article explains how to enable API analysis in [Azure API Center](overview.md) without having to manage it yourself (preview). API analysis offers linting capabilities to analyze API definitions within your organization's API center. Linting ensures your API definitions adhere to organizational style rules, generating both individual and summary reports. Use API analysis to identify and correct common errors and inconsistencies in your API definitions.
15+
This article explains how to enable API analysis in [Azure API Center](overview.md) without having to manage it yourself (preview). API analysis offers linting capabilities to analyze API definitions in your organization's API center. Linting ensures your API definitions adhere to organizational style rules, generating both individual and summary reports. Use API analysis to identify and correct common errors and inconsistencies in your API definitions.
1616

1717
> [!NOTE]
1818
> With managed linting and analysis, API Center sets up a linting engine and any required dependencies and triggers. You can also enable linting and analysis [manually](enable-api-analysis-linting.md).
1919
2020
In this scenario:
2121

2222
1. Add a linting ruleset (API style guide) in your API center using the Visual Studio Code extension for Azure API Center.
23-
1. Linting automatically runs when you add or update an API definition. It's also triggered for all API definitions when you deploy a ruleset to your API center.
23+
1. Azure API Center automatically runs linting when you add or update an API definition. It's also triggered for all API definitions when you deploy a ruleset to your API center.
2424
1. Review API analysis reports in the Azure portal to see how your API definitions conform to the style guide.
25+
1. Optionally customize the ruleset for your organization's APIs. Test the custom ruleset locally before deploying it to your API center.
2526

2627
## Limitations
2728

2829
* Currently, only OpenAPI specification documents in JSON or YAML format are analyzed.
29-
* By default, you enable analysis with the [`spectral:oas` ruleset](https://docs.stoplight.io/docs/spectral/4dec24461f3af-open-api-rules). To extend the ruleset or create custom API style guides, see the [Spectral GitHub repo](https://github.com/stoplightio/spectral/blob/develop/docs/reference/openapi-rules.md).
30-
* Currently, you configure a single ruleset, and it's applied to all APIs in your API center.
30+
* By default, you enable analysis with the [`spectral:oas` ruleset](https://docs.stoplight.io/docs/spectral/4dec24461f3af-open-api-rules). To learn more about the built-in rules, see the [Spectral GitHub repo](https://github.com/stoplightio/spectral/blob/develop/docs/reference/openapi-rules.md).
31+
* Currently, you configure a single ruleset, and it's applied to all OpenAPI definitions in your API center.
3132

3233
## Prerequisites
3334

@@ -39,21 +40,22 @@ In this scenario:
3940
* [Spectral extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=stoplight.spectral)
4041

4142
> [!NOTE]
42-
> Enable managed API analysis using the API Center extension's pre-release version. Install the extension from the [Visual Studio Code Marketplace](https://marketplace.visualstudio.com/items?itemName=apidev.azure-api-center&ssr=false#overview) and choose the pre-release version. Switch between release and pre-release versions any time via the extension's **Manage** button in the Extensions view.
43+
> Enable managed API analysis using the API Center extension's pre-release version. When installing the extension, choose the pre-release version. Switch between release and pre-release versions any time via the extension's **Manage** button in the Extensions view.
4344
4445
## Enable API analysis using Visual Studio Code
4546

4647
To enable API analysis using the default linting ruleset:
4748

48-
1. In Visual Studio Code, select the Azure API Center icon from the Activity Bar.
49-
1. In the Explorer pane, expand the API center resource in which to enable managed linting and analysis.
49+
1. In Visual Studio Code, open a folder that you will use to manage rulesets for Azure API Center.
50+
1. Select the Azure API Center icon from the Activity Bar.
51+
1. In the Explorer pane, expand the API center resource in which to enable API analysis.
5052
1. Right-click **Rules** and select **Enable API Analysis**.
5153

52-
:::image type="content" source="media/enable-managed-api-analysis-linting/enable-analysis-visual-studio-code.png" alt-text="Screenshot of enabling API linting and analysis in Visual Studio Code.":::
54+
:::image type="content" source="media/enable-managed-api-analysis-linting/enable-analysis-visual-studio-code.png" alt-text="Screenshot of enabling API linting and analysis in Visual Studio Code.":::
5355

54-
A message notifies you after API analysis is successfully enabled. The following are installed locally in the `.api-center-rules` folder:
56+
A message notifies you after API analysis is successfully enabled. The following are installed locally in the `.api-center-rules` folder at the root of your working folder:
5557

56-
* A `ruleset.yml` file that defines the default API style guide used by the linting engine
58+
* A `ruleset.yml` file that defines the default API style guide used by the linting engine.
5759
* A `functions` folder with an example custom function that you can use to extend the ruleset.
5860

5961
With analysis enabled, the linting engine analyzes API definitions in your API center based on the default ruleset and generates API analysis reports.
@@ -89,14 +91,37 @@ To view a summary of analysis reports for all API definitions in your API center
8991

9092
Optionally select the API Analysis Report icon to view the detailed analysis report for an API definition.
9193

92-
## Modify or replace ruleset
94+
## Customize ruleset
95+
96+
You can customize the default ruleset or replace it as your organization's API style guide. For example, you can [extend the ruleset](https://docs.stoplight.io/docs/spectral/83527ef2dd8c0-extending-rulesets) or add [custom functions](https://docs.stoplight.io/docs/spectral/a781e290eb9f9-custom-functions).
97+
98+
To customize or replace the ruleset:
99+
100+
1. In Visual Studio Code, open the `.api-center-rules` folder at the root of your working folder.
101+
1. In the folder for the API center resource, open the `ruleset.yml` file.
102+
1. Modify or replace the content as needed.
103+
1. Save your changes to `ruleset.yml`.
104+
105+
### Test ruleset locally
106+
107+
Before deploying the custom ruleset to your API center, validate it locally. The Azure API Center extension for Visual Studio Code provides integrated support for API specification linting with Spectral.
108+
109+
1. In Visual Studio Code, use the **Ctrl+Shift+P** keyboard shortcut to open the Command Palette.
110+
1. Type **Azure API Center: Set active API Style Guide** and hit **Enter**.
111+
1. Choose **Select Local File** and specify the `ruleset.yml` file that you customized. Hit **Enter**.
112+
113+
With the custom ruleset set as the active API style guide, opening an OpenAPI-based API definition file automatically triggers a local linting operation in Visual Studio Code. Results are displayed inline in the editor and in the **Problems** window (**View > Problems** or **Ctrl+Shift+M**).
114+
115+
:::image type="content" source="media/enable-managed-api-analysis-linting/validate-local-linting.png" alt-text="Screenshot of linting an API definition in Visual Studio Code." lightbox="media/enable-managed-api-analysis-linting/validate-local-linting.png":::
116+
117+
Review the linting results. Make any necessary adjustments to the ruleset and continue to test it locally until it performs the way you want.
118+
119+
### Deploy ruleset to your API center
93120

94-
You can modify or replace the default ruleset to create a custom API style guide for your organization. To modify or replace the ruleset:
121+
To deploy the custom ruleset to your API center:
95122

96123
1. In Visual Studio Code, select the Azure API Center icon from the Activity Bar.
97-
1. In the Explorer pane, expand the API center resource in which you want to apply the ruleset.
98-
1. Select **Rules** and select the `ruleset.yml` file.
99-
1. Modify or replace the content as needed. Save your changes to `ruleset.yml`.
124+
1. In the Explorer pane, expand the API center resource in which you customized the ruleset.
100125
1. Right-click **Rules** and select **Deploy Rules to API Center**.
101126

102127
A message notifies you after the rules are successfully deployed to your API center. The linting engine uses the updated ruleset to analyze API definitions.
1.09 MB
Loading

0 commit comments

Comments
 (0)