Skip to content

Commit

Permalink
Override put_mapping definition to make index name optional. (opensea…
Browse files Browse the repository at this point in the history
…rch-project#553)

Signed-off-by: dblock <[email protected]>
Signed-off-by: roma2023 <[email protected]>
  • Loading branch information
dblock authored and roma2023 committed Dec 28, 2023
1 parent d6e0b5f commit c14f8ac
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sphinx<7.3
sphinx_rtd_theme
jinja2
pytz
deepmerge

# No wheels for Python 3.10 yet!
numpy; python_version<"3.10"
Expand Down
2 changes: 1 addition & 1 deletion opensearchpy/_async/client/remote_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def restore(self, body, params=None, headers=None):
:arg cluster_manager_timeout: Operation timeout for connection
to cluster-manager node.
:arg wait_for_completion: Should this request wait until the
operation has completed before returning. (default: false)
operation has completed before returning. Default is false.
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
Expand Down
2 changes: 1 addition & 1 deletion opensearchpy/client/remote_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def restore(self, body, params=None, headers=None):
:arg cluster_manager_timeout: Operation timeout for connection
to cluster-manager node.
:arg wait_for_completion: Should this request wait until the
operation has completed before returning. (default: false)
operation has completed before returning. Default is false.
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
Expand Down
16 changes: 14 additions & 2 deletions utils/generate-api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# specific language governing permissions and limitations
# under the License.

import json
import os
import re
from functools import lru_cache
Expand All @@ -33,6 +34,7 @@
from pathlib import Path

import black
import deepmerge
import requests
import unasync
import urllib3
Expand Down Expand Up @@ -645,8 +647,7 @@ def read_modules():
if all_paths_have_deprecation and x_deprecation_message is not None:
api.update({"deprecation_message": x_deprecation_message})

if namespace == "indices" and name == "put_mapping":
api["url"]["paths"][0]["parts"]["index"].update({"required": False})
api = apply_patch(namespace, name, api)

if namespace not in modules:
modules[namespace] = Module(namespace)
Expand All @@ -657,6 +658,17 @@ def read_modules():
return modules


def apply_patch(namespace, name, api):
override_file_path = (
CODE_ROOT / "utils/templates/overrides" / namespace / f"{name}.json"
)
if os.path.exists(override_file_path):
with open(override_file_path) as f:
override_json = json.load(f)
api = deepmerge.always_merger.merge(api, override_json)
return api


def dump_modules(modules):
for mod in modules.values():
mod.dump()
Expand Down
20 changes: 20 additions & 0 deletions utils/templates/overrides/indices/put_mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"url": {
"paths": [
{
"path": "/{index}/_mapping",
"methods": [
"POST",
"PUT"
],
"parts": {
"index": {
"type": "string",
"description": "Comma-separated list of indices; use `_all` or empty string to perform the operation on all indices.",
"required": false
}
}
}
]
}
}

0 comments on commit c14f8ac

Please sign in to comment.