Skip to content

Commit 7452acc

Browse files
author
Iurii Sevastianov
authored
Add more information about nested type to Page type title, for example Page[NestedType] -> PageOfNestedType (#221)
1 parent 7d58f12 commit 7452acc

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

CHANGELOG.md

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

7+
## [9.6.2] - 2022-07-08
8+
9+
winter_openapi: add more information about nested type to Page type title,
10+
for example Page[NestedType] -> PageOfNestedType
11+
712
## [9.6.1] - 2022-07-04
813

914
Return 400 Bad Request instead of 500 if UUID request parameter has a newline character in the end

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "winter"
3-
version = "9.6.1"
3+
version = "9.6.2"
44
homepage = "https://github.com/WinterFramework/winter"
55
description = "Web Framework inspired by Spring Framework"
66
authors = ["Alexander Egorov <[email protected]>"]

tests/winter_openapi/test_type_inspection.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class CustomPage(Page, Generic[CustomPageItem]):
102102
'nested_number': TypeInfo(openapi.TYPE_INTEGER),
103103
}),
104104
})),
105-
(Page[NestedDataclass], TypeInfo(openapi.TYPE_OBJECT, title='Page', properties={
105+
(Page[NestedDataclass], TypeInfo(openapi.TYPE_OBJECT, title='PageOfNestedDataclass', properties={
106106
'meta': TypeInfo(openapi.TYPE_OBJECT, title='PageMeta', properties={
107107
'total_count': TypeInfo(openapi.TYPE_INTEGER),
108108
'limit': TypeInfo(openapi.TYPE_INTEGER, nullable=True),
@@ -114,7 +114,7 @@ class CustomPage(Page, Generic[CustomPageItem]):
114114
'nested_number': TypeInfo(openapi.TYPE_INTEGER),
115115
})),
116116
})),
117-
(CustomPage[int], TypeInfo(openapi.TYPE_OBJECT, title='Page', properties={
117+
(CustomPage[int], TypeInfo(openapi.TYPE_OBJECT, title='PageOfInteger', properties={
118118
'meta': TypeInfo(openapi.TYPE_OBJECT, title='PageMeta', properties={
119119
'total_count': TypeInfo(openapi.TYPE_INTEGER),
120120
'limit': TypeInfo(openapi.TYPE_INTEGER, nullable=True),

winter_openapi/page_inspector.py

+20-14
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,24 @@ def inspect_page(hint_class) -> TypeInfo:
1212
args = getattr(hint_class, '__args__', None)
1313
child_class = args[0] if args else str
1414
extra_fields = set(dataclasses.fields(hint_class.__origin__)) - set(dataclasses.fields(Page))
15+
child_type_info = inspect_type(child_class)
1516

16-
return TypeInfo(openapi.TYPE_OBJECT, title='Page', properties={
17-
'meta': TypeInfo(openapi.TYPE_OBJECT, title='PageMeta', properties={
18-
'total_count': TypeInfo(openapi.TYPE_INTEGER),
19-
'limit': TypeInfo(openapi.TYPE_INTEGER, nullable=True),
20-
'offset': TypeInfo(openapi.TYPE_INTEGER, nullable=True),
21-
'previous': TypeInfo(openapi.TYPE_STRING, openapi.FORMAT_URI, nullable=True),
22-
'next': TypeInfo(openapi.TYPE_STRING, openapi.FORMAT_URI, nullable=True),
23-
**{
24-
extra_field.name: inspect_type(extra_field.type)
25-
for extra_field in extra_fields
26-
},
27-
}),
28-
'objects': inspect_type(List[child_class]),
29-
})
17+
return TypeInfo(
18+
openapi.TYPE_OBJECT,
19+
title=f'PageOf{child_type_info.title or child_type_info.type_.capitalize()}',
20+
properties={
21+
'meta': TypeInfo(
22+
openapi.TYPE_OBJECT,
23+
title='PageMeta',
24+
properties={
25+
'total_count': TypeInfo(openapi.TYPE_INTEGER),
26+
'limit': TypeInfo(openapi.TYPE_INTEGER, nullable=True),
27+
'offset': TypeInfo(openapi.TYPE_INTEGER, nullable=True),
28+
'previous': TypeInfo(openapi.TYPE_STRING, openapi.FORMAT_URI, nullable=True),
29+
'next': TypeInfo(openapi.TYPE_STRING, openapi.FORMAT_URI, nullable=True),
30+
**{extra_field.name: inspect_type(extra_field.type) for extra_field in extra_fields},
31+
},
32+
),
33+
'objects': inspect_type(List[child_class]),
34+
},
35+
)

0 commit comments

Comments
 (0)