Skip to content

Commit 3b6c820

Browse files
v0.1.5 🏰
- Applies `isort` and enforces `isort` and `black` checks in CI pipeline - Adds support for examples defined using any class declaring a `dict` callable method, thus including `pydantic` models - Marks the package as `Production/Stable`
1 parent 94a79de commit 3b6c820

File tree

13 files changed

+232
-15
lines changed

13 files changed

+232
-15
lines changed

.github/workflows/build.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,23 @@ jobs:
4646
- name: Install dependencies
4747
run: |
4848
pip install -U --no-index --find-links=deps deps/*
49+
pip install black==20.8b1 isort==5.9.1
4950
5051
- name: Run tests
5152
run: |
5253
flake8 && pytest --doctest-modules --junitxml=junit/pytest-results-${{ matrix.python-version }}.xml --cov=$PROJECT_NAME --cov-report=xml tests/
5354
55+
- name: Run linters
56+
run: |
57+
echo "Running linters - if build fails here, please be patient!"
58+
59+
flake8 openapidocs
60+
flake8 tests
61+
isort --check-only openapidocs 2>&1
62+
isort --check-only tests 2>&1
63+
black --check openapidocs 2>&1
64+
black --check tests 2>&1
65+
5466
- name: Upload pytest test results
5567
uses: actions/upload-artifact@master
5668
with:

.isort.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[settings]
2+
profile = black
3+
multi_line_output = 3

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.1.5] - 2021-06-27 :european_castle:
9+
- Applies `isort` and enforces `isort` and `black` checks in CI pipeline
10+
- Adds support for examples defined using any class declaring a `dict` callable
11+
method, thus including `pydantic` models
12+
- Marks the package as `Production/Stable`
13+
814
## [0.1.4] - 2021-06-19 :droplet:
915
- Restores support for enums on examples `@dataclasses`, after the fix
1016
implemented in `0.1.3`

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,10 @@ test-cov-unit:
3939

4040
test-cov:
4141
pytest --cov-report html --cov=openapidocs
42+
43+
44+
format:
45+
isort openapidocs
46+
isort tests
47+
black openapidocs
48+
black tests

openapidocs/common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ def regular_dict_factory(items: List[Tuple[Any, Any]]) -> Any:
100100
# bypassing "asdict" on child properties when they implement a `to_obj`
101101
# method: some entities require a specific shape when represented
102102
def _asdict_inner(obj, dict_factory):
103+
if hasattr(obj, "dict") and callable(obj.dict):
104+
return obj.dict()
103105
if hasattr(obj, "to_obj"):
104106
return obj.to_obj()
105107
if isinstance(obj, OpenAPIElement):
@@ -122,6 +124,8 @@ def _asdict_inner(obj, dict_factory):
122124

123125

124126
def normalize_dict(obj):
127+
if hasattr(obj, "dict") and callable(obj.dict):
128+
return obj.dict()
125129
if hasattr(obj, "to_obj"):
126130
return obj.to_obj()
127131
if isinstance(obj, OpenAPIElement):

openapidocs/v2.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
https://swagger.io/specification/v2/
55
"""
66
from abc import ABC
7-
from enum import Enum
87
from dataclasses import dataclass
8+
from enum import Enum
9+
from typing import Any, Dict, List, Optional, Type, Union
10+
911
from openapidocs.common import OpenAPIRoot
10-
from typing import Any, List, Optional, Dict, Type, Union
12+
1113
from .common import OpenAPIElement
1214

1315

openapidocs/v3.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
https://swagger.io/specification/
55
"""
66
from abc import ABC
7-
from enum import Enum
87
from dataclasses import dataclass
8+
from enum import Enum
9+
from typing import Any, Dict, List, Optional, Union
10+
911
from openapidocs.common import OpenAPIRoot, normalize_dict
10-
from typing import Any, List, Optional, Dict, Union
12+
1113
from .common import OpenAPIElement
1214

1315

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ toml==0.10.1
2020
typed-ast==1.4.1
2121
typing-extensions==3.7.4.3
2222
dataclasses==0.7;python_version<'3.7'
23+
pydantic==1.8.2

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ def readme():
88

99
setup(
1010
name="essentials-openapi",
11-
version="0.1.4",
11+
version="0.1.5",
1212
description="Classes to generate OpenAPI Documentation v3 and v2, in JSON and YAML",
1313
long_description=readme(),
1414
long_description_content_type="text/markdown",
1515
classifiers=[
16-
"Development Status :: 4 - Beta",
16+
"Development Status :: 5 - Production/Stable",
1717
"License :: OSI Approved :: MIT License",
1818
"Programming Language :: Python :: 3",
1919
"Programming Language :: Python :: 3.6",

tests/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from typing import Any
3+
34
from openapidocs.common import Format
45

56

0 commit comments

Comments
 (0)