Skip to content

Commit 4a6dda9

Browse files
authored
Proper check of Pydantic properties on OAS (#102)
* Proper check of Pydantic properties on OAS * Unit test * Bump version
1 parent 08c7e1b commit 4a6dda9

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

sanic_ext/extensions/openapi/types.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import uuid
33
from datetime import date, datetime, time
44
from enum import Enum
5-
from inspect import getmembers, isfunction
5+
from inspect import getmembers, isfunction, ismethod
66
from typing import (
77
Any,
88
Dict,
@@ -312,7 +312,7 @@ def _properties(value: object) -> Dict:
312312
fields = {
313313
x: val
314314
for x, v in getmembers(value, _is_property)
315-
if (val := _extract(v))
315+
if (val := _extract(v)) and x in value.__dict__
316316
}
317317
except AttributeError:
318318
fields = {}
@@ -333,4 +333,4 @@ def _extract(item):
333333

334334

335335
def _is_property(item):
336-
return not isfunction(item)
336+
return not isfunction(item) and not ismethod(item)

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = sanic-ext
3-
version = 22.6.0
3+
version = 22.6.1
44
url = http://github.com/sanic-org/sanic-ext/
55
license = MIT
66
author = Sanic Community

tests/extensions/openapi/test_schema.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,26 @@ class Foo:
1212
list1: List[int]
1313
list2: list[int]
1414

15-
def no_show(self) -> None:
16-
...
17-
1815
@property
1916
def show(self) -> bool:
2017
return True
2118

19+
def no_show_method(self) -> None:
20+
...
21+
22+
@classmethod
23+
def no_show_classmethod(self) -> None:
24+
...
25+
26+
@staticmethod
27+
def no_show_staticmethod() -> None:
28+
...
29+
2230
schema = Schema.make(Foo)
2331
serialized = schema.serialize()
24-
assert "no_show" not in serialized
32+
assert "no_show_method" not in serialized
33+
assert "no_show_classmethod" not in serialized
34+
assert "no_show_staticmethod" not in serialized
2535
assert serialized == {
2636
"type": "object",
2737
"properties": {

0 commit comments

Comments
 (0)