preface
The company has a new front end person, the previous development specification is a single project development, independently responsible for the front and back end projects, so there is no interface documentation.
However, in order to develop specifications, the development mode is changed to front-end development. Therefore, there is an urgent need for an interface management server. The interface of Yapi is beautiful enough, and it will not be particularly serious to code intrusion. The most important thing is that it can be deployed on the Intranet with open source, so it is decided as Yapi.
An overview,
YAPI is a visual interface management tool developed by Qunar Mobile Architecture team (YMFE, a group of FE, iOS and Android engineers composed of the most imaginative, creative and influential front-end team). It is a locally deployable interface management platform that connects the front end and QA. YAPI is designed to provide more elegant interface management services for developers, products and testers. It can help developers easily create, publish and maintain apis for different projects and platforms. With YAPI, we can easily test, manage and maintain API interfaces of multiple projects. Unlike Swagger, which is born and die with application (and most of them have to be closed in online environment), YAPI is an independent service platform.
Two, installation steps
Environmental requirements:
- Nodejs (+ 7.6)
- Directing (+ 2.6)
Native version:
[root@localhost my-yapi]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
Copy the code
2.1 installation nodejs
Nodejs installation is relatively simple and can be compared with this article:
Centos7 NodeJS installation
2.2 installation mongo
Other versions can be downloaded from the official website:
www.mongodb.com/download-ce…
I used mongodb version 4.0.10 and uploaded it to the specified directory.
-
1. Unpack
[root@localhost package]# tar -xvf mongodb-linux-x86_64-4.0.10. TGZ -c /opt/software/Copy the code
-
2. Rename and configure environment variables
[root@localhost software]# mv mongodb-linux-x86_64-4.0.10/ mongodb [root@localhost software]# vim /etc/profile [root@localhost software]# source /etc/profile Copy the code
export MONGODB_HOME=/opt/software/mongodb export PATH=$MONGODB_HOME/bin Copy the code
-
3. Create a folder
[root@localhost mongodb]# mkdir -p data/db [root@localhost mongodb]# mkdir -p logs [root@localhost mongodb]# ls bin data LICENSE-Community.txt logs MPL-2 README THIRD-PARTY-NOTICES THIRD-PARTY-NOTICES.gotoolsCopy the code
-
4. Create the mongodb
Dbpath = / opt/software/mongo/data/db # data file directory contains the logpath = / opt/software/mongo/logs/mongo. Log port = # log file storage directory 27017 # port fork =true # Enabled in daemon mode, i.e. running in the background noauth =true # no security verification # auth=true # authentication required. Bind_ip =0.0.0.0 # allow remote access, or direct comment 127.0.0.1 is only allowed local accessCopy the code
-
5. Start mongodb and check
[root@localhost mongodb]# bin/mongod -f mongodb.conf Error parsing INI config file: The options configuration file contains an invalid line ' 'try 'bin/mongod --help' for more information [root@localhost mongodb]# vim mongodb.conf [root@localhost mongodb]# bin/mongod -f mongodb.conf about to fork child process, waiting until server is ready for connections. forked process: 11068 child process started successfully, parent exiting [root@localhost mongodb]# ps -ef|grep mongodb root 11068 1 5 14:42 ? 00:00:00 bin/mongod -f mongodb.conf root 11270 58533 0 14:43 pts/1 00:00:00 grep --color=auto mongodbCopy the code
2.3 installation Yapi – cli
-
1, direct online installation
npm install -g yapi-cli --registry https://registry.npm.taobao.org yapi server Copy the code
-
2. Access the corresponding IP address page
-
3. Write corresponding information. The deployment is successful.
If failed, may be a version of yapi bug, see this article: www.showdoc.com.cn/p/b9c1a4929…
-
4. Go to the yAPI directory and start the server node Vendors /server/app.js
[root@localhost software]# ls java8 mongodb mysql8 my-yapi nacos nginx node12 redis6 [root@localhost software]# cd my-yapi/ [root@localhost my-yapi]# node vendors/server/app.js & log: -------------------------------------swaggerSyncUtils constructor----------------------------------------------- log: The mongodb service has been started. Please open the following link: http://127.0.0.1:3000/ log: mongodb Load Success...Copy the code
[Note] : Add a & here to make yAPI start in the form of the background, will not close the window after the service stop.
-
5. Access port 3000 and log in according to the account and password given by it
2.4 docker installation
Reference: hub.docker.com/r/yapipro/y…
3. Yapi gameplay
3.1 Adding a Group
3.2 Adding a Project
3.3 Installing the Browser Plug-in
This can be used as our Postman test, with direct browser access to the local service.
However, you need to install a Yapi cross-domain plug-in
The test interface
4.3 configuration token
- Windows quick publishing interface Alt + Shift + E
- Quick publishing interface on MAC: CTRL + E
4.4 annotations demo
4.4.1 Controller layer annotation
/** * @module attribute */ @restController @requestMapping (value = "/pathOfCtrl") public class MockCtrl { /** * API name * API Description * @param Param1 The name or description of parameter 1 * @param Param2 can use '@link' to indicate that the current parameter is an enumeration {@link Some. Enum. The or. Constant. Class} * @ param param3 when the target enumeration field do not agree with the field name, specify additional {@ link some. Enum. Or. Constant. Class# property1} * @return Response */ @requestMapping (value = "/pathOfApi1") public Result methodName1(Long Param1, @RequestParam String param2, @RequestParam(required = false, defaultValue = "defaultValueOfParam3") String param3){ ... } /** ** default 'application/x-www-form-urlencoded', * For '@requestBody' it will use 'application/json' * it can be annotated '@deprecated' to indicate API deprecation * it can be annotated '@deprecated' * * @deprecated to use {@link #methodName3(String)} */ @Deprecated @RequestMapping(value = "/pathOfApi2") public Result methodName2(@RequestBody MockDtoOrVo jsonModel){ ... } /** * All comments or parameter descriptions can use '@link' to refer to another API * for example: * Please visit {@link #methodName4(String)} * another API can be referenced using '@see' * * @param Param1 The name or description of parameter 1 can be obtained from {@link #methodName5(String)} * @see #methodName6(String) * @deprecated Use {@link #methodName7(String)} */ @deprecated @requestMapping (value =) "/pathOfApi3") public Result methodName3(long param1){ ... }... }Copy the code
4.4.2 Annotation writing method of entity class
Public class MockDtoOrVo {/** ** private Long field1; private Double field2; / / comment can also be written in the book that / * * * using the @ see to illustrate the value of the current field is an enumeration * @ see some. Enum. The or. Constant. The class * / private int field3; / * * * when the target enumeration field do not agree with the field name, specify additional * @ see some. Enum. The or. Constant. Class# property1 * / private int field4. /** * You can use the annotation '@deprecated' to indicate that a field is Deprecated * or you can use the annotation '@deprecated' * @deprecated It's a secret */ @deprecated private int field5; @notBlank @notnull Private String field6; @notblank @notnull private String field6; . }Copy the code
4.5 Common Configuration Rules
4.5.1 the module
- For API grouping
- If no configuration takes effect, the current module/project name is used by default
- export
postman
Will be for eachmodule
Create a folder - export
yapi
, eachmodule
The correspondingyapi
One of the projects
demo:
/**
* Mock Apis
*
* @module mock
*/
@RestController
@RequestMapping(value = "mock")
public class MockCtrl {
}
Copy the code
4.5.2 ignore
Used to ignore methods or classes.
demo:
/**
* Mock Apis
*
* @ignore
*/
@RestController
@RequestMapping(value = "mock")
public class MockCtrl {
}
Copy the code
4.5.3 json. Rule. The field name
- Used to set the case where the output or input field names are different
The demo:
public class TestJsonFieldBean {
@JsonProperty("a")
private Long propertyA;
@SerializedName("b")
private Long propertyB;
}
Copy the code
The derived result is:
The name of the | type | Whether must | The default value | note | Other information |
---|---|---|---|---|---|
a | integer | Not a must | 00 mock: @ natural (0100) | ||
b | integer | Not a must | 00 mock: @ natural (0100) |
4.5.4 json. Rule. Field. Ignore
Ignore the field
The demo:
public class TestJsonIgnoreBean {
@Expose(serialize = true)
private Long shouldNotIgnoreForGson;
@Expose(serialize = false)
private Long shouldIgnoreForGson;
@JsonIgnore(false)
private Long shouldNotIgnoreForJackson;
@JsonIgnore
private Long shouldIgnoreForJackson;
}
Copy the code
Export results:
The name of the | type | Whether must | The default value | note | Other information |
---|---|---|---|---|---|
shouldNotIgnoreForGson | integer | Not a must | 00 mock: @ natural (0100) | ||
shouldNotIgnoreForJackson | integer | Not a must | 00 mock: @ natural (0100) |