Skip to content

Commit 189a921

Browse files
committed
fix #42: add path parameters to operation parameters
1 parent 397efd8 commit 189a921

3 files changed

Lines changed: 23 additions & 15 deletions

File tree

src/openapi_parser/builders/path.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def _build_path(self, url: str, data: dict) -> Path:
4242
if method.value in data
4343
]
4444

45+
if attrs.get("parameters"):
46+
for operation in attrs["operations"]:
47+
operation.parameters += attrs["parameters"]
48+
4549
attrs['extensions'] = extract_extension_attributes(data)
4650

4751
if attrs['extensions']:

tests/openapi_fixture.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,21 @@ def create_specification() -> Specification:
276276
{"Basic": []}
277277
]
278278

279+
uuid_parameters = [
280+
Parameter(
281+
name="uuid",
282+
location=ParameterLocation.PATH,
283+
description="User unique id",
284+
required=True,
285+
explode=False,
286+
style=PathParameterStyle.SIMPLE,
287+
schema=String(
288+
type=DataType.STRING,
289+
format=StringFormat.UUID,
290+
),
291+
),
292+
]
293+
279294
path_list: list[Path] = [
280295
Path(
281296
url="/users",
@@ -356,27 +371,15 @@ def create_specification() -> Specification:
356371
),
357372
Path(
358373
url="/users/{uuid}",
359-
parameters=[
360-
Parameter(
361-
name="uuid",
362-
location=ParameterLocation.PATH,
363-
description="User unique id",
364-
required=True,
365-
explode=False,
366-
style=PathParameterStyle.SIMPLE,
367-
schema=String(
368-
type=DataType.STRING,
369-
format=StringFormat.UUID,
370-
),
371-
),
372-
],
374+
parameters=uuid_parameters,
373375
operations=[
374376
Operation(
375377
method=OperationMethod.GET,
376378
summary="Get user model",
377379
description="Method to get user details",
378380
operation_id="GetUser",
379381
tags=["Users"],
382+
parameters=uuid_parameters,
380383
responses=[
381384
Response(
382385
code=200,
@@ -407,6 +410,7 @@ def create_specification() -> Specification:
407410
summary="Update existed user model",
408411
operation_id="UpdateUser",
409412
tags=["Users"],
413+
parameters=uuid_parameters,
410414
responses=[
411415
Response(code=None, description="Empty successful response", is_default=True),
412416
Response(code=200, description="Empty successful response", is_default=False),

tests/test_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ def swagger_specification():
1313
def test_run_parser(swagger_specification: Specification):
1414
actual_specification = parse('tests/data/swagger.yml')
1515

16-
assert swagger_specification == actual_specification
16+
assert actual_specification == swagger_specification

0 commit comments

Comments
 (0)