Skip to content

Commit ae14e64

Browse files
committed
test
1 parent ce11fe4 commit ae14e64

3 files changed

Lines changed: 31 additions & 26 deletions

File tree

.github/workflows/convert-proto.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ jobs:
3131
npm install -g @bufbuild/buf
3232
buf --version
3333
34-
- name: Download Release Assets
35-
uses: robinraju/release-downloader@v1
36-
with:
37-
repository: 'opensearch-project/opensearch-api-specification'
38-
latest: true
39-
fileName: 'opensearch-openapi.yaml'
40-
tag: 'main-latest'
41-
preRelease: true
34+
# - name: Download Release Assets
35+
# uses: robinraju/release-downloader@v1
36+
# with:
37+
# repository: 'opensearch-project/opensearch-api-specification'
38+
# latest: true
39+
# fileName: 'opensearch-openapi.yaml'
40+
# tag: 'main-latest'
41+
# preRelease: true
4242

4343
- name: Get Latest Commit ID
4444
id: get_commit
@@ -124,9 +124,9 @@ jobs:
124124
# - name: Post Process Protobuf
125125
# run: npm run postprocessing
126126

127-
# - name: Reformat proto files
128-
# run: |
129-
# buf format -w protos/generated
127+
- name: Reformat proto files
128+
run: |
129+
buf format -w protos/generated
130130
131131
- name: Configure Git User
132132
run: |

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ Thumbs.db
7070
protos/generated/.openapi-generator/
7171
protos/generated/.openapi-generator-ignore
7272
/cloned-repo
73-
opensearch-openapi.yaml
73+
#opensearch-openapi.yaml

tools/proto-convert/src/SchemaModifier.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ export class SchemaModifier {
4343
this.handleAdditionalPropertiesUndefined(schema)
4444

4545
},
46-
onSchema: (schema) => {
46+
onSchema: (schema, schemaName) => {
4747
if (!schema || isReferenceObject(schema)) return;
4848
this.simplifySingleMapSchema(schema, visit)
4949
this.handleAdditionalPropertiesUndefined(schema)
50+
this.markOneOfExtensions(schema, schemaName);
5051
},
5152
});
5253
return this.root
@@ -479,7 +480,8 @@ export class SchemaModifier {
479480
/**
480481
* Marks schemas and properties with oneOf extensions.
481482
* Adds x-oneof to properties when schema has minProperties=1 and maxProperties=1.
482-
* Adds x-oneof-constraint to top-level schemas that contain such patterns.
483+
* Adds x-oneof-constraint to schemas that have the min/max pattern AND to parent schemas
484+
* that contain nested schemas with the pattern.
483485
**/
484486
markOneOfExtensions(schema: OpenAPIV3.SchemaObject, schemaName?: string): void {
485487
// Check if this schema or nested items have the oneOf pattern
@@ -490,21 +492,24 @@ export class SchemaModifier {
490492
return;
491493
}
492494

493-
// Add x-oneof to properties of this schema if it has the pattern
494-
if (hasDirectPattern && schema.properties) {
495-
for (const propName in schema.properties) {
496-
const prop = schema.properties[propName] as any;
497-
if (prop && typeof prop === 'object') {
498-
prop['x-oneof'] = true;
495+
// Only mark with x-oneof-constraint if the schema directly has the pattern
496+
// OR if it has nested patterns (parent schemas that contain oneOf)
497+
if (hasDirectPattern) {
498+
// Add x-oneof to properties of this schema if it has the direct pattern
499+
if (schema.properties) {
500+
for (const propName in schema.properties) {
501+
const prop = schema.properties[propName] as any;
502+
if (prop && typeof prop === 'object') {
503+
prop['x-oneof'] = true;
504+
}
499505
}
500506
}
501-
this.logger.info(`Added x-oneof to properties with minProperties=1 and maxProperties=1`);
502-
}
503-
504-
// Add x-oneof-constraint to top-level schemas (not nested in allOf/anyOf/oneOf)
505-
if (schemaName && !['allOf', 'anyOf', 'oneOf'].includes(schemaName)) {
506507
(schema as any)['x-oneof-constraint'] = true;
507-
this.logger.info(`Marked schema with x-oneof-constraint`);
508+
this.logger.info(`Added x-oneof to properties and marked schema with x-oneof-constraint`);
509+
} else if (hasNestedPattern) {
510+
// Mark parent schemas that contain nested oneOf patterns
511+
(schema as any)['x-oneof-constraint'] = true;
512+
this.logger.info(`Marked parent schema with x-oneof-constraint (contains nested oneOf pattern)`);
508513
}
509514
}
510515

0 commit comments

Comments
 (0)