Skip to content

Commit 1028ede

Browse files
committed
Change vendorExtension protobuf type handling to use protobuf type instead of openApi type
1 parent 065ad2b commit 1028ede

5 files changed

Lines changed: 306 additions & 34 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

tools/proto-convert/src/VendorExtensionProcessor.ts

Lines changed: 3 additions & 19 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) {
@@ -167,18 +158,11 @@ export class VendorExtensionProcessor {
167158
delete schema.allOf;
168159
}
169160

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-
}
161+
// Directly use the x-protobuf-type value as the OpenAPI type
162+
schema.type = protoType;
179163

180164
delete schema[VendorExtensionProcessor.PROTOBUF_TYPE_EXTENSION];
181-
logger.info(`Applied ${VendorExtensionProcessor.PROTOBUF_TYPE_EXTENSION}: ${protoType} -> type: ${schema.type}${schema.format ? `, format: ${schema.format}` : ''}`);
165+
logger.info(`Applied ${VendorExtensionProcessor.PROTOBUF_TYPE_EXTENSION}: ${protoType} -> type: ${schema.type}`);
182166
}
183167
}
184168

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,19 @@ typeMappings:
1919
number: "GeneralNumber"
2020
bytes: "bytes"
2121
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"
2236
openapiGeneratorIgnoreList:
2337
- "README.md"

tools/proto-convert/src/config/spec-filter.yaml

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ x-operation-groups:
66
# Schemas to exclude from proto generation
77
# These schemas and their nested dependencies will not be included
88
excluded_schemas:
9-
- AggregationContainer
10-
- Aggregate
119
- Suggester
1210
- Suggest
1311
- DisMaxQuery
@@ -39,3 +37,123 @@ excluded_schemas:
3937
- TypeQuery
4038
- WrapperQuery
4139
- XyShapeQuery
40+
41+
# AggregationContainer - exclude all except TermsAggregation
42+
- AdjacencyMatrixAggregation
43+
- AutoDateHistogramAggregation
44+
- AverageAggregation
45+
- AverageBucketAggregation
46+
- BoxplotAggregation
47+
- BucketScriptAggregation
48+
- BucketSelectorAggregation
49+
- BucketSortAggregation
50+
- CardinalityAggregation
51+
- ChildrenAggregation
52+
- CompositeAggregation
53+
- CumulativeCardinalityAggregation
54+
- CumulativeSumAggregation
55+
- DateHistogramAggregation
56+
- DateRangeAggregation
57+
- DerivativeAggregation
58+
- DiversifiedSamplerAggregation
59+
- ExtendedStatsAggregation
60+
- ExtendedStatsBucketAggregation
61+
- FiltersAggregation
62+
- GeoBoundsAggregation
63+
- GeoCentroidAggregation
64+
- GeoDistanceAggregation
65+
- GeoHashGridAggregation
66+
- GeoTileGridAggregation
67+
- GlobalAggregation
68+
- HistogramAggregation
69+
- IpRangeAggregation
70+
- MatrixStatsAggregation
71+
- MaxBucketAggregation
72+
- MedianAbsoluteDeviationAggregation
73+
- MinBucketAggregation
74+
- MissingAggregation
75+
- MovingAverageAggregation
76+
- MovingFunctionAggregation
77+
- MovingPercentilesAggregation
78+
- MultiTermsAggregation
79+
- NestedAggregation
80+
- NormalizeAggregation
81+
- ParentAggregation
82+
- PercentileRanksAggregation
83+
- PercentilesAggregation
84+
- PercentilesBucketAggregation
85+
- RangeAggregation
86+
- RareTermsAggregation
87+
- RateAggregation
88+
- ReverseNestedAggregation
89+
- SamplerAggregation
90+
- ScriptedMetricAggregation
91+
- SerialDifferencingAggregation
92+
- SignificantTermsAggregation
93+
- SignificantTextAggregation
94+
- StatsAggregation
95+
- StatsBucketAggregation
96+
- SumAggregation
97+
- SumBucketAggregation
98+
- TopHitsAggregation
99+
- TTestAggregation
100+
- ValueCountAggregation
101+
- VariableWidthHistogramAggregation
102+
- WeightedAverageAggregation
103+
104+
# Aggregate - exclude all except TermsAggregate variants (DoubleTerms, LongTerms, StringTerms, UnmappedTerms)
105+
- AdjacencyMatrixAggregate
106+
- AutoDateHistogramAggregate
107+
- AvgAggregate
108+
- BoxPlotAggregate
109+
- BucketMetricValueAggregate
110+
- CardinalityAggregate
111+
- ChildrenAggregate
112+
- CompositeAggregate
113+
- CumulativeCardinalityAggregate
114+
- DateHistogramAggregate
115+
- DateRangeAggregate
116+
- DerivativeAggregate
117+
- ExtendedStatsAggregate
118+
- ExtendedStatsBucketAggregate
119+
- FilterAggregate
120+
- FiltersAggregate
121+
- GeoBoundsAggregate
122+
- GeoCentroidAggregate
123+
- GeoDistanceAggregate
124+
- GeoHashGridAggregate
125+
- GeoTileGridAggregate
126+
- GlobalAggregate
127+
- HdrPercentileRanksAggregate
128+
- HdrPercentilesAggregate
129+
- HistogramAggregate
130+
- IpRangeAggregate
131+
- LongRareTermsAggregate
132+
- MatrixStatsAggregate
133+
- MedianAbsoluteDeviationAggregate
134+
- MissingAggregate
135+
- MultiTermsAggregate
136+
- NestedAggregate
137+
- ParentAggregate
138+
- PercentilesBucketAggregate
139+
- RangeAggregate
140+
- RateAggregate
141+
- ReverseNestedAggregate
142+
- SamplerAggregate
143+
- ScriptedMetricAggregate
144+
- SignificantLongTermsAggregate
145+
- SignificantStringTermsAggregate
146+
- SimpleValueAggregate
147+
- StatsAggregate
148+
- StatsBucketAggregate
149+
- StringRareTermsAggregate
150+
- SumAggregate
151+
- TDigestPercentileRanksAggregate
152+
- TDigestPercentilesAggregate
153+
- TopHitsAggregate
154+
- TTestAggregate
155+
- UnmappedRareTermsAggregate
156+
- UnmappedSignificantTermsAggregate
157+
- ValueCountAggregate
158+
- VariableWidthHistogramAggregate
159+
- WeightedAvgAggregate

0 commit comments

Comments
 (0)