Skip to content

Commit 8ddf36b

Browse files
committed
use x-protobuf-type
Signed-off-by: xil <fridalu66@gmail.com>
1 parent d7bd626 commit 8ddf36b

3 files changed

Lines changed: 45 additions & 416 deletions

File tree

tools/proto-convert/src/VendorExtensionProcessor.ts

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class VendorExtensionProcessor {
2121

2222
/**
2323
* Process the spec by pruning anything marked with x-protobuf-excluded
24-
* and applying vendor extensions (x-protobuf-name, x-protobuf-type)
24+
* and applying vendor extensions (x-protobuf-name, x-protobuf-data-type)
2525
*/
2626
public process(): OpenAPIV3.Document {
2727
deleteMatchingKeys(this.root, (item: any) => this.hasProtobufExcluded(item));
@@ -130,39 +130,25 @@ export class VendorExtensionProcessor {
130130
}
131131

132132
/**
133-
* 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.
134134
*/
135135
private applyTypeOverride(schema: any): void {
136136
if (!schema) return;
137137

138138
if (VendorExtensionProcessor.PROTOBUF_TYPE_EXTENSION in schema) {
139139
const protoType = schema[VendorExtensionProcessor.PROTOBUF_TYPE_EXTENSION];
140140

141-
// Clear structural properties that might conflict
142-
if ('$ref' in schema) {
143-
delete schema.$ref;
144-
}
145-
if ('properties' in schema) {
146-
delete schema.properties;
147-
}
148-
if ('additionalProperties' in schema) {
149-
delete schema.additionalProperties;
150-
}
151-
if ('oneOf' in schema) {
152-
delete schema.oneOf;
153-
}
154-
if ('anyOf' in schema) {
155-
delete schema.anyOf;
156-
}
157-
if ('allOf' in schema) {
158-
delete schema.allOf;
159-
}
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;
160148

161-
// Directly use the x-protobuf-type value as the OpenAPI type
149+
// Set type to x-protobuf-type value (preserves x-protobuf-type for template)
162150
schema.type = protoType;
163-
164-
delete schema[VendorExtensionProcessor.PROTOBUF_TYPE_EXTENSION];
165-
logger.info(`Applied ${VendorExtensionProcessor.PROTOBUF_TYPE_EXTENSION}: ${protoType} -> type: ${schema.type}`);
151+
logger.info(`Applied ${VendorExtensionProcessor.PROTOBUF_TYPE_EXTENSION}: ${protoType} -> simplified to type: ${schema.type}`);
166152
}
167153
}
168154

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,5 @@ typeMappings:
1717
object: "ObjectMap"
1818
AnyType: "ObjectMap"
1919
number: "GeneralNumber"
20-
bytes: "bytes"
21-
NullValue: "NullValue"
22-
double: "double"
23-
float: "float"
24-
int32: "int32"
25-
int64: "int64"
26-
uint32: "uint32"
27-
uint64: "uint64"
28-
sint32: "sint32"
29-
sint64: "sint64"
30-
fixed32: "fixed32"
31-
fixed64: "fixed64"
32-
sfixed32: "sfixed32"
33-
sfixed64: "sfixed64"
34-
bool: "bool"
35-
string: "string"
3620
openapiGeneratorIgnoreList:
3721
- "README.md"

0 commit comments

Comments
 (0)