feat: add support for operationId in docstring; feat: v1.120.6
This commit is contained in:
parent
83739c7c8e
commit
ba0530d6b1
@ -120,6 +120,19 @@ def tags(docstring: str) -> List[str]:
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def operation_id(docstring: str) -> str | None:
|
||||||
|
"""
|
||||||
|
Extract the "OperationId:" block of the docstring.
|
||||||
|
"""
|
||||||
|
iterator = LinesIterator(docstring)
|
||||||
|
for line in iterator:
|
||||||
|
if re.fullmatch("operation_?id\\s*:.*", line, re.IGNORECASE):
|
||||||
|
iterator.rewind()
|
||||||
|
return line.split(":")[1].strip(' ')
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def operation(docstring: str) -> str:
|
def operation(docstring: str) -> str:
|
||||||
"""
|
"""
|
||||||
Extract all docstring except the "Status Code:" block.
|
Extract all docstring except the "Status Code:" block.
|
||||||
@ -127,7 +140,7 @@ def operation(docstring: str) -> str:
|
|||||||
lines = LinesIterator(docstring)
|
lines = LinesIterator(docstring)
|
||||||
ret = []
|
ret = []
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if re.fullmatch("status\\s+codes?\\s*:|tags\\s*:.*", line, re.IGNORECASE):
|
if re.fullmatch("status\\s+codes?\\s*:|tags\\s*:.*|operation_?id\\s*:.*", line, re.IGNORECASE):
|
||||||
lines.rewind()
|
lines.rewind()
|
||||||
for _ in _i_extract_block(lines):
|
for _ in _i_extract_block(lines):
|
||||||
pass
|
pass
|
||||||
|
@ -207,6 +207,17 @@ class OperationObject:
|
|||||||
else:
|
else:
|
||||||
self._spec.pop("tags", None)
|
self._spec.pop("tags", None)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def operation_id(self) -> str | None:
|
||||||
|
return self._spec.get("operationId", None)
|
||||||
|
|
||||||
|
@operation_id.setter
|
||||||
|
def operation_id(self, operation_id: str | None) -> None:
|
||||||
|
if operation_id:
|
||||||
|
self._spec["operationId"] = operation_id
|
||||||
|
else:
|
||||||
|
self._spec.pop("operationId", None)
|
||||||
|
|
||||||
|
|
||||||
class PathItem:
|
class PathItem:
|
||||||
def __init__(self, spec: dict):
|
def __init__(self, spec: dict):
|
||||||
|
@ -87,6 +87,7 @@ def _add_http_method_to_oas(
|
|||||||
if description:
|
if description:
|
||||||
oas_operation.description = docstring_parser.operation(description)
|
oas_operation.description = docstring_parser.operation(description)
|
||||||
oas_operation.tags = docstring_parser.tags(description)
|
oas_operation.tags = docstring_parser.tags(description)
|
||||||
|
oas_operation.operation_id = docstring_parser.operation_id(description)
|
||||||
status_code_descriptions = docstring_parser.status_code(description)
|
status_code_descriptions = docstring_parser.status_code(description)
|
||||||
else:
|
else:
|
||||||
status_code_descriptions = {}
|
status_code_descriptions = {}
|
||||||
|
@ -47,6 +47,7 @@ class PetCollectionView(PydanticView):
|
|||||||
Tags: pet
|
Tags: pet
|
||||||
Status Codes:
|
Status Codes:
|
||||||
200: Successful operation
|
200: Successful operation
|
||||||
|
OperationId: createPet
|
||||||
"""
|
"""
|
||||||
return web.json_response()
|
return web.json_response()
|
||||||
|
|
||||||
@ -147,6 +148,7 @@ async def test_generated_oas_should_have_pets_paths(generated_oas):
|
|||||||
async def test_pets_route_should_have_get_method(generated_oas):
|
async def test_pets_route_should_have_get_method(generated_oas):
|
||||||
assert generated_oas["paths"]["/pets"]["get"] == {
|
assert generated_oas["paths"]["/pets"]["get"] == {
|
||||||
"description": "Get a list of pets",
|
"description": "Get a list of pets",
|
||||||
|
"operationId": "createPet",
|
||||||
"tags": ["pet"],
|
"tags": ["pet"],
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user