Skip to content

Commit

Permalink
Skip elements with titles.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Jul 18, 2024
1 parent 04b870d commit a7fd2a0
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions utils/generate_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from itertools import chain, groupby
from operator import itemgetter
from pathlib import Path
from typing import Any, Dict
from typing import Any, Dict, List

import black
import deepmerge
Expand Down Expand Up @@ -547,6 +547,24 @@ def to_python(self) -> Any:
)


def collect_titles(element: Any) -> List[str]:
"""
Recursively collect titles. This assumes that if any element has a title, use that for param.
See https://github.com/opensearch-project/opensearch-api-specification/pull/416.
"""
titles = []
if isinstance(element, dict):
for key in element:
if key == "title":
titles.append(element["title"])
else:
titles += collect_titles(element[key])
if isinstance(element, list):
for item in element:
titles += collect_titles(item)
return titles


def read_modules() -> Any:
"""
checks the opensearch-api spec at
Expand Down Expand Up @@ -584,9 +602,9 @@ def read_modules() -> Any:

# Iterate over the list of parameters and update them
for param_ref in endpoint["parameters"]:
param = data["components"]["parameters"][
param_ref["$ref"].split("/")[-1]
]
param_ref = param_ref["$ref"].split("/")[-1]
param = data["components"]["parameters"][param_ref]

if "schema" in param and "$ref" in param["schema"]:
schema_path_ref = param["schema"]["$ref"].split("/")[-1]
param["schema"] = data["components"]["schemas"][schema_path_ref]
Expand All @@ -597,8 +615,11 @@ def read_modules() -> Any:
param["schema"] = data["components"]["schemas"][
common_schema_path_ref
]
params.append(param)
else:

# Ignore anything with titles, currently only 1 case, see
# https://github.com/opensearch-project/opensearch-api-specification/pull/416
titles = collect_titles(param)
if len(titles) == 0:
params.append(param)

# Iterate over the list of updated parameters to separate "parts" from "params"
Expand Down

0 comments on commit a7fd2a0

Please sign in to comment.