Skip to main content

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_openapi 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)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

voluptuous_openapi-0.4.1.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

voluptuous_openapi-0.4.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file voluptuous_openapi-0.4.1.tar.gz.

File metadata

  • Download URL: voluptuous_openapi-0.4.1.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for voluptuous_openapi-0.4.1.tar.gz
Algorithm Hash digest
SHA256 745d0d60940a851d9a90c87eebf659c57072c9ef305c0f6f04f4fd7c063dc0ac
MD5 713c365f00cd31e8746440de2fccc77e
BLAKE2b-256 60a5517c143607fd82cfc8842fcdccf5cf2c07cdd96528c936bde196e05dece3

See more details on using hashes here.

File details

Details for the file voluptuous_openapi-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for voluptuous_openapi-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b30abc527c622cd62dba1269a05099e6b6170678c2838908d347fa85ab0cdb44
MD5 97f223f33c1e793d8ebfaaf92a8ed321
BLAKE2b-256 bcbb64db054ad3852e3b63841a570942d3ce29e6b44979d5ac4be806973a2338

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page