This tutorial will show you how to automatically update Swagger data to the YApi management platform, assuming you’re already comfortable using the YApi management platform.

Configure the environment

Yapi-cli depends on Node.js, please install at least version 7.6 of Node.js, if you have installed yapi-CLI tool on your machine, and the version is >= 2.7, you can ignore this section.

Installation Node. Js

Solution 1: Download the installation package from the node.js official website

Solution 2: Install node.js using Node Version Manager(NVM). You can install NVM using the following command:

cURL:

$curl - o - https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bashCopy the code

Wget:

$wget - qO - https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bashCopy the code

Once NVM is installed, restart the terminal and run the following command to install Node.js:

nvm install stable
Copy the code

Install yAPI using the NPM cli

Ensure that yapi- CLI tool version >= 1.2.7.

npm install yapi-cli [-g]
Copy the code

Method of use

This feature can be used on any machine, just make sure that the machine can connect to the deployed YApi web site.

Step 1: Create a configuration file

Create a configuration file yapi-import.json in any directory. The content is as follows:

{
  "type": "swagger"."token": "17fba0027f300248b804"."file": "swagger.json"."merge": "good"."server": "http://yapi.local.qunar.com:3000"
}
Copy the code

Type is a datatype, currently officially only supported by Swagger

The token is a project token. Go to Project Settings -> Token Settings to obtain the token

File is a Swagger interface documentation file that can be used with absolute paths or URLS

Merge Import the old interface policy. The default interface mode is smart. There are three modes: “Normal”, “good”, and “merge”

Server is the ADDRESS of the YAPI server

Step 2: Run the import command

In the current directory of the new configuration file, execute the following commands to import the data to the YAPI management platform.

yapi import
Copy the code

If a message is displayed indicating that the yapi command cannot be found, you can run the yapi-cli command because some system environments are incompatible.

Automatic updates

With scheduled task execution tools such as CronTab, you can automatically update interface data. You are smart enough to do this.