Skip to main content

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


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.3.0.tar.gz (17.5 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.3.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for voluptuous_openapi-0.3.0.tar.gz
Algorithm Hash digest
SHA256 1ecd2386e63b59b791e0f64715e317c7018a2e5598333138bd1f28adfd348d5c
MD5 0b508ba06a35782db2dc4da3e94860f3
BLAKE2b-256 ed5fe77f088f4eff2e0f572f651bb9c2259561ec32d0bff20f59dd107e392ad8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for voluptuous_openapi-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db35598e9fc711cbaf7d7732de160de3edf89cc7411b6febe5a132f1f54ea931
MD5 8f90e5c7a675d5dec986706caeceaabe
BLAKE2b-256 ad2d3a8728e638bac8fd5857bb7775e39a9a520ae90b1d6dffd8badfa9852ccc

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