Exceptions

The following exceptions can be encountered during the configuration of the openapi_builder package:

MissingConverter

A converter is missing for the field or schema that needs to be serialized. You can either solve this error using DocumentationOptions.strict_mode, or by registering your custom converter. You can use the following snippet as an example:

from openapi_builder import DocumentationOptions, OpenApiDocumentation
from openapi_builder.converters.schema.base import SchemaConverter
from openapi_builder.specification import Schema


class YourFieldConverter(SchemaConverter):
    converts_class = YourFieldClass

    def convert(self, value) -> Schema:
        return Schema(type="string", format="email")


OpenApiDocumentation(
    ...,
    options=DocumentationOptions(
        schema_converter_classes=[YourFieldConverter],
    ),
)

MissingParameterConverter

A converter is missing for the parameter. This might be because you added a custom parameter validator using the following snippet:

app.url_map.converters["uid"] = validators.UUIDValidator

You can solve this error by registering your custom parameter converter. You can use the following snippet as an example:

from openapi_builder import DocumentationOptions, OpenApiDocumentation
from openapi_builder.converters.parameters.base import ParameterConverter
from openapi_builder.specification import Schema


class UUIDConverter(ParameterConverter):
    converts_class = validators.UUIDValidator

    @property
    def schema(self) -> Schema:
        return Schema(type="string", format="hex")


OpenApiDocumentation(
    ...,
    options=DocumentationOptions(
        schema_converter_classes=[YourFieldConverter],
    ),
)

MissingDefaultConverter

A converter is missing for a default type. This might be because you return a default that is not JSON serializable.

You can solve this error by registering your custom defaults converter. You can use the following snippet as an example:

import datetime

from openapi_builder import DocumentationOptions, OpenApiDocumentation
from openapi_builder.converters.defaults.base import DefaultsConverter
from openapi_builder.specification import Schema


class TimeDeltaConverter(DefaultsConverter):
    converts_class = datetime.timedelta

    def convert(self, value) -> Any:
        return value.isoformat()


OpenApiDocumentation(
    ...,
    options=DocumentationOptions(
        schema_converter_classes=[YourFieldConverter],
    ),
)

MissingConfigContext

A function is called that requires a proper value for the documentation variable. This variable is used by the OpenAPIBuilder. You can only encounter this exception when overriding the OpenAPIBuilder-class itself. Decorate your function according to the following snippet:

def process():
    config = Documentation(...)
    with builder.config_manager.use_documentation_context(config):
        ...