File: factories.py

package info (click to toggle)
python-openapi-core 0.19.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,008 kB
  • sloc: python: 18,868; makefile: 47
file content (30 lines) | stat: -rw-r--r-- 879 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from typing import Optional

from jsonschema_path import SchemaPath

from openapi_core.deserializing.styles.datatypes import StyleDeserializersDict
from openapi_core.deserializing.styles.deserializers import StyleDeserializer


class StyleDeserializersFactory:
    def __init__(
        self,
        style_deserializers: Optional[StyleDeserializersDict] = None,
    ):
        if style_deserializers is None:
            style_deserializers = {}
        self.style_deserializers = style_deserializers

    def create(
        self,
        style: str,
        explode: bool,
        schema: SchemaPath,
        name: str,
    ) -> StyleDeserializer:
        schema_type = schema.getkey("type", "")

        deserialize_callable = self.style_deserializers.get(style)
        return StyleDeserializer(
            style, explode, name, schema_type, deserialize_callable
        )