forked from cloudquery/plugin-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.py
More file actions
57 lines (54 loc) · 1.71 KB
/
openapi.py
File metadata and controls
57 lines (54 loc) · 1.71 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
57
import pyarrow as pa
from cloudquery.sdk.transformers import oapi_definition_to_columns
from cloudquery.sdk.schema import Column
from cloudquery.sdk.types import JSONType
OAPI_SPEC = {
"swagger": "2.0",
"info": {
"version": "2.0",
"title": "Test API",
"description": "Unit tests APIs",
},
"host": "cloudquery.io",
"schemes": ["https"],
"consumes": ["application/json"],
"produces": ["application/json"],
"paths": {},
"definitions": {
"TestDefinition": {
"type": "object",
"properties": {
"string": {
"type": "string",
},
"number": {
"type": "number",
},
"integer": {
"type": "integer",
},
"boolean": {
"type": "boolean",
},
"object": {
"$ref": "#/definitions/SomeDefinition",
},
"array": {
"type": "array",
"items": {"$ref": "#/definitions/SomeDefinition"},
},
},
},
},
}
def test_oapi_properties_to_columns():
expected_columns = [
Column("string", pa.string(), description=None),
Column("number", pa.int64(), description=None),
Column("integer", pa.int64(), description=None),
Column("boolean", pa.bool_(), description=None),
Column("object", JSONType(), description=None),
Column("array", JSONType(), description=None),
]
columns = oapi_definition_to_columns(OAPI_SPEC["definitions"]["TestDefinition"])
assert expected_columns == columns