Skip to content

Commit 8f6eb6f

Browse files
luckyxilu66lucy66hw
authored andcommitted
Preprocessing - Add filter to not convert addtionalProperties with min/max = 1
Signed-off-by: xil <fridalu66@gmail.com>
1 parent dbd5534 commit 8f6eb6f

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
88
- Add Cardinality and Missing aggregations. ([#245](https://github.com/opensearch-project/opensearch-protobufs/pull/245))
99
- Add terms aggregation protos ([#268](https://github.com/opensearch-project/opensearch-protobufs/pull/268))
1010
- Preprocessing: Handle unnamed additionalProperties.([#272](https://github.com/opensearch-project/opensearch-protobufs/pull/272))
11+
- Preprocessing - Preprocessing - Add filter to not convert additionalProperties when only one key allowed ([#288](https://github.com/opensearch-project/opensearch-protobufs/pull/288))
1112

1213
### Changed
1314
- Update preprocessing for x-protobuf-excluded ([#266](https://github.com/opensearch-project/opensearch-protobufs/pull/266))

tools/proto-convert/src/SchemaModifier.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ export class SchemaModifier {
1919
traverse(this.root, {
2020
onSchemaProperty: (schema) => {
2121
this.deduplicateEnumValue(schema)
22-
this.convertAdditionalPropertiesToProperty(schema, true)
2322
this.handleAdditionalPropertiesUndefined(schema)
2423
this.convertNullTypeToNullValue(schema)
2524
this.collapseOrMergeOneOfArray(schema)
2625
},
2726
onSchema: (schema, schemaName) => {
2827
if (!schema || isReferenceObject(schema)) return;
2928
this.deduplicateEnumValue(schema)
30-
this.convertAdditionalPropertiesToProperty(schema, false)
29+
this.convertAdditionalPropertiesToProperty(schema)
3130
this.handleAdditionalPropertiesUndefined(schema)
3231
this.convertNullTypeToNullValue(schema)
3332
this.handleOneOfConst(schema, schemaName)
@@ -351,7 +350,6 @@ export class SchemaModifier {
351350
* Converts additionalProperties with a title into a named property.
352351
*
353352
* @param schema - The schema to process
354-
* @param isNestedProperty - If true, skip conversion (nested properties already have context)
355353
*
356354
* Example:
357355
* Input:
@@ -381,14 +379,14 @@ export class SchemaModifier {
381379
* minProperties: 2
382380
* }
383381
**/
384-
convertAdditionalPropertiesToProperty(schema: OpenAPIV3.SchemaObject, isNestedProperty: boolean = false): void {
382+
convertAdditionalPropertiesToProperty(schema: OpenAPIV3.SchemaObject): void {
385383
if (!schema.additionalProperties || typeof schema.additionalProperties !== 'object') {
386384
return;
387385
}
388386

389387
const additionalProps = schema.additionalProperties as any;
390388

391-
if (isNestedProperty) {
389+
if (schema.minProperties === 1 && schema.maxProperties === 1) {
392390
return;
393391
}
394392

0 commit comments

Comments
 (0)