├── .gitignore
├── README.md
├── pom.xml
└── src
└── main
├── assembly
└── assembly.xml
├── bin
└── startup.cmd
├── java
└── com
│ └── lyl
│ └── plugin
│ ├── EnvArgs.java
│ ├── JmxGenerator.java
│ ├── generate
│ ├── ExampleGenerator.java
│ ├── MyDefaultGenerator.java
│ └── XmlExampleGenerator.java
│ ├── model
│ ├── ParamNode.java
│ ├── RequestNode.java
│ ├── TagNode.java
│ └── VariableNode.java
│ ├── parse
│ ├── AuthParser.java
│ └── SwaggerParser.java
│ ├── utils
│ └── ModelUtils.java
│ └── vo
│ └── TemplateParamVO.java
└── resources
└── templates
└── template.jmx
/.gitignore:
--------------------------------------------------------------------------------
1 | Thumbs.db
2 | .project
3 | .classpath
4 | /.evosuite/
5 | /.settings/
6 | /.idea/
7 | /target/
8 | *.class
9 | *.log
10 | *.bak
11 | *.tmp
12 | *.swp
13 | *.orig
14 | *.iml
15 | out
16 | gen
17 | target
18 | logs
19 | LOG_PATH_IS_UNDEFINEDdaily
20 | LOG_PATH_IS_UNDEFINEDLOG_FILE_IS_UNDEFINED
21 | *.prefs
22 | org.eclipse.wst.common.project.facet.core.xml
23 | .project
24 | .classpath
25 | .factorypath
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | #### V1.1 新增功能介绍
3 |
4 | * 支持通过初始参数值默认生成
5 | 生成jmeter脚本会根据参数的默认值(即取@ApiImplicitParam的defaultValue和@ApiModelProperty的example的值)生成。
6 |
7 | * 支持测试用例生成的顺序
8 | @ApiOperation维护扩展属性{@Extension(name="ext",properties = @ExtensionProperty(name = "sortNo", value = "1"))}),指定sortNo的值,值越小,生成测试用例越靠前。
9 |
10 | ***
11 |
12 |
13 | #### Step 1: 获取工具包
14 |
15 | 1、直接到 [latest stable release](https://github.com/liuyunlong1229/swagger2jmx-plugin/releases).下载
16 |
17 | 2、有maven环境的话,直接在本地执行mvn package生成
18 |
19 | #### Step 2: 解压包后,运行bin目录下的startup.cmd文件,运行前先设置2个参数值
20 |
21 | 【SWAGGER_LOCATION】参数:指定swagger的源,可以是本地文件,或者线上的swagger地址。
22 |
23 | * **方式一:线上swagger**
24 |
25 | ```sh
26 | SWAGGER_LOCATION=http://localhost:18083/v2/api-docs
27 |
28 | ```
29 |
30 | * **方式二:本地swagger的文件,也就是上面的线上显示的整个大的json内容保存到本地一个文件中**。
31 |
32 | ```sh
33 | SWAGGER_LOCATION=D:/swagger.json
34 |
35 | ```
36 |
37 | 【JMX_FILE_DIR】参数:指定生成jmeter脚本`auto_test.jmx`生成的位置
38 | 例如保存到D:/jmeter目录下,可以这么设置
39 |
40 | ```sh
41 | JMX_FILE_DIR=D:/jmeter/
42 |
43 | ```
44 | #### 效果
45 | 
46 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.lyl
8 | swagger2jmx-plugin
9 | 1.0-SNAPSHOT
10 |
11 |
12 | 1.8
13 | 1.8
14 | 2.1.1
15 | 2.0.19
16 | UTF-8
17 |
18 |
19 |
20 |
21 |
22 | io.swagger.core.v3
23 | swagger-core
24 | ${swagger-core-version}
25 |
26 |
27 | io.swagger.parser.v3
28 | swagger-parser
29 | ${swagger-parser-version}
30 |
31 |
32 |
33 | org.freemarker
34 | freemarker
35 | 2.3.23
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.apache.maven.plugins
44 | maven-jar-plugin
45 | 2.6
46 |
47 |
48 | false
49 |
50 | true
51 | lib/
52 | com.lyl.plugin.JmxGenerator
53 |
54 |
55 |
56 |
57 |
58 |
59 | org.apache.maven.plugins
60 | maven-assembly-plugin
61 |
62 |
63 | src/main/assembly/assembly.xml
64 |
65 |
66 |
67 |
68 | package
69 |
70 | single
71 |
72 |
73 |
74 |
75 |
76 |
77 | org.apache.maven.plugins
78 | maven-surefire-plugin
79 |
80 | true
81 |
82 |
83 |
84 |
85 | swagger2jmx-plugin
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/src/main/assembly/assembly.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
10 |
11 | ${version}-bin
12 |
13 |
14 |
15 | zip
16 |
17 |
18 |
19 | false
20 |
21 |
22 |
23 |
24 | false
25 | lib
26 | false
27 |
28 |
29 |
30 |
31 |
32 |
33 | ${project.basedir}
34 |
35 |
36 | README*
37 | LICENSE*
38 | NOTICE*
39 |
40 |
41 |
42 |
43 |
47 |
48 |
49 |
50 | ${project.basedir}/src/main/bin
51 | bin
52 |
53 |
54 |
55 |
56 | ${project.build.directory}
57 |
58 |
59 | *.jar
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/src/main/bin/startup.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | rem Copyright 1999-2018 Alibaba Group Holding Ltd.
3 | rem Licensed under the Apache License, Version 2.0 (the "License");
4 | rem you may not use this file except in compliance with the License.
5 | rem You may obtain a copy of the License at
6 | rem
7 | rem http://www.apache.org/licenses/LICENSE-2.0
8 | rem
9 | rem Unless required by applicable law or agreed to in writing, software
10 | rem distributed under the License is distributed on an "AS IS" BASIS,
11 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | rem See the License for the specific language governing permissions and
13 | rem limitations under the License.
14 | if not exist "%JAVA_HOME%\bin\java.exe" echo Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better! & EXIT /B 1
15 | set "JAVA=%JAVA_HOME%\bin\java.exe"
16 |
17 | setlocal enabledelayedexpansion
18 |
19 | set BASE_DIR=%~dp0
20 | rem added double quotation marks to avoid the issue caused by the folder names containing spaces.
21 | rem removed the last 5 chars(which means \bin\) to get the base DIR.
22 | set BASE_DIR="%BASE_DIR:~0,-5%"
23 |
24 | rem the swagger address, which can be online or local
25 | set SWAGGER_LOCATION=http://localhost:18083/v2/api-docs
26 |
27 | rem File directory for JMeter script output
28 | set JMX_FILE_DIR=D:/jmeter-script/
29 |
30 | set SERVER=swagger2jmx-plugin
31 |
32 | rem set exec options
33 | set "EXEC_OPTS=-Dfile.encoding=utf-8"
34 | set "EXEC_OPTS=%EXEC_OPTS% -jar %BASE_DIR%\%SERVER%.jar"
35 | set "EXEC_OPTS=%EXEC_OPTS% --i=%SWAGGER_LOCATION% --o=%JMX_FILE_DIR%"
36 |
37 | set COMMAND="%JAVA%" %EXEC_OPTS%
38 |
39 | rem start generate command
40 | %COMMAND%
41 |
42 | pause
--------------------------------------------------------------------------------
/src/main/java/com/lyl/plugin/EnvArgs.java:
--------------------------------------------------------------------------------
1 | package com.lyl.plugin;
2 |
3 | /**
4 | * 运行参数对象
5 | * @author yunlong.liu
6 | * @date 2020-11-06 11:35:10
7 | */
8 |
9 | public class EnvArgs {
10 |
11 | /**
12 | * swagger地址,可以是网上的地址,也可以是本地文件
13 | */
14 | private String swaggerAddr;
15 |
16 | /**
17 | * jmeter的脚本生成位置
18 | */
19 | private String fileOutput;
20 |
21 | public String getSwaggerAddr() {
22 | return swaggerAddr;
23 | }
24 |
25 | public void setSwaggerAddr(String swaggerAddr) {
26 | this.swaggerAddr = swaggerAddr;
27 | }
28 |
29 | public String getFileOutput() {
30 | return fileOutput;
31 | }
32 |
33 | public void setFileOutput(String fileOutput) {
34 | this.fileOutput = fileOutput;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/lyl/plugin/JmxGenerator.java:
--------------------------------------------------------------------------------
1 | package com.lyl.plugin;
2 |
3 |
4 | import com.lyl.plugin.generate.MyDefaultGenerator;
5 | import org.apache.commons.lang3.StringUtils;
6 |
7 | /**
8 | * 生成器,程序主入口
9 | * @author yunlong.liu
10 | * @date 2020-11-03 19:42:43
11 | */
12 |
13 | public class JmxGenerator {
14 |
15 | public static void main(String[] args) {
16 |
17 | // generate -i swagger.json -g jmeter
18 |
19 | EnvArgs envArgs= parseArgs(args);
20 |
21 | MyDefaultGenerator myDefaultGenerator=new MyDefaultGenerator();
22 | try {
23 | myDefaultGenerator.generate(envArgs.getSwaggerAddr(),envArgs.getFileOutput());
24 | System.out.println("++++++++生成好了 ,文件地址:"+envArgs.getFileOutput()+"/auto_test.jmx");
25 | } catch (Exception e) {
26 | e.printStackTrace();
27 | }
28 |
29 |
30 | }
31 |
32 |
33 | static EnvArgs parseArgs(String [] args){
34 |
35 | // if(args==null || args.length <2){
36 | // System.err.println("请通过参数swagger地址和脚本输出目录");
37 | // System.exit(1);
38 | // }
39 | // "--i=http://localhost:18083/v2/api-docs";
40 | // "--o=D:/";
41 | EnvArgs envArgs=new EnvArgs();
42 | for(int i=0;i examples;
34 | private OpenAPI openAPI;
35 | private Random random;
36 |
37 | public ExampleGenerator(Map examples, OpenAPI openAPI) {
38 | this.examples = examples;
39 | this.openAPI = openAPI;
40 | this.random = new Random((long)"ExampleGenerator".hashCode());
41 | }
42 |
43 | public List