Skip to content

Commit 5b6e4f5

Browse files
authored
proto convertion support nullvalue (opensearch-project#189)
Add NULLVALUE template reformat Signed-off-by: xil <fridalu66@gmail.com>
1 parent 7cc2a7c commit 5b6e4f5

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
55
## [Unreleased]
66
### Added
77
- Publish opensearch-protos python package to PyPi. ([#183](https://github.com/opensearch-project/opensearch-protobufs/pull/183))
8+
- Proto Convertion tooling support null value ([#189](https://github.com/opensearch-project/opensearch-protobufs/pull/189))
89

910
### Changed
1011
- update `score` protobuf type ([#179](https://github.com/opensearch-project/opensearch-protobufs/pull/179))

tools/proto-convert/src/SchemaModifier.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ export class SchemaModifier {
2020
onSchemaProperty: (schema) => {
2121
this.deduplicateEnumValue(schema)
2222
this.handleAdditionalPropertiesUndefined(schema)
23+
this.convertNullTypeToNullValue(schema)
2324
this.collapseOrMergeOneOfArray(schema)
2425
},
2526
onSchema: (schema, schemaName) => {
2627
if (!schema || isReferenceObject(schema)) return;
2728
this.deduplicateEnumValue(schema)
2829
this.handleAdditionalPropertiesUndefined(schema)
30+
this.convertNullTypeToNullValue(schema)
2931
this.handleOneOfConst(schema, schemaName)
3032
this.collapseOrMergeOneOfArray(schema)
3133
this.collapseOneOfObjectPropContainsTitleSchema(schema)
@@ -333,4 +335,11 @@ export class SchemaModifier {
333335

334336
schema.enum = Array.from(enumSet)
335337
}
338+
339+
// Converts type: "null" to type: NullValue for protobuf compatibility
340+
convertNullTypeToNullValue(schema: OpenAPIV3.SchemaObject): void {
341+
if ((schema.type as any) === 'null') {
342+
(schema as any).type = 'NullValue';
343+
}
344+
}
336345
}

tools/proto-convert/src/config/protobuf-schema-template/custom_message.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ message GeneralNumber {
3030
double double_value = 4;
3131
}
3232
}
33+
34+
enum NullValue {
35+
NULL_VALUE_UNSPECIFIED = 0;
36+
NULL_VALUE_NULL = 1;
37+
}

0 commit comments

Comments
 (0)