Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
- id: pycln
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.15.13
rev: v0.16.0
hooks:
# Run the linter.
- id: ruff-check
Expand Down Expand Up @@ -62,7 +62,7 @@ repos:

- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.11.15
rev: 0.11.32
hooks:
# Update the uv lockfile
- id: uv-lock
Expand Down
3 changes: 1 addition & 2 deletions docs/source/_ext/aioai3.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from docutils import nodes
from sphinx.domains import Domain
from sphinx.roles import XRefRole

from docutils import nodes


def resolve_url(env, name):
resolve_target = getattr(env.config, "linkcode_resolve", None)
Expand Down
7 changes: 3 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import os
import datetime
import importlib
import inspect
from pathlib import Path
import os
import sys
import datetime

from pathlib import Path

sys.path.append(str(p := (Path(".").absolute() / "_ext")))
assert p.exists(), f"{p} {os.getcwd()}"
Expand Down
31 changes: 15 additions & 16 deletions src/aiopenapi3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
from .version import __version__
from .openapi import OpenAPI
from .loader import FileSystemLoader
from .errors import (
SpecError,
ReferenceResolutionError,
ContentTypeError,
HTTPError,
ResponseError,
HTTPStatusError,
ContentTypeError,
ReferenceResolutionError,
RequestError,
ResponseDecodingError,
ResponseError,
ResponseSchemaError,
RequestError,
SpecError,
)

from .loader import FileSystemLoader
from .openapi import OpenAPI
from .version import __version__

__all__ = [
"__version__",
"OpenAPI",
"ContentTypeError",
"FileSystemLoader",
"SpecError",
"ReferenceResolutionError",
"HTTPError",
"ResponseError",
"HTTPStatusError",
"ContentTypeError",
"OpenAPI",
"ReferenceResolutionError",
"RequestError",
"ResponseDecodingError",
"ResponseError",
"ResponseSchemaError",
"RequestError",
"SpecError",
"__version__",
]
1 change: 1 addition & 0 deletions src/aiopenapi3/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys

from .cli import main

if __name__ == "__main__":
Expand Down
16 changes: 4 additions & 12 deletions src/aiopenapi3/_types.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import re
from typing import TYPE_CHECKING, Union, TypeAlias, Optional, Literal
from collections.abc import Sequence
from typing import Literal, TypeAlias, Union

import yaml

from httpx._types import RequestContent, FileTypes, RequestFiles, AuthTypes # noqa
from httpx._types import AuthTypes, FileTypes, RequestContent, RequestFiles
from pydantic import BaseModel


from . import v20, v30, v31, v32

if TYPE_CHECKING:
pass


RequestFileParameter = tuple[str, FileTypes]
RequestFilesParameter = Sequence[RequestFileParameter]

JSON: TypeAlias = Optional[Union[dict[str, "JSON"], list["JSON"], str, int, float, bool]]
JSON: TypeAlias = dict[str, "JSON"] | list["JSON"] | str | int | float | bool | None
"""
Define a JSON type
https://github.com/python/typing/issues/182#issuecomment-1320974824
Expand All @@ -41,7 +35,7 @@
AsyncRequestType = Union[v20.AsyncRequest, v30.AsyncRequest]
MediaTypeType = Union[v30.MediaType, v31.MediaType]
ExpectedType = Union[v20.Response, MediaTypeType]
ResponseHeadersType = dict[str, Union[str, BaseModel, list[BaseModel]]]
ResponseHeadersType = dict[str, str | BaseModel | list[BaseModel]]
ResponseDataType = Union[BaseModel, bytes, str]
TagType = Union[v20.Tag, v30.Tag, v32.Tag]

Expand Down Expand Up @@ -72,13 +66,11 @@
"RequestParameters",
"ReferenceType",
"PrimitiveTypes",
#
"YAMLLoaderType",
# httpx forwards
"RequestContent",
"RequestFiles",
"AuthTypes",
#
"JSON",
"RequestFilesParameter",
"RequestFileParameter",
Expand Down
23 changes: 10 additions & 13 deletions src/aiopenapi3/base.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import typing
import warnings
from typing import Any, ForwardRef, Union, cast
from collections.abc import Sequence

import re
import builtins
import keyword
import re
import typing
import uuid

import warnings
from collections.abc import Sequence
from pathlib import Path
from typing import Any, ForwardRef, TypeGuard, Union, cast

from typing import TypeGuard

from pydantic import RootModel, BaseModel, TypeAdapter, Field, AnyUrl, model_validator, PrivateAttr, ConfigDict
from pydantic import AnyUrl, BaseModel, ConfigDict, Field, PrivateAttr, RootModel, TypeAdapter, model_validator

from .errors import OperationParameterValidationError, ReferenceResolutionError
from .json import JSONPointer, JSONReference
from .errors import ReferenceResolutionError, OperationParameterValidationError

if typing.TYPE_CHECKING:
from aiopenapi3 import OpenAPI
from ._types import SchemaType, JSON, PathItemType, ParameterType, ReferenceType, DiscriminatorType

from ._types import JSON, DiscriminatorType, ParameterType, PathItemType, ReferenceType, SchemaType

HTTP_METHODS = frozenset(["get", "delete", "head", "post", "put", "patch", "trace", "query"])

Expand Down Expand Up @@ -156,8 +153,8 @@ def replace(ivalue):
else:
if v._target is None:
continue
from .model import Model
from . import errors
from .model import Model

if "object" not in (t := sorted(Model.types(v._target))):
raise errors.SpecError(f"Discriminated Union on a schema with types {t}")
Expand Down
28 changes: 14 additions & 14 deletions src/aiopenapi3/cli.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import argparse
import cProfile
import datetime
import sys
import json
import itertools
import typing
from pstats import SortKey
import pstats
import io
import importlib.util
import cProfile
import tracemalloc
import io
import itertools
import json
import linecache
import logging
import pstats
import sys
import tracemalloc
import typing
from pstats import SortKey

import httpx2
import jmespath
import yaml
import yarl
import httpx2

import aiopenapi3.plugin

Expand All @@ -25,12 +25,12 @@

from pathlib import Path

from .openapi import OpenAPI

from .loader import ChainLoader, RedirectLoader, WebLoader
import aiopenapi3.loader
from aiopenapi3.v30.formdata import decode_content_type

from .loader import ChainLoader, RedirectLoader, WebLoader
from .log import init
from .openapi import OpenAPI

if typing.TYPE_CHECKING:
import aiopenapi3.request
Expand Down Expand Up @@ -236,7 +236,7 @@ def prepare_arg(value):
if auth:
api.authenticate(**auth)

req: "aiopenapi3.request.RequestBase"
req: aiopenapi3.request.RequestBase
if args.method:
req = api.createRequest((args.operationId, args.method))
else:
Expand Down
8 changes: 5 additions & 3 deletions src/aiopenapi3/debug.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from aiopenapi3.plugin import Document
import yaml
from pathlib import Path
import json
from pathlib import Path

import yaml

from aiopenapi3.plugin import Document


class DescriptionDocumentDumper(Document):
Expand Down
18 changes: 6 additions & 12 deletions src/aiopenapi3/errors.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import dataclasses
import typing
from typing import Optional
import dataclasses

import httpx2
import pydantic

if typing.TYPE_CHECKING:
from ._types import (
SchemaType,
RequestType,
ExpectedType,
HeaderType,
OperationType,
RequestData,
RequestParameters,
RequestType,
SchemaType,
ServerType,
HeaderType,
ExpectedType,
OperationType,
)


Expand Down Expand Up @@ -79,8 +79,6 @@ class ParameterFormatError(SpecError):
The specified parameter encoding is invalid for the parameter family
"""

pass


class HTTPError(ErrorBase):
pass
Expand Down Expand Up @@ -204,11 +202,7 @@ def __str__(self):
class HTTPClientError(HTTPStatusIndicatedError):
"""response code 4xx"""

pass


@dataclasses.dataclass(repr=False)
class HTTPServerError(HTTPStatusIndicatedError):
"""response code 5xx"""

pass
4 changes: 2 additions & 2 deletions src/aiopenapi3/extra/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .reduce import Cull, Reduce
from .cookies import Cookies
from .reduce import Cull, Reduce

__all__ = ["Cull", "Reduce", "Cookies"]
__all__ = ["Cookies", "Cull", "Reduce"]
2 changes: 1 addition & 1 deletion src/aiopenapi3/extra/cookies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Literal
import email.message
import http.cookiejar
import urllib.request
from typing import Literal

import aiopenapi3.plugin

Expand Down
6 changes: 3 additions & 3 deletions src/aiopenapi3/extra/reduce.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typing
from typing import Union
import logging
import re
import typing
from typing import Union

from ..plugin import Document, Init

Expand Down Expand Up @@ -35,7 +35,7 @@ def __init__(
super().__init__()

def _reduced_paths(self, ctx: "Document.Context") -> dict:
reduced: dict[str, dict[str, "PathItemType"]] = {}
reduced: dict[str, dict[str, PathItemType]] = {}
if "paths" not in ctx.document:
return reduced
keep_keys = {"summary", "description", "servers", "parameters"}
Expand Down
Loading
Loading