What is @stoplight/spectral-cli?
@stoplight/spectral-cli is a command-line tool for validating, linting, and transforming JSON/YAML documents, particularly useful for API specifications like OpenAPI and AsyncAPI. It helps enforce consistency and best practices in API design.
What are @stoplight/spectral-cli's main functionalities?
Linting
Linting is the process of running a program that will analyze code for potential errors. The `lint` command in Spectral checks the provided OpenAPI document (`openapi.yaml`) against predefined or custom rules to ensure it adheres to best practices and standards.
spectral lint openapi.yaml
Custom Rules
Spectral allows users to define their own rulesets in a YAML file. The `-r` option specifies the custom ruleset file (`custom-ruleset.yaml`) to be used for linting the OpenAPI document (`openapi.yaml`).
spectral lint -r custom-ruleset.yaml openapi.yaml
Transforming Documents
Spectral can transform documents based on rules. The `transform` command processes the input document (`openapi.yaml`) and outputs the transformed document (`transformed.yaml`).
spectral transform openapi.yaml -o transformed.yaml
Validating Documents
The `validate` command checks the provided document (`openapi.yaml`) for structural correctness and adherence to the specified format (e.g., OpenAPI, AsyncAPI).
spectral validate openapi.yaml
Other packages similar to @stoplight/spectral-cli
swagger-cli
swagger-cli is a command-line tool for validating and bundling OpenAPI definitions. It focuses on ensuring that OpenAPI documents are valid and can be bundled into a single file. Compared to Spectral, it is more specialized in OpenAPI validation and bundling but lacks the extensive linting and custom rule capabilities.
openapi-lint
openapi-lint is a linter specifically for OpenAPI documents. It provides a set of rules to enforce best practices in OpenAPI specifications. While it offers similar linting capabilities, it is not as flexible as Spectral in terms of custom rules and document transformation.