Skip to content

Commit cfb69e3

Browse files
authored
Remove unused fields from openapi (#316)
1 parent 5f537b8 commit cfb69e3

File tree

6 files changed

+46
-6
lines changed

6 files changed

+46
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ 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+
## [26.0.1] - 2024-08-15
8+
- Remove unexpected openapi attributes from path and query parameters
9+
710
## [26.0.0] - 2024-08-12
811
- Do not ignore unexpected openapi attributes anymore
912

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "winter"
3-
version = "26.0.0"
3+
version = "26.0.1"
44
homepage = "https://github.com/WinterFramework/winter"
55
description = "Web Framework with focus on python typing, dataclasses and modular design"
66
authors = ["Alexander Egorov <[email protected]>"]

tests/winter_openapi/test_query_and_path_parameter_spec.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,47 @@ def simple_method(
115115
assert parameters == [expected_parameter]
116116

117117

118+
@pytest.mark.parametrize('type_hint, default_value, expected_parameter_properties', [
119+
(int, 3, {'schema': {'format': 'int32', 'type': 'integer'}}),
120+
(str, '12', {'schema': {'type': 'string'}}),
121+
(IntegerEnum, IntegerEnum.RED, {'schema': {'enum': [1, 2], 'format': 'int32', 'type': 'integer'}}),
122+
(IntegerValueEnum, IntegerValueEnum.RED, {'schema': {'enum': [1, 2], 'format': 'int32', 'type': 'integer'}}),
123+
(StringValueEnum, StringValueEnum.RED, {'schema': {'enum': ['red', 'green'], 'type': 'string'}}),
124+
(MixedValueEnum, MixedValueEnum.RED, {'schema': {'enum': [123, 'green'], 'type': 'string'}}),
125+
])
126+
def test_query_parameter_inspector_with_default_value(type_hint, default_value, expected_parameter_properties):
127+
class _TestAPI:
128+
@winter.route_get('/resource/{?query_param}')
129+
@winter.map_query_parameter('mapped_query_param', to='invalid_query_param')
130+
def simple_method(
131+
self,
132+
query_param: type_hint = default_value,
133+
): # pragma: no cover
134+
"""
135+
:param query_param: docstr
136+
"""
137+
pass
138+
139+
expected_parameter = {
140+
'name': 'query_param',
141+
'in': 'query',
142+
'required': False,
143+
'allowEmptyValue': False,
144+
'allowReserved': False,
145+
'deprecated': False,
146+
'explode': False,
147+
'description': 'docstr',
148+
**expected_parameter_properties,
149+
}
150+
route = get_route(_TestAPI.simple_method)
151+
# Act
152+
result = generate_openapi(title='title', version='1.0.0', description='Winter api description', routes=[route])
153+
154+
# Assert
155+
parameters = result["paths"]["/resource/"]["get"]["parameters"]
156+
assert parameters == [expected_parameter]
157+
158+
118159
@pytest.mark.parametrize('type_hint, expected_parameter_properties', param_with_diff_types)
119160
def test_path_parameter_different_types(type_hint, expected_parameter_properties):
120161
class _TestAPI:

winter/core/component_method_argument.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ class ComponentMethodArgument:
3131
def parameter(self) -> inspect.Parameter:
3232
return self.method.signature.parameters[self.name]
3333

34-
def get_default(self, default=inspect.Parameter.empty) -> Any:
34+
def get_default(self) -> Any:
3535
if self.parameter.default is not inspect.Parameter.empty:
3636
return self.parameter.default
3737
if is_optional(self.type_):
3838
return None
39-
if default is not inspect.Parameter.empty:
40-
return default
4139
raise ArgumentDoesNotHaveDefault(self)
4240

4341
@property

winter_openapi/inspectors/path_parameters_inspector.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def _convert_argument_to_openapi_parameter(
3333
description=argument.description,
3434
required=argument.required,
3535
param_in='path',
36-
default=argument.get_default(None),
3736
param_schema=schema,
3837
)
3938

winter_openapi/inspectors/query_parameters_inspector.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def _convert_argument_to_openapi_parameter(
5555
description=argument.description,
5656
required=argument.required,
5757
param_in='query',
58-
default=argument.get_default(None),
5958
param_schema=schema,
6059
explode=query_parameter.explode,
6160
)

0 commit comments

Comments
 (0)