Skip to content

Commit cff173d

Browse files
committed
change to use field option
Signed-off-by: xil <fridalu66@gmail.com>
1 parent 05d8f10 commit cff173d

5 files changed

Lines changed: 44 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
77
- Add compatibility matrix ([#373](https://github.com/opensearch-project/opensearch-protobufs/pull/373))
88
- Enhance spec-filter to support x-operation-group filtering and merge parameters across operations in same x-operation-group instead of selecting by max parameters ([#374](https://github.com/opensearch-project/opensearch-protobufs/pull/374))
99
- Add BoostingQuery and SimpleQueryString protos ([#376](https://github.com/opensearch-project/opensearch-protobufs/pull/376))
10-
- Add @grpc_only annotation to preserve manually-maintained protobuf fields ([#377](https://github.com/opensearch-project/opensearch-protobufs/pull/377))
10+
- Add tooling_skip field option to preserve manually-maintained protobuf fields ([#378](https://github.com/opensearch-project/opensearch-protobufs/pull/378))
1111

1212
### Changed
1313

protos/schemas/options.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
syntax = "proto3";
2+
package org.opensearch.protobufs;
3+
4+
import "google/protobuf/descriptor.proto";
5+
6+
option go_package = "github.com/opensearch-project/opensearch-protobufs/go/opensearchpb";
7+
option java_multiple_files = true;
8+
option java_outer_classname = "OptionsProto";
9+
option java_package = "org.opensearch.protobufs";
10+
11+
extend google.protobuf.FieldOptions {
12+
// Mark a field to be skipped by tooling. These fields are manually maintained and won't be marked as deprecated.
13+
optional bool tooling_skip = 50001;
14+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
syntax = "proto3";
55
package org.opensearch.protobufs;
66

7+
import "protos/schemas/options.proto";
8+
79
option go_package = "github.com/opensearch-project/opensearch-protobufs/go/opensearchpb";
810
option java_multiple_files = true;
911
option java_outer_classname = "CommonProto";

tools/proto-convert/src/postprocessing/CompatibilityMerger.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { CompatibilityReporter, formatField } from './CompatibilityReporter';
1414

1515
const DEPRECATED: Annotation = { name: 'deprecated', value: 'true' };
16-
const GRPC_ONLY_TAG = '@grpc_only';
16+
const TOOLING_SKIP: Annotation = { name: '(tooling_skip)', value: 'true' };
1717

1818
/**
1919
* Extract base name
@@ -43,15 +43,14 @@ function isDeprecated(item: HasAnnotations): boolean {
4343
) ?? false;
4444
}
4545

46-
/** Type with comment field */
47-
type HasComment = { comment?: string };
48-
4946
/**
50-
* Check if an item has @grpc_only tag in its comment.
51-
* Fields with this tag are manually maintained for gRPC and won't be deprecated.
47+
* Check if an item has tooling_skip option set to true.
48+
* Fields with this option are manually maintained and won't be deprecated.
5249
*/
53-
function isGrpcOnly(item: HasComment): boolean {
54-
return item.comment?.includes(GRPC_ONLY_TAG) ?? false;
50+
function hasToolingSkip(item: HasAnnotations): boolean {
51+
return item.annotations?.some(a =>
52+
a.name === TOOLING_SKIP.name && a.value === TOOLING_SKIP.value
53+
) ?? false;
5554
}
5655

5756
/**
@@ -126,8 +125,7 @@ function mergeField(
126125
}
127126
}
128127
} else {
129-
if (isGrpcOnly(sourceField)) {
130-
// Keep gRPC-only field as-is, don't deprecate it
128+
if (hasToolingSkip(sourceField)) {
131129
return sourceField;
132130
}
133131
reporter?.addFieldChange({

tools/proto-convert/test/postprocessing/CompatibilityMerger.test.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,14 @@ describe('mergeMessage', () => {
276276
expect(deprecatedOptions).toHaveLength(1);
277277
});
278278

279-
it('should keep fields with @grpc_only comment without deprecating', () => {
279+
it('should keep fields with tooling_skip option without deprecating', () => {
280280
const source: ProtoMessage = {
281281
name: 'TestMessage',
282282
fields: [{
283-
name: 'grpc_field',
283+
name: 'skip_field',
284284
type: 'string',
285285
number: 1,
286-
comment: '@grpc_only'
286+
annotations: [{ name: '(tooling_skip)', value: 'true' }]
287287
}, {
288288
name: 'normal_field',
289289
type: 'string',
@@ -301,21 +301,22 @@ describe('mergeMessage', () => {
301301

302302
const result = mergeMessage(source, upcoming);
303303

304-
// grpc_field should remain without deprecated annotation
304+
// skip_field should remain without deprecated annotation added
305305
expect(result.fields).toHaveLength(2);
306-
const grpcField = result.fields.find(f => f.name === 'grpc_field');
307-
expect(grpcField).toBeDefined();
308-
expect(grpcField!.annotations).toBeUndefined();
306+
const skipField = result.fields.find(f => f.name === 'skip_field');
307+
expect(skipField).toBeDefined();
308+
// Should only have tooling_skip, not deprecated
309+
expect(skipField!.annotations).not.toContainEqual({ name: 'deprecated', value: 'true' });
309310
});
310311

311-
it('should not report @grpc_only fields as deprecated', () => {
312+
it('should not report tooling_skip fields as deprecated', () => {
312313
const source: ProtoMessage = {
313314
name: 'TestMessage',
314315
fields: [{
315-
name: 'grpc_field',
316+
name: 'skip_field',
316317
type: 'string',
317318
number: 1,
318-
comment: '@grpc_only'
319+
annotations: [{ name: '(tooling_skip)', value: 'true' }]
319320
}]
320321
};
321322
const upcoming: ProtoMessage = {
@@ -327,18 +328,18 @@ describe('mergeMessage', () => {
327328
mergeMessage(source, upcoming, reporter);
328329

329330
const markdown = reporter.toMarkdown();
330-
// Should not report deprecation for @grpc_only fields
331+
// Should not report deprecation for tooling_skip fields
331332
expect(markdown).toContain('No changes detected');
332333
});
333334

334-
it('should keep @grpc_only field if it exists in upcoming', () => {
335+
it('should keep tooling_skip field if it exists in upcoming', () => {
335336
const source: ProtoMessage = {
336337
name: 'TestMessage',
337338
fields: [{
338339
name: 'field_name',
339340
type: 'string',
340341
number: 1,
341-
comment: '@grpc_only'
342+
annotations: [{ name: '(tooling_skip)', value: 'true' }]
342343
}]
343344
};
344345
const upcoming: ProtoMessage = {
@@ -356,18 +357,18 @@ describe('mergeMessage', () => {
356357
expect(result.fields[0].name).toBe('field_name');
357358
});
358359

359-
it('should assign new field number after max including @grpc_only field', () => {
360+
it('should assign new field number after max including tooling_skip field', () => {
360361
const source: ProtoMessage = {
361362
name: 'TestMessage',
362363
fields: [{
363364
name: 'existing_field',
364365
type: 'string',
365366
number: 1
366367
}, {
367-
name: 'grpc_field',
368+
name: 'skip_field',
368369
type: 'string',
369370
number: 5, // This is the max field number
370-
comment: '@grpc_only'
371+
annotations: [{ name: '(tooling_skip)', value: 'true' }]
371372
}]
372373
};
373374
const upcoming: ProtoMessage = {
@@ -385,9 +386,9 @@ describe('mergeMessage', () => {
385386

386387
const result = mergeMessage(source, upcoming);
387388

388-
// grpc_field is kept, new_field is added
389+
// skip_field is kept, new_field is added
389390
expect(result.fields).toHaveLength(3);
390-
expect(result.fields.find(f => f.name === 'grpc_field')).toBeDefined();
391+
expect(result.fields.find(f => f.name === 'skip_field')).toBeDefined();
391392

392393
const newField = result.fields.find(f => f.name === 'new_field');
393394
expect(newField).toBeDefined();

0 commit comments

Comments
 (0)