You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/doc/docs/references/api-schema.mdx
+29-30Lines changed: 29 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# API Schema
2
2
3
-
API Schema is a definition file for creating each Data API endpoint. When using VulcanSQL, you not only write SQL Query files to get results from the data source, but also need to write the API Schema, or no API created.
3
+
The API Schema is a configuration file for each Data API endpoint.
4
4
5
5
## API Schema Structure
6
6
7
-
Below is a API schema structure example, the API schema uses YAML format to define it:
7
+
Below is an example of the API schema structure, and the API schema uses the YAML format:
8
8
9
9
```yaml
10
10
urlPath: /users/:id
@@ -19,15 +19,14 @@ profiles:
19
19
- pg # replace this with your profile name
20
20
```
21
21
22
-
VulcanSQL will read the API Schema and know what the SQL files mapping it, then auto-generated APIs that map to the user-written SQL files.
23
-
24
-
Below is the introduction of each field in the structure.
22
+
Here is the introduction of each field in the API Schema.
25
23
26
24
## API Schema Fields
27
25
28
26
### `urlPath` Field
29
27
30
-
This is the Data API endpoint URL path. you could add the path parameter hereby `:[param-name]`, format, but when you add the path parameter, the `feildName` should also have the path parameter, and `fieldIn` should be `path`, if you forgot, VulcanSQL will auto-generated it to make it work.
28
+
This is the Data API endpoint URL path. You could add the path parameter here using the `:[param-name]` format.
29
+
If you forgot to add the `fieldName` and `filedIn` only if it's not `header`, VulcanSQL will auto generate it to make it work.
31
30
32
31
```yaml
33
32
urlPath: /users/:id
@@ -39,11 +38,11 @@ request:
39
38
40
39
After API is generated, VulcanSQL will add a prefix `/api` to distinguish Data API endpoints and other Non-Data API endpoints. For the above sample, the request url eventually should be `/api/users/:id`.
41
40
42
-
If you don't set urlPath, VulcanSQL uses your API Schema filename as the url, e.g. API schema filename is `user.yaml`, then the urlPath will be `/user`.
41
+
If you don't set the `urlPath`, VulcanSQL uses your API Schema filepath as the url, e.g. API schema filepath is `new/user.yaml`, then the urlPath will be `/new/user`.
43
42
44
43
### `templateSource` Field
45
44
46
-
The`templateSource` field could let VulcanSQL know what the SQL file this API will like to map for querying it and response data. It should be SQL filename ( not need file extension ).
45
+
The`templateSource` field is the mapping to the name of the respective SQL file.
47
46
48
47
```yaml
49
48
- sqls
@@ -58,10 +57,11 @@ templateSource: user
58
57
59
58
### `request` Fields
60
59
61
-
The `request` define what the request parameters would like to send with the API request, if you would like to have parameters to send the request, you should define the parameter with at least `fieldName`, `fieldIn` two fields.
60
+
The `request` fields define what are the request parameters sent with the API request.
61
+
If you would like to send a request with a parameter, you should define the parameter with at least `fieldName` and `fieldIn` fields.
62
62
63
-
- `fieldName` - The field name of the parameter of the API request, but the parameter field is optional, so you could send the request with the parameter optional. However, if your parameter is a path parameter e.g: `/users/:id`, then VulcanSQL will make the path parameter **required**.
64
-
- `fieldIn` - Where the parameter field is put in with the API request. It could be `path`, `query`, and `header`. If the `fieldIn` is the `path`, then you should also define the path parameter in `urlPath` . below is the sample:
63
+
- `fieldName` - The field name of the parameter of the API request. If it's a query parameter, it is optional by default. However, if your parameter is a path parameter e.g: `/users/:id`, then VulcanSQL will make the path parameter **required**.
64
+
- `fieldIn` - Where is the parameter field put within the API request. It could be `path`, `query`, and `header`. If the `fieldIn` is the `path`, then you should also define the path parameter in `urlPath`. Here is the sample:
65
65
66
66
```yaml
67
67
urlPath: users
@@ -73,30 +73,30 @@ The `request` define what the request parameters would like to send with the API
73
73
fieldIn: query
74
74
```
75
75
76
-
The request could be below 4 cases:
76
+
The requests could be 4 cases shown below:
77
77
78
78
```bash
79
79
/api/users
80
80
/api/users?gender=male
81
81
/api/users?age=18
82
82
/api/users?gender=male&age=18
83
-
84
83
```
85
84
86
-
- `type`- The `type` could let VulcanSQL know the data is what type for handing it. The type could be `string`, `number`, and `boolean`.
87
-
If not set the field, the default is `string` type. But don't worry, in most time, the driver is smart enough to handle parameter types, so it might take more effect on validators.
88
-
- `description`- The `description` field is an optional value too, but if you add the `description`, then it could make the API document could display the description to make the users know what the request field is.
89
-
- `validators`- The `validators` field is an array type to make the request parameter field have some validator to check the value format. E.g If your parameter field should be required, then set the `requried` in validators could make VulcanSQL check the parameter must be required. VulcanSQL provides some built-in validators for you, you could see the [API Validation](../develop/validator) to know the detail.
85
+
- `type`- It means the request parameter data type. It could be `string`, `number`, or `boolean`, and the default is `string` type.
86
+
- `description`- It's optional. If you add the `description` text, it'll be shown on the API documentation and the API catalog. It's more user friendly for users.
87
+
- `validators`- The `validators` field is an array type. It's used for validating request parameters.
88
+
For example, if your parameter field is required, then the `required` value should be filled in. VulcanSQL also provides some built-in validators for you,
89
+
you could see the [API Validation](../develop/validator) for further details.
90
90
91
91
### `sample` fields
92
92
93
93
The `sample` fields are optional fields, if you don't set them, then the API document will show the response fields in the API endpoint introduction. VulcanSQL will use `sample` fields to send a query for sampling and get the result column with the field type for generating the information in the API documentation.
94
94
95
95
If you would like to set it, you should provide these fields:
96
96
97
-
- `parameters` - The `parameters` could let you set the sampling data for the SQL query needed, for example, if your API needs to send the request with `gender` and `age`, then you should send the field in the `sample` fields:
97
+
- `parameters`- The parameters of API requests for querying sampling data.
98
98
99
-
- `profiles`: The `profiles` indicate the data source you would like to use for querying the sample data result.
99
+
- `profile`: The `profile` indicates the data source you would like to use for querying the sample data.
100
100
101
101
```yaml
102
102
urlPath: users/:id
@@ -114,17 +114,18 @@ profiles:
114
114
```
115
115
116
116
:::info
117
-
For the more detail of using `sample` field, please see [API Document](../develop/api-doc#setting-sampler).
117
+
For further details of using the `sample` field, please check out the section of [API Document](../develop/api-doc#setting-sampler) documentation.
118
118
119
119
:::
120
120
121
-
### `profiles` field / `profile` field
121
+
### `profiles` / `profile` field
122
122
123
-
The `profiles` / `profile` indicated which data sources the API will use to query the data result.
123
+
The `profiles` / `profile` indicate what data sources the APIs use to query the data.
124
124
125
-
The `profiles` field take precedence over the `profile` field when both existed.
125
+
The `profiles` field takes precedence over the `profile` field when both existed.
126
126
127
-
When you use the `profile`, it means the API endpoint will query the data from the data source, and each data source could set the [Authorization](../data-privacy/authz) to specify who ( users ) have permission to send the query by the Data API.
127
+
When you use the `profile`, it means the API endpoint will query the data from the data source.
128
+
You could set the [Authorization](../data-privacy/authz) for each data source to specify who has the permission to query data from APIs.
128
129
129
130
```yaml
130
131
urlPath: user/:id
@@ -134,9 +135,9 @@ request: ...
134
135
profile: pg
135
136
```
136
137
137
-
Like the above example, if today user3 would like to query the API, it has no authorization to the get result.
138
+
Like the above example, if user3 would like to query data from APIs, he doesn't have the permission to the get data.
138
139
139
-
When using the `profiles`, it could support multiple data sources like the below examples:
140
+
If you specify the `profiles` field, it could support multiple data sources like the below example:
140
141
141
142
```yaml
142
143
urlPath: user/:id
@@ -149,11 +150,9 @@ profile:
149
150
- duckdb
150
151
```
151
152
152
-
With the above example, user3 can use only `duckdb` profile to send queries.
153
-
154
-
This feature could make the user could use the sample SQL query but control the permission to make different use querying the data from different data sources.
153
+
With the above example, user3 can only use the `duckdb` profile to send API requests.
155
154
156
155
:::caution
157
-
You should make sure the `pg` and `duckdb` profiles have been properly configured for your project, please check [Data Source Profile](./data-source-profile) for further information.
156
+
You should make sure the `pg` and `duckdb` profiles have been properly configured for your project, please check out [Data Source Profile](./data-source-profile) for further information.
When sending an API request to query the data through SQL file logistic, also should check the data source ( e.g: Database, Warehouse ) has connected, so VulcanSQL needs you to define the Data Source Profile.
3
+
This file defines data source connection information.
4
4
5
5
## Define profile in independent YAML files
6
6
7
-
You could create independent YAML files to define data sources and set the filePath in the `profiles`options of the project config:
7
+
You could create independent YAML files to define data sources and set the filePath in the `profiles`option in the project config(`vulcan.yaml`):
8
8
9
9
```yaml
10
10
# pg-profile.yaml
11
11
- name: pg
12
-
type: postgres
12
+
type: pg
13
13
allow: '*'
14
14
connection:
15
15
host: example.com
@@ -20,32 +20,35 @@ You could create independent YAML files to define data sources and set the fileP
20
20
21
21
------------------------------------
22
22
# duck-profile.yaml
23
-
name: duck
24
-
type: duckdb
25
-
connection:
26
-
persistent-path: ./test-data/moma.db
27
-
log-queries: true
28
-
log-parameters: true
29
-
allow: '*'
23
+
- name: duckdb
24
+
type: duckdb
25
+
connection:
26
+
persistent-path: ./test-data/moma.db
27
+
log-queries: true
28
+
log-parameters: true
29
+
allow: '*'
30
30
31
31
-------------------------
32
32
# vulcan.yaml (project config)
33
33
extensions:
34
-
postgres: '@vulcan-sql/extension-driver-duckdb'
34
+
pg: '@vulcan-sql/extension-driver-pg'
35
35
duckdb: '@vulcan-sql/extension-driver-duckdb'
36
36
37
37
profiles:
38
38
- ./pg-profile.yaml
39
39
- ./duck-profile.yaml
40
40
```
41
41
42
-
You should make sure you have installed the data source driver package and declared the module name under the `extensions` of the project config.
42
+
You should make sure you have installed the required data source driver package and
43
+
declared the module name under the `extensions` in the project config(`vulcan.yaml`).
43
44
44
45
## Profile fields
45
46
46
-
In. this Profile, we should give these fields:
47
+
These fields are needed to be filled in:
47
48
48
-
- `name`- The `name` is the data source name for recognizing so that [API Schema](./api-schema) could set the name to know where the data source the API request queries the result from. Like above `duckdb-profile.yaml` example, the name is `duck`, so you could set the `duck` in `profiles` / `profile` in the API Schema to specify what data source the query is from.
49
-
- `type`- It's a data source type, each data source type uses the `module-name` under the `extensions` config to be the `type` for recognizing, the above sample you could see.
50
-
- `connection` - The needed information to make the connection built, you should check what the connection fields need in each external extension of the data, e.g: [@vulcan-sql/extension-driver-pg](https://www.npmjs.com/package/@vulcan-sql/extension-driver-pg) npm.
51
-
- `allow`- The `allow` field could make our Data API could query the data result from different data sources according to whether the user has permission or not. The [API Schema](./api-schema) `profiles` / `profile` fields have shown some examples. For the `allow` configuration rule, you could see the [Authorization](../data-privacy/authz) for introducing detail.
49
+
- `name`- This data source name should match with the value in the `profiles`/`profile` field according to [API Schema](./api-schema).
50
+
- `type`- It's the data source from the extension package name, such as `@vulcan-sql/extension-driver-[data source]`.
51
+
- `connection` - The information needed to connect to the data source, and you should check what connection fields are needed in each external extension, e.g: [@vulcan-sql/extension-driver-pg](https://www.npmjs.com/package/@vulcan-sql/extension-driver-pg).
52
+
- `allow`- This allows VulcanSQL to be able to query data from different data sources according to autorization rules.
53
+
There are some examples in the section of `profiles` / `profile` fields in [API Schema](./api-schema).
54
+
You could check out the [Authorization](../data-privacy/authz) to understand more about the `allow` configuration.
0 commit comments