Skip to content

Commit 8f45486

Browse files
authored
Change vendorExtension protobuf type handling to use protobuf type instead of openApi type (opensearch-project#413)
* Change vendorExtension protobuf type handling to use protobuf type instead of openApi type Signed-off-by: xil <fridalu66@gmail.com> * use x-protobuf-type Signed-off-by: xil <fridalu66@gmail.com> * codecov setup Signed-off-by: xil <fridalu66@gmail.com> --------- Signed-off-by: xil <fridalu66@gmail.com>
1 parent 065ad2b commit 8f45486

5 files changed

Lines changed: 71 additions & 269 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
77

88
### Changed
99
- Fix simplifySingleMapSchema to generate named wrapper schemas. ([#406](https://github.com/opensearch-project/opensearch-protobufs/pull/406))
10+
- Change vendorExtension protobuf type handling to use protobuf type instead of openApi type ([#409](https://github.com/opensearch-project/opensearch-protobufs/pull/409))
1011

1112
### Removed
1213

codecov.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
codecov:
2+
require_ci_to_pass: yes
3+
4+
coverage:
5+
status:
6+
project:
7+
default:
8+
target: 85% # Require 85% overall coverage
9+
threshold: 1% # Allow 1% decrease
10+
patch:
11+
default:
12+
target: 85% # Require 85% coverage on new code
13+
threshold: 1% # Allow 1% decrease on patches
14+
15+
comment:
16+
layout: "header, diff, flags, files"
17+
behavior: default
18+
require_changes: false
19+
require_base: false

tools/proto-convert/src/VendorExtensionProcessor.ts

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ export class VendorExtensionProcessor {
1313
private static readonly PROTOBUF_TYPE_EXTENSION = 'x-protobuf-type';
1414
private static readonly PROTOBUF_NAME_EXTENSION = 'x-protobuf-name';
1515

16-
private static readonly PROTOBUF_TYPE_MAPPING: Record<string, { type: string; format?: string }> = {
17-
'int32': { type: 'integer', format: 'int32' },
18-
'int64': { type: 'integer', format: 'int64' },
19-
'float': { type: 'number', format: 'float' },
20-
'double': { type: 'number', format: 'double' },
21-
'bool': { type: 'boolean' },
22-
'string': { type: 'string' },
23-
};
24-
2516
private root: OpenAPIV3.Document;
2617

2718
constructor(root: OpenAPIV3.Document) {
@@ -30,7 +21,7 @@ export class VendorExtensionProcessor {
3021

3122
/**
3223
* Process the spec by pruning anything marked with x-protobuf-excluded
33-
* and applying vendor extensions (x-protobuf-name, x-protobuf-type)
24+
* and applying vendor extensions (x-protobuf-name, x-protobuf-data-type)
3425
*/
3526
public process(): OpenAPIV3.Document {
3627
deleteMatchingKeys(this.root, (item: any) => this.hasProtobufExcluded(item));
@@ -139,46 +130,25 @@ export class VendorExtensionProcessor {
139130
}
140131

141132
/**
142-
* Apply type override to a schema if it has x-protobuf-type
133+
* Apply type override to simplify complex schemas to a single protobuf type.
143134
*/
144135
private applyTypeOverride(schema: any): void {
145136
if (!schema) return;
146137

147138
if (VendorExtensionProcessor.PROTOBUF_TYPE_EXTENSION in schema) {
148139
const protoType = schema[VendorExtensionProcessor.PROTOBUF_TYPE_EXTENSION];
149140

150-
// Clear structural properties that might conflict
151-
if ('$ref' in schema) {
152-
delete schema.$ref;
153-
}
154-
if ('properties' in schema) {
155-
delete schema.properties;
156-
}
157-
if ('additionalProperties' in schema) {
158-
delete schema.additionalProperties;
159-
}
160-
if ('oneOf' in schema) {
161-
delete schema.oneOf;
162-
}
163-
if ('anyOf' in schema) {
164-
delete schema.anyOf;
165-
}
166-
if ('allOf' in schema) {
167-
delete schema.allOf;
168-
}
169-
170-
const typeMapping = VendorExtensionProcessor.PROTOBUF_TYPE_MAPPING[protoType];
171-
if (typeMapping) {
172-
schema.type = typeMapping.type;
173-
if (typeMapping.format) {
174-
schema.format = typeMapping.format;
175-
}
176-
} else {
177-
schema.type = protoType;
178-
}
179-
180-
delete schema[VendorExtensionProcessor.PROTOBUF_TYPE_EXTENSION];
181-
logger.info(`Applied ${VendorExtensionProcessor.PROTOBUF_TYPE_EXTENSION}: ${protoType} -> type: ${schema.type}${schema.format ? `, format: ${schema.format}` : ''}`);
141+
// Clear structural properties that conflict with simple type
142+
delete schema.$ref;
143+
delete schema.properties;
144+
delete schema.additionalProperties;
145+
delete schema.oneOf;
146+
delete schema.anyOf;
147+
delete schema.allOf;
148+
149+
// Set type to x-protobuf-type value (preserves x-protobuf-type for template)
150+
schema.type = protoType;
151+
logger.info(`Applied ${VendorExtensionProcessor.PROTOBUF_TYPE_EXTENSION}: ${protoType} -> simplified to type: ${schema.type}`);
182152
}
183153
}
184154

tools/proto-convert/src/config/protobuf-generator-config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,5 @@ typeMappings:
1717
object: "ObjectMap"
1818
AnyType: "ObjectMap"
1919
number: "GeneralNumber"
20-
bytes: "bytes"
21-
NullValue: "NullValue"
2220
openapiGeneratorIgnoreList:
2321
- "README.md"

0 commit comments

Comments
 (0)