Skip to content

Commit 05b8a30

Browse files
committed
Any schema type
1 parent 4731504 commit 05b8a30

File tree

5 files changed

+89
-5
lines changed

5 files changed

+89
-5
lines changed

openapi_core/schema/schemas/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
class SchemaType(Enum):
66

7+
ANY = None
78
INTEGER = 'integer'
89
NUMBER = 'number'
910
STRING = 'string'

openapi_core/schema/schemas/factories.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, dereferencer):
1616
def create(self, schema_spec):
1717
schema_deref = self.dereferencer.dereference(schema_spec)
1818

19-
schema_type = schema_deref.get('type', 'object')
19+
schema_type = schema_deref.get('type', None)
2020
schema_format = schema_deref.get('format')
2121
model = schema_deref.get('x-model', None)
2222
required = schema_deref.get('required', False)

openapi_core/schema/schemas/models.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Schema(object):
2626
"""Represents an OpenAPI Schema."""
2727

2828
DEFAULT_CAST_CALLABLE_GETTER = {
29+
SchemaType.ANY: lambda x: x,
2930
SchemaType.INTEGER: int,
3031
SchemaType.NUMBER: float,
3132
SchemaType.BOOLEAN: forcebool,
@@ -61,7 +62,7 @@ def __init__(
6162
schema_format=None, required=None, default=None, nullable=False,
6263
enum=None, deprecated=False, all_of=None, one_of=None,
6364
additional_properties=None):
64-
self.type = schema_type and SchemaType(schema_type)
65+
self.type = SchemaType(schema_type)
6566
self.model = model
6667
self.properties = properties and dict(properties) or {}
6768
self.items = items
@@ -137,9 +138,6 @@ def cast(self, value):
137138
raise InvalidSchemaValue("Null value for non-nullable schema")
138139
return self.default
139140

140-
if self.type is None:
141-
return value
142-
143141
cast_mapping = self.get_cast_mapping()
144142

145143
if self.type is not SchemaType.STRING and value == '':

tests/integration/data/v3.0/petstore.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ paths:
168168
$ref: "#/components/responses/ErrorResponse"
169169
components:
170170
schemas:
171+
Utctime:
172+
oneOf:
173+
- type: string
174+
enum: [always, now]
175+
- type: string
176+
format: date-time
171177
Address:
172178
type: object
173179
x-model: Address
@@ -202,6 +208,7 @@ components:
202208
type: integer
203209
format: int64
204210
PetCreate:
211+
type: object
205212
x-model: PetCreate
206213
allOf:
207214
- $ref: "#/components/schemas/PetCreatePartOne"
@@ -284,6 +291,8 @@ components:
284291
required:
285292
- name
286293
properties:
294+
created:
295+
$ref: "#/components/schemas/Utctime"
287296
name:
288297
type: string
289298
TagList:

tests/integration/test_petstore.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,3 +1032,79 @@ def test_post_tags_additional_properties(
10321032
assert response_result.data.message == message
10331033
assert response_result.data.rootCause == rootCause
10341034
assert response_result.data.additionalinfo == additionalinfo
1035+
1036+
def test_post_tags_created_now(
1037+
self, spec, response_validator):
1038+
host_url = 'http://petstore.swagger.io/v1'
1039+
path_pattern = '/v1/tags'
1040+
pet_name = 'Dog'
1041+
data_json = {
1042+
'created': 'now',
1043+
'name': pet_name,
1044+
}
1045+
data = json.dumps(data_json)
1046+
1047+
request = MockRequest(
1048+
host_url, 'POST', '/tags',
1049+
path_pattern=path_pattern, data=data,
1050+
)
1051+
1052+
parameters = request.get_parameters(spec)
1053+
body = request.get_body(spec)
1054+
1055+
assert parameters == {}
1056+
assert body == data_json
1057+
1058+
data_json = {
1059+
'code': 400,
1060+
'message': 'Bad request',
1061+
'rootCause': 'Tag already exist',
1062+
'additionalinfo': 'Tag Dog already exist',
1063+
}
1064+
data = json.dumps(data_json)
1065+
response = MockResponse(data, status_code=404)
1066+
1067+
response_result = response_validator.validate(request, response)
1068+
1069+
assert response_result.errors == []
1070+
assert response_result.data == data_json
1071+
1072+
def test_post_tags_created_datetime(
1073+
self, spec, response_validator):
1074+
host_url = 'http://petstore.swagger.io/v1'
1075+
path_pattern = '/v1/tags'
1076+
pet_name = 'Dog'
1077+
data_json = {
1078+
'created': '2016-04-16T16:06:05Z',
1079+
'name': pet_name,
1080+
}
1081+
data = json.dumps(data_json)
1082+
1083+
request = MockRequest(
1084+
host_url, 'POST', '/tags',
1085+
path_pattern=path_pattern, data=data,
1086+
)
1087+
1088+
parameters = request.get_parameters(spec)
1089+
body = request.get_body(spec)
1090+
1091+
assert parameters == {}
1092+
assert body == data_json
1093+
1094+
data_json = {
1095+
'code': 400,
1096+
'message': 'Bad request',
1097+
'rootCause': 'Tag already exist',
1098+
'additionalinfo': 'Tag Dog already exist',
1099+
}
1100+
data = json.dumps(data_json)
1101+
response = MockResponse(data, status_code=404)
1102+
1103+
response_result = response_validator.validate(request, response)
1104+
1105+
assert response_result.errors == []
1106+
assert isinstance(response_result.data, BaseModel)
1107+
assert response_result.data.code == code
1108+
assert response_result.data.message == message
1109+
assert response_result.data.rootCause == rootCause
1110+
assert response_result.data.additionalinfo == additionalinfo

0 commit comments

Comments
 (0)