-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhandler_api.yaml
More file actions
56 lines (48 loc) · 2.63 KB
/
Copy pathhandler_api.yaml
File metadata and controls
56 lines (48 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Language: Benthos YAML, Project: DatAasee, License: MIT, Author: Christian Himpe
processor_resources:
- label: 'handler_api'
processors:
- switch:
- check: 'metadata("request") == null && metadata("response") == null && metadata("params") == null'
processors:
- cached:
cache: 'global_cache'
key: 'api'
processors:
- label: 'handler_api__openapi_schema'
mapping: |
map prepend {
root = match {
this.externalDocs != null => { "externalDocs": { "url": "${DL_BASE}${DL_PATH}" + this.externalDocs.url } }
this.type() == "object" => this.map_each(z -> z.value.apply("prepend"))
this.type() == "array" => this.map_each(z -> z.apply("prepend"))
_ => this
}
}
root.data = file("/schemas/openapi.yaml").parse_yaml().apply("prepend")
root.data.paths."/database" = if env("DL_SAFE").bool(false) { deleted() }
- check: 'metadata("params").or("").re_match("^(api|database|schema|metadata)$") && !env("DL_SAFE").bool(false)'
processors:
- label: 'handler_api__params_schema'
mapping: |
root.data = file("/schemas/params/" + metadata("params").string() + ".json").parse_json()
- check: 'metadata("request").or("").re_match("^(ingest)$")'
processors:
- label: 'handler_api__request_schema'
mapping: |
root.data = file("/schemas/request/" + metadata("request").string() + ".json").parse_json()
- check: 'metadata("response").or("").re_match("^(api|database|error|health|ingest|metadata|ready|schema)$") && !env("DL_SAFE").bool(false)'
processors:
- label: 'handler_api__response_schema'
mapping: |
root.data = file("/schemas/response/" + metadata("response").string() + ".json").parse_json()
- processors:
- mapping: |
meta status = "404"
root.errors = [{"title": "Request Error: Not Found",
"detail": "A parameter is not an endpoint, has no request body, or no query parameters."}]
- catch:
- mapping: |
meta status = "500"
root.errors = [{"title": "Server error: Internal Server Error",
"detail": "Schema read error."}]