def test_dataclass_nested_objects(): expected_openapi_schema = { 'DataclassNestedObject': { 'title': 'DataclassNestedObject', 'type': 'object', 'required': ['str_field', 'nested_object'], 'properties': { 'str_field': { 'type': 'string' }, 'nested_object': { '$ref': '#/components/schemas/DataclassObject' } } }, 'DataclassObject': { 'title': 'DataclassObject', 'required': [ 'str_field', 'int_field', 'float_field', 'boolean_field', 'list_field', 'date_field', 'datetime_field' ], 'type': 'object', 'properties': { 'str_field': { 'type': 'string' }, 'int_field': { 'type': 'integer' }, 'float_field': { 'type': 'number' }, 'boolean_field': { 'type': 'boolean' }, 'list_field': { 'type': 'array', 'items': {} }, 'date_field': { 'type': 'string', 'format': 'date' }, 'datetime_field': { 'type': 'string', 'format': 'date-time' }, } } } assert expected_openapi_schema == get_openapi_schema(DataclassNestedObject, reference=False)
def test_marshmallow_schema(): expected_openapi_schema = { 'Marshmallow': { 'title': 'Marshmallow', 'type': 'object', 'required': ['str_field'], 'properties': { 'str_field': { 'type': 'string' }, 'int_field': { 'type': 'integer' }, 'float_field': { 'type': 'number' }, 'boolean_field': { 'type': 'boolean' }, 'list_field': { 'type': 'array', 'items': { 'type': 'string' } }, 'date_field': { 'type': 'string', 'format': 'date' }, 'datetime_field': { 'type': 'string', 'format': 'date-time' }, } } } assert expected_openapi_schema == get_openapi_schema(MarshmallowSchema, reference=False)
def test_openapi_schema(data_type, openapi_schema): assert openapi_schema == get_openapi_schema(data_type)