Skip to content

Commit

Permalink
Add support for Python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoPrevato committed Nov 20, 2023
1 parent 6bbd8c5 commit 829c27f
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, "3.10", "3.11"]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v1
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
path: dist

- name: Use Python 3.11
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: '3.11'

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__
*.tar.gz
_test_files/
dist/
venv312/
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.9] - 2023-11-20
- Adds support for Python 3.12.
- Adds `MarkupSafe` among required dependencies (and not optional).
- Adds support for latest function `model_dump` in Pydantic 2 (for examples
defined using Pydantic models).
- Upgrades development dependencies.

## [1.0.8] - 2023-07-19 :cat:
- Fixes example generation breaks on explicitly enumerated array elements #31,
by @jjedele.
Expand Down
2 changes: 1 addition & 1 deletion openapidocs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "1.0.8"
__version__ = "1.0.9"
VERSION = __version__
8 changes: 6 additions & 2 deletions openapidocs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ def regular_dict_factory(items: List[Tuple[Any, Any]]) -> Any:
# bypassing "asdict" on child properties when they implement a `to_obj`
# method: some entities require a specific shape when represented
def _asdict_inner(obj, dict_factory):
if hasattr(obj, "dict") and callable(obj.dict):
return obj.dict()
if hasattr(obj, "to_obj"):
return obj.to_obj()
if isinstance(obj, OpenAPIElement):
Expand All @@ -111,6 +109,12 @@ def _asdict_inner(obj, dict_factory):
value = _asdict_inner(getattr(obj, f.name), dict_factory)
result.append((f.name, value))
return dict_factory(result)
if hasattr(obj, "model_dump") and callable(obj.model_dump):
# For Pydantic 2
return obj.model_dump()
if hasattr(obj, "dict") and callable(obj.dict):
# For Pydantic 1
return obj.dict()
if is_dataclass(obj):
return asdict(obj, dict_factory=regular_dict_factory)
elif isinstance(obj, (list, tuple)):
Expand Down
32 changes: 22 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dynamic = ["version"]
authors = [{ name = "Roberto Prevato", email = "[email protected]" }]
description = "Classes to generate OpenAPI Documentation v3 and v2, in JSON and YAML."
readme = "README.md"
requires-python = ">=3.7"
requires-python = ">=3.8"
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
Expand All @@ -17,17 +17,29 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Operating System :: OS Independent",
]
keywords = ["openapi", "docs", "swagger", "api", "documentation", "v3", "v2", "json", "yaml", "Markdown"]
keywords = [
"openapi",
"docs",
"swagger",
"api",
"documentation",
"v3",
"v2",
"json",
"yaml",
"Markdown",
]

dependencies = ["PyYAML>=6", "essentials>=1.1.5"]
dependencies = ["PyYAML>=6", "essentials>=1.1.5", "MarkupSafe~=2.1.2"]

[tool.hatch.version]
path = "openapidocs/__init__.py"

[project.optional-dependencies]
full = ["click~=8.1.3", "Jinja2~=3.1.2", "MarkupSafe==2.1.2", "rich~=12.6.0", "httpx<1"]
full = ["click~=8.1.3", "Jinja2~=3.1.2", "rich~=12.6.0", "httpx<1"]

[project.scripts]
openapidocs = "openapidocs.main:main"
Expand All @@ -42,12 +54,12 @@ exclude = ["tests"]
[tool.hatch.build]
only-packages = false
include = [
"LICENSE",
"README.md",
"CHANGELOG.md",
"openapidocs/**/*.py",
"openapidocs/**/*.html",
"openapidocs/**/*.md",
"LICENSE",
"README.md",
"CHANGELOG.md",
"openapidocs/**/*.py",
"openapidocs/**/*.html",
"openapidocs/**/*.md",
]

[project.urls]
Expand Down
72 changes: 32 additions & 40 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,47 +1,39 @@
anyio==3.6.2
attrs==22.1.0
black==22.10.0
build==0.10.0
certifi==2022.9.24
charset-normalizer==3.0.0
click==8.1.3
commonmark==0.9.1
coverage==6.5.0
annotated-types==0.6.0
anyio==4.0.0
black==23.11.0
blinker==1.7.0
certifi==2023.11.17
click==8.1.7
coverage==7.3.2
essentials==1.1.5
flake8==5.0.4
Flask==2.2.2
h11==0.12.0
httpcore==0.15.0
httpx==0.24.0
flake8==6.1.0
Flask==3.0.0
h11==0.14.0
httpcore==1.0.2
httpx==0.25.1
idna==3.4
iniconfig==1.1.1
isort==5.10.1
iniconfig==2.0.0
isort==5.12.0
itsdangerous==2.1.2
Jinja2==3.1.2
markdown-it-py==2.2.0
MarkupSafe==2.1.2
markdown-it-py==3.0.0
MarkupSafe==2.1.3
mccabe==0.7.0
mdurl==0.1.2
mypy-extensions==0.4.3
packaging==21.3
pathspec==0.10.1
platformdirs==2.5.2
pluggy==1.0.0
py==1.11.0
pycodestyle==2.9.1
pydantic==1.10.2
pyflakes==2.5.0
Pygments==2.13.0
pyparsing==3.0.9
pyproject_hooks==1.0.0
pytest==7.2.0
pytest-cov==4.0.0
PyYAML==6.0
regex==2022.10.31
rfc3986==1.5.0
rich==13.3.5
mypy-extensions==1.0.0
packaging==23.2
pathspec==0.11.2
platformdirs==4.0.0
pluggy==1.3.0
pycodestyle==2.11.1
pydantic==2.5.1
pydantic_core==2.14.3
pyflakes==3.1.0
Pygments==2.17.1
pytest==7.4.3
pytest-cov==4.1.0
PyYAML==6.0.1
rich==13.7.0
sniffio==1.3.0
toml==0.10.2
tomli==2.0.1
typing_extensions==4.4.0
Werkzeug==2.2.2
typing_extensions==4.8.0
Werkzeug==3.0.1
22 changes: 15 additions & 7 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,25 @@
import re
from typing import Any

import pkg_resources
import yaml

from openapidocs.common import Format

try:
from importlib.resources import files

def get_resource_file_path(file_name: str) -> str:
return str(files(__name__) / "res" / file_name)

except ImportError:
# Python 3.8
import pkg_resources # type: ignore

def get_resource_file_path(file_name: str) -> str:
return pkg_resources.resource_filename(
__name__, os.path.join(".", "res", file_name)
)


def debug() -> bool:
return bool(os.environ.get("DEBUG", "1"))
Expand All @@ -26,12 +40,6 @@ def debug_result(version: str, instance: Any, result: str, format: Format) -> No
debug_file.write(result)


def get_resource_file_path(file_name: str) -> str:
return pkg_resources.resource_filename(
__name__, os.path.join(".", "res", file_name)
)


def get_resource_file_content(file_name: str) -> str:
with open(
get_resource_file_path(file_name),
Expand Down

0 comments on commit 829c27f

Please sign in to comment.