Spectral Style Guides

Create or import Spectral rulesets in Swagger Studio and execute them in your API definitions for easy linting and validation. This functionality ensures centralized and efficient control over API governance. The protocols that support Spectral rulesets are Swagger Studio are: OpenAPI 2.x, 3.x, and AsyncAPI.

SwaggerHub CLI enables you to upload and download Spectral style guides.

Import Spectral style guides

Supported formats

You can import Spectral rulesets to your Swagger Studio organization in the following formats:

  • YAML

  • JavaScript

  • JSON

  • Pre-bundled as a .zip archive

    Important

    The .zip archive must contain a valid Spectral ruleset at the root and can reference other files and functions in the archive. Custom functions must be stored in a separate folder in the archive.

Import a ruleset

To import a Spectral ruleset, follow these steps:

  1. Click Governance on the sidebar.

  2. Select Import Style Guide under the Spectral Style Guides section.

  3. In the Import Style Guide dialog, provide the name of the new ruleset. Depending on your preferred import method, enter a path or URL of the style guide file or click Browse to select the file from your local device.

  4. Click Import to upload the file.

The list of imported style guides appears under Spectral Style Guides.

Create and edit custom style guides

The Spectral Ruleset Editor allows you to create and edit Spectral rulesets directly from the Governance page. It supports the creation of single- and multi-file ruleset projects, and adding or updating custom functions.

Overview of Spectral Ruleset Editor

Using the Spectral Ruleset Editor, you can modify your rulesets and organize their structure. A ruleset project's folder and file layout is visible in the editor's left panel.

Studio_screenshot_spectral_editor_01.png
  • Click the + plus icon to add a new file to the last opened folder.

  • Click the Studio_icon_spectral_editor_folder_01.png folder icon to add a new folder.

  • Click the Studio_icon_spectral_editor_pencil_01.png pencil icon to rename your ruleset.

  • Search for files or folders within your project by entering their name in the search bar.

Add a new ruleset

To create a new Spectral ruleset, follow these steps:

  1. Click Governance on the sidebar.

  2. Select Create New in the Spectral Style Guides section.

  3. Enter the name of the new ruleset and click Save.

    A new ruleset project is created and opens in the Spectral Ruleset Editor. The project is pre-populated with spectral.yaml.

  4. (Optional.) After adding any further changes to the project in the Spectral Ruleset Editor, click Save to submit your work.

Edit a ruleset

To edit an existing ruleset, follow these steps:

  1. Click Governance on the sidebar.

  2. Expand the Spectral Style Guides section to display the list of your Spectral rulesets.

  3. Select Edit next to the ruleset project you want to update.

    The project opens in the Spectral Ruleset Editor.

  4. Add your updates to the ruleset.

  5. Click Save to submit the edits.

Manage style guides

You can manage your existing rulesets in the Spectral Style Guides section of the Governance page.

Studio_screenshot_spectral_editor_02.png
  • Click the Studio_icon_spectral_editor_copy_01.png copy icon to duplicate a ruleset.

  • Click the Studio_icon_spectral_editor_export_01.png download icon to export a ruleset.

  • Click the Studio_icon_spectral_editor_pencil_01.png pencil icon to edit your ruleset in the Spectral Editor.

  • Click the Studio_icon_spectral_editor_trash_01.png delete icon to remove a ruleset.

Learn more about Spectral

You can find the open-source Spectral library here.

For detailed information about Spectral features and rulesets, refer to the Spectral documentation and best practices when creating API style guides.

See also

Publication date: