voluptuous-openapi 0.0.6__tar.gz → 0.0.7__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.7/PKG-INFO +67 -0
- voluptuous_openapi-0.0.7/pyproject.toml +18 -0
- {voluptuous_openapi-0.0.6 → voluptuous_openapi-0.0.7}/tests/test_lib.py +27 -0
- {voluptuous_openapi-0.0.6 → voluptuous_openapi-0.0.7}/voluptuous_openapi/__init__.py +4 -1
- voluptuous_openapi-0.0.7/voluptuous_openapi.egg-info/PKG-INFO +67 -0
- {voluptuous_openapi-0.0.6 → voluptuous_openapi-0.0.7}/voluptuous_openapi.egg-info/SOURCES.txt +2 -4
- voluptuous_openapi-0.0.6/MANIFEST.in +0 -2
- voluptuous_openapi-0.0.6/PKG-INFO +0 -10
- voluptuous_openapi-0.0.6/setup.py +0 -14
- voluptuous_openapi-0.0.6/voluptuous_openapi.egg-info/PKG-INFO +0 -10
- voluptuous_openapi-0.0.6/voluptuous_openapi.egg-info/zip-safe +0 -1
- {voluptuous_openapi-0.0.6 → voluptuous_openapi-0.0.7}/LICENSE +0 -0
- {voluptuous_openapi-0.0.6 → voluptuous_openapi-0.0.7}/README.md +0 -0
- {voluptuous_openapi-0.0.6 → voluptuous_openapi-0.0.7}/setup.cfg +0 -0
- {voluptuous_openapi-0.0.6 → voluptuous_openapi-0.0.7}/tests/test_validation.py +0 -0
- {voluptuous_openapi-0.0.6 → voluptuous_openapi-0.0.7}/voluptuous_openapi.egg-info/dependency_links.txt +0 -0
- {voluptuous_openapi-0.0.6 → voluptuous_openapi-0.0.7}/voluptuous_openapi.egg-info/requires.txt +0 -0
- {voluptuous_openapi-0.0.6 → voluptuous_openapi-0.0.7}/voluptuous_openapi.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: voluptuous-openapi
|
|
3
|
+
Version: 0.0.7
|
|
4
|
+
Summary: Convert voluptuous schemas to OpenAPI Schema object
|
|
5
|
+
Author-email: Denis Shulyaka <Shulyaka@gmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Source code, https://github.com/home-assistant-libs/voluptuous-openapi
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: voluptuous
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# Voluptuous OpenAPI
|
|
15
|
+
|
|
16
|
+
Convert Voluptuous schemas to [OpenAPI Schema object](https://spec.openapis.org/oas/v3.0.3#schema-object).
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
schema = {}
|
|
20
|
+
schema[vol.Required('name')] = vol.All(str, vol.Length(min=5))
|
|
21
|
+
schema[vol.Required('age', description='Age in full years')] = vol.All(vol.Coerce(int), vol.Range(min=18))
|
|
22
|
+
schema[vol.Optional('hobby', default='not specified')] = str
|
|
23
|
+
schema = vol.Schema(schema)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
becomes
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"type": "object",
|
|
31
|
+
"properties": {
|
|
32
|
+
"name": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"minLength": 5,
|
|
35
|
+
},
|
|
36
|
+
"age": {
|
|
37
|
+
"type": "integer",
|
|
38
|
+
"minimum": 18,
|
|
39
|
+
"description": "Age in full years",
|
|
40
|
+
},
|
|
41
|
+
"hobby": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"default": "not specified",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
"required": ["name", "age"],
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
See the tests for more examples.
|
|
51
|
+
|
|
52
|
+
## Custom serializer
|
|
53
|
+
|
|
54
|
+
You can pass a custom serializer to be able to process custom validators. If the serializer returns `UNSUPPORTED`, it will return to normal processing. Example:
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
|
|
58
|
+
from voluptuous_openai import UNSUPPORTED, convert
|
|
59
|
+
|
|
60
|
+
def custom_convert(value):
|
|
61
|
+
if value is my_custom_validator:
|
|
62
|
+
return {'pattern': '^[a-zA-Z0-9]$'}
|
|
63
|
+
|
|
64
|
+
return UNSUPPORTED
|
|
65
|
+
|
|
66
|
+
convert(value, custom_serializer=custom_convert)
|
|
67
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
build-backend = "setuptools.build_meta"
|
|
3
|
+
requires = ["setuptools>=77.0"]
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "voluptuous-openapi"
|
|
7
|
+
version = "0.0.7"
|
|
8
|
+
license = "Apache-2.0"
|
|
9
|
+
description = "Convert voluptuous schemas to OpenAPI Schema object"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
authors = [{ name = "Denis Shulyaka", email = "Shulyaka@gmail.com" }]
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
dependencies = [
|
|
14
|
+
"voluptuous",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[project.urls]
|
|
18
|
+
"Source code" = "https://github.com/home-assistant-libs/voluptuous-openapi"
|
|
@@ -579,3 +579,30 @@ def test_mixed_type_list() -> None:
|
|
|
579
579
|
|
|
580
580
|
with pytest.raises(vol.Invalid):
|
|
581
581
|
validator(123)
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
@pytest.mark.parametrize(
|
|
585
|
+
"required",
|
|
586
|
+
[
|
|
587
|
+
(["query"]),
|
|
588
|
+
([]),
|
|
589
|
+
],
|
|
590
|
+
)
|
|
591
|
+
def test_convert_to_voluptuous_marker_description(required: list[str]):
|
|
592
|
+
schema = convert_to_voluptuous(
|
|
593
|
+
{
|
|
594
|
+
"type": "object",
|
|
595
|
+
"properties": {
|
|
596
|
+
"query": {"type": "string", "description": "The query to search for"},
|
|
597
|
+
"max_results": {
|
|
598
|
+
"type": "number",
|
|
599
|
+
"description": "The maximum number of results to return",
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
"required": required,
|
|
603
|
+
}
|
|
604
|
+
)
|
|
605
|
+
assert [(key, key.description) for key in schema.schema.keys()] == [
|
|
606
|
+
("query", "The query to search for"),
|
|
607
|
+
("max_results", "The maximum number of results to return"),
|
|
608
|
+
]
|
|
@@ -429,11 +429,14 @@ def convert_to_voluptuous(schema: dict) -> vol.Schema:
|
|
|
429
429
|
required_properties = set(schema.get("required", []))
|
|
430
430
|
for key, value in schema.get("properties", {}).items():
|
|
431
431
|
value_type = convert_to_voluptuous(value)
|
|
432
|
+
description: str | None = None
|
|
433
|
+
if isinstance(value, dict):
|
|
434
|
+
description = value.get("description")
|
|
432
435
|
if key in required_properties:
|
|
433
436
|
key_type = vol.Required
|
|
434
437
|
else:
|
|
435
438
|
key_type = vol.Optional
|
|
436
|
-
properties[key_type(key)] = value_type
|
|
439
|
+
properties[key_type(key, description=description)] = value_type
|
|
437
440
|
if schema.get("additionalProperties") is True:
|
|
438
441
|
return vol.Schema(properties, extra=vol.ALLOW_EXTRA)
|
|
439
442
|
return vol.Schema(properties)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: voluptuous-openapi
|
|
3
|
+
Version: 0.0.7
|
|
4
|
+
Summary: Convert voluptuous schemas to OpenAPI Schema object
|
|
5
|
+
Author-email: Denis Shulyaka <Shulyaka@gmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Source code, https://github.com/home-assistant-libs/voluptuous-openapi
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: voluptuous
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# Voluptuous OpenAPI
|
|
15
|
+
|
|
16
|
+
Convert Voluptuous schemas to [OpenAPI Schema object](https://spec.openapis.org/oas/v3.0.3#schema-object).
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
schema = {}
|
|
20
|
+
schema[vol.Required('name')] = vol.All(str, vol.Length(min=5))
|
|
21
|
+
schema[vol.Required('age', description='Age in full years')] = vol.All(vol.Coerce(int), vol.Range(min=18))
|
|
22
|
+
schema[vol.Optional('hobby', default='not specified')] = str
|
|
23
|
+
schema = vol.Schema(schema)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
becomes
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"type": "object",
|
|
31
|
+
"properties": {
|
|
32
|
+
"name": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"minLength": 5,
|
|
35
|
+
},
|
|
36
|
+
"age": {
|
|
37
|
+
"type": "integer",
|
|
38
|
+
"minimum": 18,
|
|
39
|
+
"description": "Age in full years",
|
|
40
|
+
},
|
|
41
|
+
"hobby": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"default": "not specified",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
"required": ["name", "age"],
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
See the tests for more examples.
|
|
51
|
+
|
|
52
|
+
## Custom serializer
|
|
53
|
+
|
|
54
|
+
You can pass a custom serializer to be able to process custom validators. If the serializer returns `UNSUPPORTED`, it will return to normal processing. Example:
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
|
|
58
|
+
from voluptuous_openai import UNSUPPORTED, convert
|
|
59
|
+
|
|
60
|
+
def custom_convert(value):
|
|
61
|
+
if value is my_custom_validator:
|
|
62
|
+
return {'pattern': '^[a-zA-Z0-9]$'}
|
|
63
|
+
|
|
64
|
+
return UNSUPPORTED
|
|
65
|
+
|
|
66
|
+
convert(value, custom_serializer=custom_convert)
|
|
67
|
+
```
|
{voluptuous_openapi-0.0.6 → voluptuous_openapi-0.0.7}/voluptuous_openapi.egg-info/SOURCES.txt
RENAMED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
LICENSE
|
|
2
|
-
MANIFEST.in
|
|
3
2
|
README.md
|
|
3
|
+
pyproject.toml
|
|
4
4
|
setup.cfg
|
|
5
|
-
setup.py
|
|
6
5
|
tests/test_lib.py
|
|
7
6
|
tests/test_validation.py
|
|
8
7
|
voluptuous_openapi/__init__.py
|
|
@@ -10,5 +9,4 @@ voluptuous_openapi.egg-info/PKG-INFO
|
|
|
10
9
|
voluptuous_openapi.egg-info/SOURCES.txt
|
|
11
10
|
voluptuous_openapi.egg-info/dependency_links.txt
|
|
12
11
|
voluptuous_openapi.egg-info/requires.txt
|
|
13
|
-
voluptuous_openapi.egg-info/top_level.txt
|
|
14
|
-
voluptuous_openapi.egg-info/zip-safe
|
|
12
|
+
voluptuous_openapi.egg-info/top_level.txt
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: voluptuous-openapi
|
|
3
|
-
Version: 0.0.6
|
|
4
|
-
Summary: Convert voluptuous schemas to OpenAPI Schema object
|
|
5
|
-
Home-page: https://github.com/home-assistant-libs/voluptuous-openapi
|
|
6
|
-
Author: Denis Shulyaka
|
|
7
|
-
Author-email: Shulyaka@gmail.com
|
|
8
|
-
License: Apache License 2.0
|
|
9
|
-
License-File: LICENSE
|
|
10
|
-
Requires-Dist: voluptuous
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
from setuptools import setup
|
|
2
|
-
|
|
3
|
-
setup(
|
|
4
|
-
name="voluptuous-openapi",
|
|
5
|
-
version="0.0.6",
|
|
6
|
-
description="Convert voluptuous schemas to OpenAPI Schema object",
|
|
7
|
-
url="https://github.com/home-assistant-libs/voluptuous-openapi",
|
|
8
|
-
author="Denis Shulyaka",
|
|
9
|
-
author_email="Shulyaka@gmail.com",
|
|
10
|
-
license="Apache License 2.0",
|
|
11
|
-
install_requires=["voluptuous"],
|
|
12
|
-
packages=["voluptuous_openapi"],
|
|
13
|
-
zip_safe=True,
|
|
14
|
-
)
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: voluptuous-openapi
|
|
3
|
-
Version: 0.0.6
|
|
4
|
-
Summary: Convert voluptuous schemas to OpenAPI Schema object
|
|
5
|
-
Home-page: https://github.com/home-assistant-libs/voluptuous-openapi
|
|
6
|
-
Author: Denis Shulyaka
|
|
7
|
-
Author-email: Shulyaka@gmail.com
|
|
8
|
-
License: Apache License 2.0
|
|
9
|
-
License-File: LICENSE
|
|
10
|
-
Requires-Dist: voluptuous
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{voluptuous_openapi-0.0.6 → voluptuous_openapi-0.0.7}/voluptuous_openapi.egg-info/requires.txt
RENAMED
|
File without changes
|
{voluptuous_openapi-0.0.6 → voluptuous_openapi-0.0.7}/voluptuous_openapi.egg-info/top_level.txt
RENAMED
|
File without changes
|