Skip to content

Commit 5879e18

Browse files
committed
Any schema type
1 parent d4ada7b commit 5879e18

File tree

5 files changed

+85
-2
lines changed

5 files changed

+85
-2
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Schema(object):
2020
"""Represents an OpenAPI Schema."""
2121

2222
DEFAULT_CAST_CALLABLE_GETTER = {
23+
SchemaType.ANY: lambda x: x,
2324
SchemaType.INTEGER: int,
2425
SchemaType.NUMBER: float,
2526
SchemaType.BOOLEAN: forcebool,
@@ -30,7 +31,7 @@ def __init__(
3031
schema_format=None, required=None, default=None, nullable=False,
3132
enum=None, deprecated=False, all_of=None, one_of=None,
3233
additional_properties=None):
33-
self.type = schema_type and SchemaType(schema_type)
34+
self.type = SchemaType(schema_type)
3435
self.model = model
3536
self.properties = properties and dict(properties) or {}
3637
self.items = items

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ paths:
155155
$ref: "#/components/responses/ErrorResponse"
156156
components:
157157
schemas:
158+
Utctime:
159+
oneOf:
160+
- type: string
161+
enum: [always, now]
162+
- type: string
163+
format: date-time
158164
Address:
159165
type: object
160166
x-model: Address
@@ -189,6 +195,7 @@ components:
189195
type: integer
190196
format: int64
191197
PetCreate:
198+
type: object
192199
x-model: PetCreate
193200
allOf:
194201
- $ref: "#/components/schemas/PetCreatePartOne"
@@ -271,6 +278,8 @@ components:
271278
required:
272279
- name
273280
properties:
281+
created:
282+
$ref: "#/components/schemas/Utctime"
274283
name:
275284
type: string
276285
format: custom

tests/integration/test_petstore.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,3 +829,75 @@ def test_post_tags_additional_properties(
829829

830830
assert response_result.errors == []
831831
assert response_result.data == data_json
832+
833+
def test_post_tags_created_now(
834+
self, spec, response_validator):
835+
host_url = 'http://petstore.swagger.io/v1'
836+
path_pattern = '/v1/tags'
837+
pet_name = 'Dog'
838+
data_json = {
839+
'created': 'now',
840+
'name': pet_name,
841+
}
842+
data = json.dumps(data_json)
843+
844+
request = MockRequest(
845+
host_url, 'POST', '/tags',
846+
path_pattern=path_pattern, data=data,
847+
)
848+
849+
parameters = request.get_parameters(spec)
850+
body = request.get_body(spec)
851+
852+
assert parameters == {}
853+
assert body == data_json
854+
855+
data_json = {
856+
'code': 400,
857+
'message': 'Bad request',
858+
'rootCause': 'Tag already exist',
859+
'additionalinfo': 'Tag Dog already exist',
860+
}
861+
data = json.dumps(data_json)
862+
response = MockResponse(data, status_code=404)
863+
864+
response_result = response_validator.validate(request, response)
865+
866+
assert response_result.errors == []
867+
assert response_result.data == data_json
868+
869+
def test_post_tags_created_datetime(
870+
self, spec, response_validator):
871+
host_url = 'http://petstore.swagger.io/v1'
872+
path_pattern = '/v1/tags'
873+
pet_name = 'Dog'
874+
data_json = {
875+
'created': '2016-04-16T16:06:05Z',
876+
'name': pet_name,
877+
}
878+
data = json.dumps(data_json)
879+
880+
request = MockRequest(
881+
host_url, 'POST', '/tags',
882+
path_pattern=path_pattern, data=data,
883+
)
884+
885+
parameters = request.get_parameters(spec)
886+
body = request.get_body(spec)
887+
888+
assert parameters == {}
889+
assert body == data_json
890+
891+
data_json = {
892+
'code': 400,
893+
'message': 'Bad request',
894+
'rootCause': 'Tag already exist',
895+
'additionalinfo': 'Tag Dog already exist',
896+
}
897+
data = json.dumps(data_json)
898+
response = MockResponse(data, status_code=404)
899+
900+
response_result = response_validator.validate(request, response)
901+
902+
assert response_result.errors == []
903+
assert response_result.data == data_json

0 commit comments

Comments
 (0)