voluptuous-openapi 0.0.2__tar.gz → 0.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {voluptuous_openapi-0.0.2/voluptuous_openapi.egg-info → voluptuous_openapi-0.0.4}/PKG-INFO +1 -1
- {voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4}/setup.py +1 -1
- {voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4}/tests/test_lib.py +49 -3
- {voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4}/voluptuous_openapi/__init__.py +39 -38
- {voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4/voluptuous_openapi.egg-info}/PKG-INFO +1 -1
- {voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4}/LICENSE +0 -0
- {voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4}/MANIFEST.in +0 -0
- {voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4}/README.md +0 -0
- {voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4}/setup.cfg +0 -0
- {voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4}/voluptuous_openapi.egg-info/SOURCES.txt +0 -0
- {voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4}/voluptuous_openapi.egg-info/dependency_links.txt +0 -0
- {voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4}/voluptuous_openapi.egg-info/requires.txt +0 -0
- {voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4}/voluptuous_openapi.egg-info/top_level.txt +0 -0
- {voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4}/voluptuous_openapi.egg-info/zip-safe +0 -0
|
@@ -91,6 +91,37 @@ def test_dict():
|
|
|
91
91
|
)
|
|
92
92
|
)
|
|
93
93
|
|
|
94
|
+
assert {"type": "object", "additionalProperties": True} == convert(vol.Schema(dict))
|
|
95
|
+
|
|
96
|
+
assert {"type": "object", "additionalProperties": True} == convert(
|
|
97
|
+
vol.Schema(dict[str, Any])
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
assert {"type": "object", "additionalProperties": {"type": "integer"}} == convert(
|
|
101
|
+
vol.Schema({str: int})
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
assert {
|
|
105
|
+
"type": "object",
|
|
106
|
+
"properties": {"x": {"type": "integer"}},
|
|
107
|
+
"required": [],
|
|
108
|
+
"additionalProperties": {"type": "string"},
|
|
109
|
+
} == convert(vol.Schema({"x": int, str: str}))
|
|
110
|
+
|
|
111
|
+
assert {"type": "object", "properties": {}, "required": []} == convert(
|
|
112
|
+
vol.Schema({})
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_tuple():
|
|
117
|
+
assert {"type": "array", "items": {"type": "string"}} == convert(vol.Schema(tuple))
|
|
118
|
+
assert {"type": "array", "items": {"type": "string"}} == convert(
|
|
119
|
+
vol.Schema(tuple[Any])
|
|
120
|
+
)
|
|
121
|
+
assert {"type": "array", "items": {"type": "integer"}} == convert(
|
|
122
|
+
vol.Schema(tuple[int])
|
|
123
|
+
)
|
|
124
|
+
|
|
94
125
|
|
|
95
126
|
def test_marker_description():
|
|
96
127
|
assert {
|
|
@@ -211,6 +242,14 @@ def test_list():
|
|
|
211
242
|
|
|
212
243
|
assert {"type": "array", "items": {"type": "string"}} == convert(vol.Schema(list))
|
|
213
244
|
|
|
245
|
+
assert {"type": "array", "items": {"type": "string"}} == convert(
|
|
246
|
+
vol.Schema(list[Any])
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
assert {"type": "array", "items": {"type": "integer"}} == convert(
|
|
250
|
+
vol.Schema(list[int])
|
|
251
|
+
)
|
|
252
|
+
|
|
214
253
|
|
|
215
254
|
def test_any_of():
|
|
216
255
|
assert {"anyOf": [{"type": "number"}, {"type": "integer"}]} == convert(
|
|
@@ -230,15 +269,22 @@ def test_key_any():
|
|
|
230
269
|
"properties": {
|
|
231
270
|
"name": {
|
|
232
271
|
"type": "string",
|
|
233
|
-
"description": "At least one of ('name', 'area') must be provided",
|
|
234
272
|
},
|
|
235
273
|
"area": {
|
|
236
274
|
"type": "string",
|
|
237
|
-
"description": "
|
|
275
|
+
"description": "The ID or the area",
|
|
238
276
|
},
|
|
239
277
|
},
|
|
240
278
|
"required": [],
|
|
241
|
-
} == convert(
|
|
279
|
+
} == convert(
|
|
280
|
+
vol.Schema(
|
|
281
|
+
{
|
|
282
|
+
vol.Any(
|
|
283
|
+
"name", vol.Optional("area", description="The ID or the area")
|
|
284
|
+
): str
|
|
285
|
+
}
|
|
286
|
+
)
|
|
287
|
+
)
|
|
242
288
|
|
|
243
289
|
|
|
244
290
|
def test_function():
|
|
@@ -53,22 +53,6 @@ def convert(schema: Any, *, custom_serializer: Callable | None = None) -> dict:
|
|
|
53
53
|
properties = {}
|
|
54
54
|
required = []
|
|
55
55
|
|
|
56
|
-
# Unfold vol.Any in keys
|
|
57
|
-
if vol.Any in [type(k) for k in schema.keys()]:
|
|
58
|
-
pschema = {}
|
|
59
|
-
for key, value in schema.items():
|
|
60
|
-
if isinstance(key, vol.Any):
|
|
61
|
-
description = key.msg
|
|
62
|
-
if not description:
|
|
63
|
-
description = (
|
|
64
|
-
f"At least one of {key.validators} must be provided"
|
|
65
|
-
)
|
|
66
|
-
for val in key.validators:
|
|
67
|
-
pschema[vol.Optional(val, description=description)] = value
|
|
68
|
-
else:
|
|
69
|
-
pschema[key] = value
|
|
70
|
-
schema = pschema
|
|
71
|
-
|
|
72
56
|
for key, value in schema.items():
|
|
73
57
|
description = None
|
|
74
58
|
if isinstance(key, vol.Marker):
|
|
@@ -86,13 +70,30 @@ def convert(schema: Any, *, custom_serializer: Callable | None = None) -> dict:
|
|
|
86
70
|
pval["default"] = key.default()
|
|
87
71
|
|
|
88
72
|
pval = ensure_default(pval)
|
|
89
|
-
|
|
90
|
-
|
|
73
|
+
|
|
74
|
+
if isinstance(pkey, type) and issubclass(pkey, str):
|
|
75
|
+
if additional_properties is None:
|
|
76
|
+
additional_properties = pval
|
|
77
|
+
elif isinstance(key, vol.Any):
|
|
78
|
+
for val in key.validators:
|
|
79
|
+
if isinstance(val, vol.Marker):
|
|
80
|
+
if val.description:
|
|
81
|
+
properties[str(val.schema)] = pval.copy()
|
|
82
|
+
properties[str(val.schema)]["description"] = val.description
|
|
83
|
+
else:
|
|
84
|
+
properties[str(val)] = pval
|
|
85
|
+
else:
|
|
86
|
+
properties[str(val)] = pval
|
|
87
|
+
else:
|
|
88
|
+
properties[str(pkey)] = pval
|
|
91
89
|
|
|
92
90
|
if isinstance(key, vol.Required):
|
|
93
|
-
required.append(pkey)
|
|
91
|
+
required.append(str(pkey))
|
|
94
92
|
|
|
95
|
-
val = {"type": "object"
|
|
93
|
+
val = {"type": "object"}
|
|
94
|
+
if properties or not additional_properties:
|
|
95
|
+
val["properties"] = properties
|
|
96
|
+
val["required"] = required
|
|
96
97
|
if additional_properties:
|
|
97
98
|
val["additionalProperties"] = additional_properties
|
|
98
99
|
return val
|
|
@@ -186,6 +187,13 @@ def convert(schema: Any, *, custom_serializer: Callable | None = None) -> dict:
|
|
|
186
187
|
if isinstance(schema, (str, int, float, bool)) or schema is None:
|
|
187
188
|
return {"enum": [schema]}
|
|
188
189
|
|
|
190
|
+
if (
|
|
191
|
+
get_origin(schema) is list
|
|
192
|
+
or get_origin(schema) is set
|
|
193
|
+
or get_origin(schema) is tuple
|
|
194
|
+
):
|
|
195
|
+
schema = [get_args(schema)[0]]
|
|
196
|
+
|
|
189
197
|
if isinstance(schema, Sequence):
|
|
190
198
|
if len(schema) == 1:
|
|
191
199
|
return {
|
|
@@ -205,13 +213,19 @@ def convert(schema: Any, *, custom_serializer: Callable | None = None) -> dict:
|
|
|
205
213
|
if schema in TYPES_MAP:
|
|
206
214
|
return {"type": TYPES_MAP[schema]}
|
|
207
215
|
|
|
208
|
-
if schema is
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
216
|
+
if get_origin(schema) is dict:
|
|
217
|
+
if get_args(schema)[1] is Any or isinstance(get_args(schema)[1], TypeVar):
|
|
218
|
+
schema = dict
|
|
219
|
+
else:
|
|
220
|
+
return convert({get_args(schema)[0]: get_args(schema)[1]})
|
|
213
221
|
|
|
214
222
|
if isinstance(schema, type):
|
|
223
|
+
if schema is dict:
|
|
224
|
+
return {"type": "object", "additionalProperties": True}
|
|
225
|
+
|
|
226
|
+
if schema is list or schema is set or schema is tuple:
|
|
227
|
+
return {"type": "array", "items": ensure_default({})}
|
|
228
|
+
|
|
215
229
|
if issubclass(schema, Enum):
|
|
216
230
|
return {"enum": [item.value for item in schema]}
|
|
217
231
|
elif schema is NoneType:
|
|
@@ -231,19 +245,6 @@ def convert(schema: Any, *, custom_serializer: Callable | None = None) -> dict:
|
|
|
231
245
|
schema = schema[0]
|
|
232
246
|
else:
|
|
233
247
|
return {}
|
|
234
|
-
if get_origin(schema) is dict:
|
|
235
|
-
schema = get_args(schema)[1]
|
|
236
|
-
if schema is Any or isinstance(schema, TypeVar):
|
|
237
|
-
schema = dict
|
|
238
|
-
else:
|
|
239
|
-
return {
|
|
240
|
-
"type": "object",
|
|
241
|
-
"additionalProperties": convert(
|
|
242
|
-
schema, custom_serializer=custom_serializer
|
|
243
|
-
),
|
|
244
|
-
}
|
|
245
|
-
if get_origin(schema) is list or get_origin(schema) is set:
|
|
246
|
-
schema = [get_args(schema)[0]]
|
|
247
248
|
|
|
248
249
|
return convert(schema, custom_serializer=custom_serializer)
|
|
249
250
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4}/voluptuous_openapi.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4}/voluptuous_openapi.egg-info/requires.txt
RENAMED
|
File without changes
|
{voluptuous_openapi-0.0.2 → voluptuous_openapi-0.0.4}/voluptuous_openapi.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|