Type Mapping

OpenAlchemy translates OpenAPI types to SQLalchemy types using the following mappings:

OpenAPI type

OpenAPI format

SQLAlchemy type

Python type

integer

undefined

Integer

int

int32

Integer

int

int64

BigInteger

int

number

undefined

Float

float

float

Float

float

string

undefined

String

str

password

String

str

byte

String

str

binary

LargeBinary

bytes

date

Date

datetime.date

date-time

DateTime

datetime.datetime

<other>

String

str

boolean

Boolean

bool

type as an array is supported, however, exactly one type (other than null) is required.

String

OpenAPI optionally allows the maxLength property for strings. This is translated to the length argument for the SQLAlchemy String, which is set to None if maxLength is undefined.

Password

The same maxLength information as for String also applies.

Note

The password format under the hood is the same as String. No special protection (such as encryption) is added.

Byte

This format is for base64 encoded binary data. The same maxLength information as for String also applies.

Binary

The same maxLength information as for String also applies. The codec is assumed to be utf-8.

DateTime

OpenAPI supports the inbuilt date-time format for a string. This is mapped to the DateTime SQLAlchemy type. Currently, time zones are not supported. Database best practice is to store everything in UTC. Applications, such as web front ends, should convert to UTC as early as possible and localize a date and time as late as possible.

JSON

SQLAlchemy supports generic data through the JSON type. OpenAlchemy supports this through adding the x-json extension property to any property of a model. This means that OpenAlchemy will ignore the true type of the property and instead create a JSON column. For example, the data property of the following Employee object is a generic JSON data store:

1
2
3
4
5
6
7
8
9
Employee:
   type: object
   x-tablename: employee
   properties:
     id:
       type: integer
     data:
       type: object
       x-json: True

Note

If you are using the SQLAlchemy ORM do not use a JSON property as the primary key. This is technically valid although the unique identification logic in SQLAlchemy does not support this.

See also

SQLAlchemy JSON

Documentation for the SQLAlchemy JSON type.