Definition schema
Schema
Example
The format will be illustrated using the example available in our GitHub repository:
Now let’s go over the fields in the definition file
Fields
version (required)
The version field specifies the version of the definition file. Currently, the latest version is version 1
name (required)
The name is a unique identifier for the definition. It must be unique and should be somewhat declarative. Preferably someone should know by the name and the context which endpoint will be monitored just by looking at the name.
format (required)
This field specifies the response format the API returns. Currently, the following formats are supported
- JSON
- YAML
base_url (required)
This field contains the base URL of the request, meaning the requested path without query parameters.
Example
Let’s say you want to monitor the following endpoint
Then the base URL of the definition would be the following
query_parameters
This is a list of query parameters to add to the #base_url. Each one is a pair of name and value
Example
This would result in the Completed
variable being inserted into the completed
query parameter
and would result in a URL looking like this
variables
In the variable section of the definition file you can define two types of variables.
- Constant
- Not Constant
These variables lead to the creation of so-called test cases. For each definition file All test cases are run and the results are added to the report.
Constant variables
Constant variables have only one constant value and keep their value throughout all test cases
Non constant variables
Non-constant variables are variables with multiple values. Keep in mind, that the number of values for non-constant variables must not differ for any variable. The amount of values in a non-constant variable declaration determines how many test cases there are.
Example
A set of variables could look something like this
And their use in the #base_url field like this
With these query parameters
This will lead to the creation of two test cases, because the non-constant variables have two values each (in this example there is only one)
The test cases will look like this
test_case_names
Each test case that gets generated will also get a human-readable name.
If this field is not set all test cases will be named TestCaseN
where N
is the number of test case starting at one
If you want to assign your own names you can populate this array with names for all test cases. It is important that the number of names in this list matches the amount of generated test cases
method
This field sets the HTTP method of the requests. By default, this is a GET request. Currently, the following HTTP methods are allowed
- GET
- POST
- PUT
- DELETE
payload
This can contain an arbitrary object that can be serialized to JSON to send along the request
ok_code
This field defines which code to expect in case of success. If not set defaults to 200 (OK)
excluded_validators
This is a list of validators to skip in the validation process. They will still show up in the report as skipped
authorization
Use this field to override the value of the Authorization HTTP header. Takes precedence over #headers but gets overridden by #jwt_login
jwt_login
This field can be used to define a JWT authentication procedure
url
This field sets the endpoint to send the login request to
login_paylaod
This contains an arbitrary JSON serializable object to send along the login request containing probably the credentials
token_key_name
This contains the name of the top-level property of the response object where the JWT token resides.
Example
An example setup could look like this
In this example a following request will be sent
A response like this is expected
Check out Secrets on how to use secrets to hide sensitive login data in your definition
headers
Here you can add additional headers to add to each request
Example
Let’s say you want to add a custom header called AwesomeHeader
. Then the field would look like this
response_schema
This field contains the expected response schema on a successful request. The schema is in the form of the json-schema specification
Templating
Some parts in the definition support Go templates. Other than the variables defined by the user and default template constructs there are also some built-in functions that can be used in the templates
Built-in functions
The apisense definition template has also two build in functions you can use
- Now
- Env
Now
Now is a function that takes as an argument a valid go time format string and prints out the current time in the provided format upon templating.
Note that the templating happens each time the daemon does a validation cycle.
Env
Env takes in a string and prints out the value of the environment variable with the given key. If the key does not exist, the function prints a empty string.