Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lieldulev/swagger-to-locustfile
A CLI tool that creates locust.io tasks file (locustfile.py) from Swagger/OpenAPI Spec.
https://github.com/lieldulev/swagger-to-locustfile
Last synced: 28 days ago
JSON representation
A CLI tool that creates locust.io tasks file (locustfile.py) from Swagger/OpenAPI Spec.
- Host: GitHub
- URL: https://github.com/lieldulev/swagger-to-locustfile
- Owner: lieldulev
- License: isc
- Created: 2016-01-21T18:29:43.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-07-13T23:02:25.000Z (over 2 years ago)
- Last Synced: 2024-11-10T19:56:38.500Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 31.3 KB
- Stars: 32
- Watchers: 3
- Forks: 13
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-locust - swagger-to-locustfile - A command-line tool to create Locust tasks file (locustfile) from Swagger/OpenAPI spec. (Tools / Miscellaneous)
README
# swagger-to-locustfile
A CLI tool that creates [locust.io](http://locust.io) tasks file (locustfile.py) from [Swagger/OpenAPI Spec](https://github.com/OAI/OpenAPI-Specification).## Requirements
* Node JS (4.0 & up)## Installation
Best option is:
1. `$ git clone https://github.com/DataGreed/swagger-to-locustfile.git`
2. `$ cd swagger-to-locustfile`
3. `$ npm -g install`
4. You are good to go.## Currently Supports
* Grabbing the host field for the spec.
* Generating tasks for GET/POST/PUT/UPDATE/DELETE endpoints.
* Replacing Path-Parameters holders with their default value.
* Appending the required query string parameters and their default values.
* Swagger/OAI vendor extensions (`x-locust-import` and `x-locust-value`) to override default values with custom python expressions.
* Command Line Options allow overriding `min_wait`, `min_max` and `host`## Future Plans / Open Issues
* Extracting body/params for POST/PUT/DELETE/UPDATE endpoints.
* Support *required* headers## Usage
__Basically:__
`$ swagger2locust /path/to/swagger.json > /tmp/locustfile.py`
_Or you can pipe the spec:_
`$ cat /path/to/spec.yaml | swagger2locust`
__Full Usage:__
```
Usage: swagger2locust [options]Options:
-h, --help output usage information
-V, --version output the version number
-m, --min minimum time, in milliseconds, that a simulated user will wait between executing each task (default: 1000).
-x, --max maximum time, in milliseconds, that a simulated user will wait between executing each task (default: 3000).
-H, --host The host attribute is a URL prefix (i.e. “http://google.com”) to the host that is to be loaded.```
## Custom Swagger/OAI fields
### x-locust-import
You can add `x-locust-import` to your root node (same level as `host` field) to specify extra imports for your locust file. _This is useful if you need access to an import when you write an expression in `x-locust-value`._
So for the following swagger spec:
JSONYAML
{
"swagger" : "2.0",
...
"host" : "subdomain.domain.tld",
"x-locust-import" : ["time"],
...
}
swagger: "2.0"
...
host: "subdomain.domain.tld"
x-locust-import:
- "time"
...The `locustfile.py` will have the following imports:
```.py
from locust import HttpLocust, TaskSet, task
import timeclass MyTaskSet(TaskSet):
...
```### x-locust-value
`x-locust-value` allows you to write a python expression that replaces the hardcoded
default value of a field.
Example:The following spec file
JSONYAML
...
"paths" : {
"/required/qs/params-with-x-locust-value" : {
"get" : {
"parameters" : [ {
"name" : "sreq_timestamp_param",
"in" : "query",
"description" : "Some timestamp.",
"required" : true,
"type" : "number",
"default" : 1455134652,
"x-locust-value" : "str(int(time.time()))"
} ]
}
}
}
...
...
paths:
/required/qs/params-with-x-locust-value:
get:
parameters: -
name: "req_timestamp_param"
in: "query"
description: "Some timestamp."
required: true
type: "number"
default: 1455134652
x-locust-value: "str(int(time.time()))"
...Will result in the following line in `locustfile.py` (__`x-locust-value`
overrrides `default`__):```.py
...
@task
def get_required_qs_params_with_x_locust_value(self):
self.client.get("/api/v1/required/qs/params-with-x-locust-value?some_required_timestamp_param={0}".format(str(int(time.time()))))
...
```While omitting `x-locust-value` field will result in the following line:
```.py
...
@task
def get_required_qs_params_without_x_locust_value(self):
self.client.get("/api/v1/required/qs/params-with-x-locust-value?some_required_timestamp_param={0}".format("1455134652"))
...
```## Contribute
* fork
* create a branch on your fork.
* pull-request to master branch here.
* win.### Thanks
- [@DataGreed](https://github.com/DataGreed) (PR #13)
## License### ISC License (ISC)
Copyright (c) 2016, Liel DulevPermission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.