Convert voluptuous schemas to OpenAPI Schema object
Project description
Voluptuous OpenAPI
Convert Voluptuous schemas to OpenAPI Schema object.
schema = {}
schema[vol.Required('name')] = vol.All(str, vol.Length(min=5))
schema[vol.Required('age', description='Age in full years')] = vol.All(vol.Coerce(int), vol.Range(min=18))
schema[vol.Optional('hobby', default='not specified')] = str
schema = vol.Schema(schema)
becomes
{
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 5,
},
"age": {
"type": "integer",
"minimum": 18,
"description": "Age in full years",
},
"hobby": {
"type": "string",
"default": "not specified",
},
},
"required": ["name", "age"],
}
See the tests for more examples.
Custom serializer
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:
from voluptuous_openai import UNSUPPORTED, convert
def custom_convert(value):
if value is my_custom_validator:
return {'pattern': '^[a-zA-Z0-9]$'}
return UNSUPPORTED
convert(value, custom_serializer=custom_convert)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file voluptuous_openapi-0.1.0.tar.gz.
File metadata
- Download URL: voluptuous_openapi-0.1.0.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84bc44107c472ba8782f7a4cb342d19d155d5fe7f92367f092cd96cc850ff1b7
|
|
| MD5 |
d9643db5c2323717dfbda307de29895b
|
|
| BLAKE2b-256 |
ba20ed87b130ae62076b731521b3c4bc502e6ba8cc92def09954e4e755934804
|
File details
Details for the file voluptuous_openapi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: voluptuous_openapi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3aac740286d368c90a99e007d55ddca7fcddf790d218c60ee0eeec2fcd3db2b
|
|
| MD5 |
14638740d20ebdd6caee99579f1835ba
|
|
| BLAKE2b-256 |
683b9e689d9fc68f0032bf5b7cbf767fc8bd4771d75cddaf01267fcc05490061
|