File: finders.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 (22 lines) | stat: -rw-r--r-- 713 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
from jsonschema_path import SchemaPath

from openapi_core.templating.responses.exceptions import ResponseNotFound


class ResponseFinder:
    def __init__(self, responses: SchemaPath):
        self.responses = responses

    def find(self, http_status: str = "default") -> SchemaPath:
        if http_status in self.responses:
            return self.responses / http_status

        # try range
        http_status_range = f"{http_status[0]}XX"
        if http_status_range in self.responses:
            return self.responses / http_status_range

        if "default" not in self.responses:
            raise ResponseNotFound(http_status, list(self.responses.keys()))

        return self.responses / "default"