* fix: Remove github token with incorrect access * docs: Improve uninstall CTA in migration guide * fix: Update checkout action version for vale * docs: Vale reports errors in any edited file * docs: Update to make Vale happy * docs: Markdownlint fixes * fix: Remove sync actions as this integration is no longer used * core: Add markdownlint config and github action Uses rules from https://github.com/Redocly/marketing-site-portal/pull/1142 * chore: Move contributing file to top level * chore: Add markdown to the file types that we want prettier to operate on * fix: Make files fit prettier rules, ignore LICENSE since we can't change that * chore: Combine docs-related workflows into one for simplicity * docs: Add instructions for running the CLI docs standalone from this repo * chore: Add changeset, this docs change is quite large * Update .changeset/bright-steaks-walk.md Co-authored-by: Ihor Karpiuk <106662428+IgorKarpiuk@users.noreply.github.com> --------- Co-authored-by: Ihor Karpiuk <106662428+IgorKarpiuk@users.noreply.github.com>
3.9 KiB
Migrate to Redocly CLI from swagger-cli
Redocly CLI is the recommended replacement for the deprecated swagger-cli package. This guide shows you how to replace the old commands with Redocly CLI commands. Redocly CLI is built for OpenAPI but you can assume that Swagger 2.0 is also supported when the documentation refers to an OpenAPI description. We know those existing APIs are still working hard in many places!
{% admonition type="success" name="Modern API tooling" %} Redocly CLI is open source and actively maintained, supporting newer versions of OpenAPI (3.1) and continuing to evolve. It also provides extensive linting options, easy and beautiful API reference documentation, and plenty of extensibility with custom plugins. {% /admonition %}
Validate OpenAPI/Swagger files
Redocly CLI lints your OpenAPI file, checking that it is valid and also making recommendations to improve your OpenAPI descriptions. While you have multiple options for using Redocly CLI for better API standards let’s start with replacing the old command with the new command for linting with the minimal ruleset.
If the old command was:
swagger-cli validate openapi.yml
Then the new command is:
redocly lint --extends=minimal openapi.yml
You can run these commands locally, as part of your CI (continuous integration) pipeline, or (ideally) both.
Structure validation only
In some cases, checking additional rules during lint is less useful. For instance, in the case of legacy APIs that are no longer updated to meet more modern API expectations. To restrict Redocly to only checking that the API description meets the expected structure for OpenAPI, use a redocly.yaml file to configure a ruleset that contains only the spec rule.
The configuration in the redocly.yaml file should look like this:
extends: []
rule:
spec: error
Redocly CLI automatically detects the redocly.yaml configuration file, so your command should be:
redocly lint openapi.yml
You can add more built-in rules by adding them in the configuration file, and adjust the level of the messages by using warn rather than error.
Learn more about configuring Redocly CLI in the documentation.
Bundle OpenAPI/Swagger into a single file
While the OpenAPI (and earlier Swagger) standards were designed to use $ref reference syntax and re-use elements of API descriptions across mulitple files, not all tools support this. If there's a tool in your API lifecycle that needs a single file, you can still use mulitple files for the day-to-day work, and then "bundle" the API description into a single file for use by another tool.
With swagger-cli the command would be something like this:
swagger-cli bundle openapi.yml
With Redocly CLI the command to create a single file is:
redocly bundle openapi.yml
Both commands have additional options; here's a quick reference on how to replace the old with the new:
- Keep
-oor replace--outfilewith--outputto direct the command output to a filename. - Replace the
-tor--typeargument with--extfor the file type to output. Redocly CLI also detects the correct format from the output filename, so this option isn't needed for file output, but can be useful if outputting to stdout. - Replace
-ror--dereferencewith-ror--dereferencedto output a file with all$refs resolved.
Get the best from Redocly CLI
Redocly CLI has more functionality than swagger-cli did, so if that sounds interesting you should visit the main docs and see if there's anything you'd like to add to your own workflows.