|
1 | | -from openapi_core.schema.schemas.enums import SchemaType |
2 | | - |
3 | 1 | from openapi_core.casting.schemas.casters import ( |
4 | 2 | PrimitiveCaster, DummyCaster, ArrayCaster |
5 | 3 | ) |
|
9 | 7 | class SchemaCastersFactory(object): |
10 | 8 |
|
11 | 9 | DUMMY_CASTERS = [ |
12 | | - SchemaType.STRING, SchemaType.OBJECT, SchemaType.ANY, |
| 10 | + 'string', 'object', 'any', |
13 | 11 | ] |
14 | 12 | PRIMITIVE_CASTERS = { |
15 | | - SchemaType.INTEGER: int, |
16 | | - SchemaType.NUMBER: float, |
17 | | - SchemaType.BOOLEAN: forcebool, |
| 13 | + 'integer': int, |
| 14 | + 'number': float, |
| 15 | + 'boolean': forcebool, |
18 | 16 | } |
19 | 17 | COMPLEX_CASTERS = { |
20 | | - SchemaType.ARRAY: ArrayCaster, |
| 18 | + 'array': ArrayCaster, |
21 | 19 | } |
22 | 20 |
|
23 | 21 | def create(self, schema): |
24 | | - if schema.type in self.DUMMY_CASTERS: |
| 22 | + schema_type = schema.getkey('type', 'any') |
| 23 | + if schema_type in self.DUMMY_CASTERS: |
25 | 24 | return DummyCaster() |
26 | | - elif schema.type in self.PRIMITIVE_CASTERS: |
27 | | - caster_callable = self.PRIMITIVE_CASTERS[schema.type] |
| 25 | + elif schema_type in self.PRIMITIVE_CASTERS: |
| 26 | + caster_callable = self.PRIMITIVE_CASTERS[schema_type] |
28 | 27 | return PrimitiveCaster(schema, caster_callable) |
29 | | - elif schema.type in self.COMPLEX_CASTERS: |
30 | | - caster_class = self.COMPLEX_CASTERS[schema.type] |
| 28 | + elif schema_type in self.COMPLEX_CASTERS: |
| 29 | + caster_class = self.COMPLEX_CASTERS[schema_type] |
31 | 30 | return caster_class(schema, self) |
0 commit comments