Skip to content

Commit 531cf1f

Browse files
authored
Merge pull request #100 from lucy66hw/xil/fix-termslookup-oneof-compat
Xil/fix termslookup oneof compat
2 parents 7f5d894 + 49f9f5d commit 531cf1f

8 files changed

Lines changed: 381 additions & 67 deletions

File tree

.github/workflows/convert-proto.yml

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ name: Auto Proto Convert
33
on:
44
workflow_dispatch:
55
inputs:
6+
artifact_download_url:
7+
description: 'Download URL for the api-spec build artifact zip.'
8+
required: true
9+
type: string
10+
api_spec_commit:
11+
description: 'Optional api-spec commit SHA for PR metadata.'
12+
required: false
13+
type: string
14+
api_spec_run_id:
15+
description: 'Optional api-spec workflow run ID for PR metadata.'
16+
required: false
17+
type: string
618
opensearch_version:
719
description: 'OpenSearch version. Leave empty to fetch latest.'
820
required: false
@@ -32,32 +44,42 @@ jobs:
3244
distribution: temurin
3345
java-version: 17
3446

35-
- name: Download Release Assets
36-
uses: robinraju/release-downloader@28fc21f50d76778e7023361aa1f863e717d3d56f # v1
37-
with:
38-
repository: 'opensearch-project/opensearch-api-specification'
39-
latest: true
40-
fileName: 'opensearch-openapi.yaml'
41-
tag: 'main-latest'
42-
preRelease: true
43-
44-
- name: Get Latest Commit ID
45-
id: get_commit
46-
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6
47-
with:
48-
github-token: ${{ secrets.GITHUB_TOKEN }}
49-
script: |
50-
const owner = "opensearch-project";
51-
const repo = "opensearch-api-specification";
52-
const commits = await github.rest.repos.listCommits({
53-
owner,
54-
repo,
55-
sha: "main",
56-
per_page: 1
57-
});
58-
const latestCommit = commits.data[0].sha;
59-
core.setOutput("latest_commit", latestCommit);
60-
console.log("Latest commit: " + latestCommit);
47+
- name: Resolve provided artifact metadata
48+
id: api_spec_artifact
49+
env:
50+
ARTIFACT_DOWNLOAD_URL: ${{ inputs.artifact_download_url || github.event.client_payload.artifact_download_url || '' }}
51+
API_SPEC_COMMIT: ${{ inputs.api_spec_commit || github.event.client_payload.api_spec_commit || '' }}
52+
API_SPEC_RUN_ID: ${{ inputs.api_spec_run_id || github.event.client_payload.api_spec_run_id || '' }}
53+
run: |
54+
if [ -z "$ARTIFACT_DOWNLOAD_URL" ]; then
55+
echo "artifact_download_url is required for both workflow_dispatch and repository_dispatch."
56+
exit 1
57+
fi
58+
59+
echo "artifact_download_url=$ARTIFACT_DOWNLOAD_URL" >> "$GITHUB_OUTPUT"
60+
echo "source_commit=${API_SPEC_COMMIT:-unknown}" >> "$GITHUB_OUTPUT"
61+
echo "run_id=${API_SPEC_RUN_ID:-unknown}" >> "$GITHUB_OUTPUT"
62+
63+
- name: Download API spec build artifact
64+
env:
65+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
run: |
67+
curl -L \
68+
-H "Authorization: Bearer $GH_TOKEN" \
69+
-H "Accept: application/vnd.github+json" \
70+
-o api-spec-build.zip \
71+
"${{ steps.api_spec_artifact.outputs.artifact_download_url }}"
72+
73+
rm -rf api-spec-build
74+
unzip -q api-spec-build.zip -d api-spec-build
75+
76+
SPEC_PATH=$(find api-spec-build -name opensearch-openapi.yaml -print -quit)
77+
if [ -z "$SPEC_PATH" ]; then
78+
echo "Could not find opensearch-openapi.yaml in downloaded artifact"
79+
exit 1
80+
fi
81+
82+
cp "$SPEC_PATH" opensearch-openapi.yaml
6183
6284
- name: Get Latest OpenSearch Core Version
6385
id: get_opensearch_version
@@ -164,7 +186,7 @@ jobs:
164186
token: ${{ secrets.GITHUB_TOKEN }}
165187
branch: auto-pr-branch
166188
commit-message: "Protobuf schema change detected"
167-
title: "[Automated PR]: Update generated protobuf schema (OpenSearch: ${{ steps.get_opensearch_version.outputs.version }}, spec commit: ${{ steps.get_commit.outputs.latest_commit }})"
189+
title: "[Automated PR]: Update generated protobuf schema (OpenSearch: ${{ steps.get_opensearch_version.outputs.version }}, spec commit: ${{ steps.api_spec_artifact.outputs.source_commit }})"
168190
signoff: true
169191
base: main
170192
delete-branch: true
@@ -173,7 +195,8 @@ jobs:
173195
This pull request was automatically generated by GitHub Actions.
174196
175197
**OpenSearch Version**: ${{ steps.get_opensearch_version.outputs.version }}
176-
**API Spec Commit**: ${{ steps.get_commit.outputs.latest_commit }}
198+
**API Spec Commit**: ${{ steps.api_spec_artifact.outputs.source_commit }}
199+
**API Spec Build Run**: ${{ steps.api_spec_artifact.outputs.run_id }}
177200
178201
---
179202

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1010
- Add PIT RPCs to `SearchService` ([#469](https://github.com/opensearch-project/opensearch-protobufs/pull/469)).
1111

1212
### Changed
13+
- Improve protobuf compatibility handling for optional and `oneof` field migrations ([#479](https://github.com/opensearch-project/opensearch-protobufs/pull/479)).
1314

1415
### Removed
1516

tools/proto-convert/src/SchemaModifier.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,23 +749,38 @@ export class SchemaModifier {
749749
return;
750750
}
751751

752+
const existingProperties = schema.properties ? { ...schema.properties } : {};
753+
const existingRequired = Array.isArray(schema.required) ? [...schema.required] : undefined;
752754
const mergedProperties: any = {};
753755

754756
for (const item of schema.oneOf) {
755757
if (item && item.properties) {
756-
Object.assign(mergedProperties, item.properties);
758+
for (const [name, property] of Object.entries(item.properties)) {
759+
mergedProperties[name] = {
760+
...(property as Record<string, unknown>),
761+
'x-oneof-property': true
762+
};
763+
}
757764
}
758765
}
759766

760-
schema.properties = mergedProperties;
767+
schema.properties = {
768+
...existingProperties,
769+
...mergedProperties
770+
};
761771
schema.minProperties = 1;
762772
schema.maxProperties = 1;
773+
if (existingRequired) {
774+
schema.required = existingRequired;
775+
}
763776

764777
if ('unevaluatedProperties' in schema) {
765778
delete schema.unevaluatedProperties;
766779
}
767780
delete schema.oneOf;
768-
delete schema.required;
781+
if (!existingRequired) {
782+
delete schema.required;
783+
}
769784
}
770785

771786
/**
@@ -783,9 +798,12 @@ export class SchemaModifier {
783798

784799
if (hasDirectPattern) {
785800
if (schema.properties) {
801+
const hasPreMarkedProperties = Object.values(schema.properties).some(prop =>
802+
prop && typeof prop === 'object' && 'x-oneof-property' in (prop as Record<string, unknown>)
803+
);
786804
for (const propName in schema.properties) {
787805
const prop = schema.properties[propName] as any;
788-
if (prop && typeof prop === 'object') {
806+
if (prop && typeof prop === 'object' && (!hasPreMarkedProperties || prop['x-oneof-property'])) {
789807
prop['x-oneof-property'] = true;
790808
}
791809
}

0 commit comments

Comments
 (0)