2021-11-10 06:22:15 +01:00
The dataset metadata should be defined directly in the Swagger file, section `["example"]` . If this is not true, the following procedures will take place.
## Capabilities
2023-08-01 22:24:09 -06:00
This plugin reads the swagger file where the endpoints are defined, reads example data if provided (for any method), or searches for
data for the endpoints which do not have example data and accept a `GET` call.
2021-11-10 06:22:15 +01:00
2022-05-02 00:18:15 -07:00
For every selected endpoint defined in the `paths` section,
2023-08-01 22:24:09 -06:00
the tool searches whether the metadata are already defined.
2021-11-10 06:22:15 +01:00
As example, if in your swagger file there is the `/api/users/` defined as follows:
```yaml
paths:
/api/users/:
get:
2025-04-16 16:55:51 -07:00
tags: ["Users"]
2021-11-10 06:22:15 +01:00
operationID: GetUsers
description: Retrieve users data
responses:
2025-04-16 16:55:51 -07:00
"200":
2021-11-10 06:22:15 +01:00
description: Return the list of users
content:
application/json:
example:
2025-04-16 16:55:51 -07:00
{
"user": "username",
"name": "Full Name",
"job": "any",
"is_active": True,
}
2021-11-10 06:22:15 +01:00
```
then this plugin has all the information needed to create the dataset in DataHub.
2023-08-01 22:24:09 -06:00
In case there is no example defined, the plugin will try to get the metadata directly from the endpoint, if it is a `GET` method.
2021-11-10 06:22:15 +01:00
So, if in your swagger file you have
```yaml
paths:
/colors/:
get:
2025-04-16 16:55:51 -07:00
tags: ["Colors"]
2021-11-10 06:22:15 +01:00
operationID: GetDefinedColors
description: Retrieve colors
responses:
2025-04-16 16:55:51 -07:00
"200":
2021-11-10 06:22:15 +01:00
description: Return the list of colors
```
2023-08-01 22:24:09 -06:00
the tool will make a `GET` call to `https://test_endpoint.com/colors`
2021-11-10 06:22:15 +01:00
and parse the response obtained.
### Automatically recorded examples
Sometimes you can have an endpoint which wants a parameter to work, like
`https://test_endpoint.com/colors/{color}` .
Since in the OpenApi specifications the listing endpoints are specified
just before the detailed ones, in the list of the paths, you will find
2023-08-01 22:24:09 -06:00
https://test_endpoint.com/colors
2021-11-10 06:22:15 +01:00
defined before
https://test_endpoint.com/colors/{color}
This plugin is set to automatically keep an example of the data given by the first URL,
which with some probability will include an example of attribute needed by the second.
So, if by calling GET to the first URL you get as response:
{"pantone code": 100,
"color": "yellow",
...}
2025-04-16 16:55:51 -07:00
the `"color": "yellow"` part will be used to complete the second link, which
2021-11-10 06:22:15 +01:00
will become:
https://test_endpoint.com/colors/yellow
and this last URL will be called to get back the needed metadata.
### Automatic guessing of IDs
If no useful example is found, a second procedure will try to guess a numerical ID.
So if we have:
2023-08-01 22:24:09 -06:00
https://test_endpoint.com/colors/{colorID}
2021-11-10 06:22:15 +01:00
and there is no `colorID` example already found by the plugin,
it will try to put a number one (1) at the parameter place
https://test_endpoint.com/colors/1
and this URL will be called to get back the needed metadata.
## Config details
2022-02-25 08:29:01 +01:00
### Token authentication
If this tool needs to get an access token to interrogate the endpoints, this can be requested. Two methods are available at the moment:
2025-04-16 16:55:51 -07:00
- 'get' : this requires username/password combination to be present in the url. Note that {username} and {password} are mandatory placeholders. They will be replaced with the true credentials at runtime. Note that username and password will be sent in the request address, so it's unsecure. If your provider allows for the other method, please go for it.
- 'post' : username and password will be inserted in the body of the POST request
2022-02-25 08:29:01 +01:00
In both cases, username and password are the ones defined in the configuration file.
2021-11-10 06:22:15 +01:00
### Getting dataset metadata from `forced_example`
2022-05-02 00:18:15 -07:00
Suppose you have an endpoint defined in the swagger file, but without example given, and the tool is
2021-11-10 06:22:15 +01:00
unable to guess the URL. In such cases you can still manually specify it in the `forced_examples` part of the
2022-05-02 00:18:15 -07:00
configuration file.
2021-11-10 06:22:15 +01:00
As example, if in your swagger file you have
```yaml
paths:
/accounts/groupname/{name}/:
get:
2025-04-16 16:55:51 -07:00
tags: ["Groups"]
2021-11-10 06:22:15 +01:00
operationID: GetGroup
description: Retrieve group data
responses:
2025-04-16 16:55:51 -07:00
"200":
2021-11-10 06:22:15 +01:00
description: Return details about the group
```
2023-08-01 22:24:09 -06:00
and the plugin did not find an example in its previous calls,
the tool has no idea about what to substitute for the `{name}` part.
2021-11-10 06:22:15 +01:00
By specifying in the configuration file
```yaml
2025-04-16 16:55:51 -07:00
forced_examples: # optionals
/accounts/groupname/{name}: ["test"]
2021-11-10 06:22:15 +01:00
```
the plugin is able to build a correct URL, as follows:
2022-05-02 00:18:15 -07:00
https://test_endpoint.com/accounts/groupname/test