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.0.tar.gz (20.3 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.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: voluptuous_openapi-0.4.0.tar.gz
  • Upload date:
  • Size: 20.3 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.0.tar.gz
Algorithm Hash digest
SHA256 9b86a5f9222e9f812decd6b18dd336238923c22c7991c1fcc7ec8085b00b1331
MD5 f7ed5c4f178f2181de545e5e173c02b3
BLAKE2b-256 70f3f3c240e5a2c0e478ce6bcb8d93ce0792af12edfd57a72970cc7c2f67d05e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for voluptuous_openapi-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6ffae7cc5da04e7671d18ef16bf636ef8ab22e8d107872cb78ad7d4758c1306
MD5 f764eebfd3080a1456979b640fd9bd82
BLAKE2b-256 446be350b318835c7c746f909522df4e252e08cc9d6c949fb4eb8502d26d8fa1

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