From 416861729db41e13b0b8e4c6a36bf6e1537884b1 Mon Sep 17 00:00:00 2001 From: Spencer Kwok Date: Thu, 11 Jul 2024 21:46:40 +0000 Subject: [PATCH 1/3] Allow both @extension and @grpcExtension to bridge rest.li with gRpc --- gradle.properties | 2 +- .../ExtensionSchemaValidationCmdLineApp.java | 18 ++------ .../extensions/validCase/BazExtensions.pdl | 10 +++++ .../src/test/pegasus/DummyKeyWithGrpc.pdl | 42 +++++++++++++++++++ 4 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 restli-tools/src/test/extensions/validCase/BazExtensions.pdl create mode 100644 restli-tools/src/test/pegasus/DummyKeyWithGrpc.pdl diff --git a/gradle.properties b/gradle.properties index e8093e6764..1e56ca1fbd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=29.57.2 +version=29.58.0 group=com.linkedin.pegasus org.gradle.configureondemand=true org.gradle.parallel=true diff --git a/restli-tools/src/main/java/com/linkedin/restli/tools/data/ExtensionSchemaValidationCmdLineApp.java b/restli-tools/src/main/java/com/linkedin/restli/tools/data/ExtensionSchemaValidationCmdLineApp.java index 494963bafd..9446359fd6 100644 --- a/restli-tools/src/main/java/com/linkedin/restli/tools/data/ExtensionSchemaValidationCmdLineApp.java +++ b/restli-tools/src/main/java/com/linkedin/restli/tools/data/ExtensionSchemaValidationCmdLineApp.java @@ -63,8 +63,8 @@ * 1. The extension schema is a valid schema. * 2. The extension schema name has to follow the naming convention: + "Extensions" * 3. The extension schema can only include the base schema. - * 4. The extension schema's field annotation keys must be in the "extension" or "grpcExtension" namespaces (but not both). - * 5. The extension schema's field annotations must conform to {@link ExtensionSchemaAnnotation} or {@link GrpcExtensionAnnotation}. + * 4. The extension schema's field annotation keys must be in the "extension" and/or "grpcExtension" namespaces + * 5. The extension schema's field annotations must conform to {@link ExtensionSchemaAnnotation} and/or {@link GrpcExtensionAnnotation}. * 6. The extension schema's fields can only be Typeref or array of Typeref. * 7. The extension schema's field schema's annotation keys must be in the "resourceKey" and/or "grpcService" namespaces. * 8. The extension schema's field annotation versionSuffix value has to match the versionSuffix value in "resourceKey"/"grpcService" annotation on the field schema. @@ -232,7 +232,7 @@ private static void checkExtensionSchemaFields(List exte { validateRestLiExtensionField(field); } - else if (properties.containsKey(GRPC_EXTENSION_ANNOTATION_NAMESPACE)) + if (properties.containsKey(GRPC_EXTENSION_ANNOTATION_NAMESPACE)) { validateGrpcExtensionField(field); } @@ -242,12 +242,6 @@ else if (properties.containsKey(GRPC_EXTENSION_ANNOTATION_NAMESPACE)) private static void validateRestLiExtensionField(RecordDataSchema.Field field) throws InvalidExtensionSchemaException { Map properties = field.getProperties(); - // Validate that it doesn't also contain gRPC downstream info - if (properties.containsKey(GRPC_EXTENSION_ANNOTATION_NAMESPACE)) - { - throw new InvalidExtensionSchemaException("The extension schema field '" - + field.getName() + "' cannot be annotated with both 'extension' and 'grpcExtension'"); - } // Validate the actual content/structure of the annotation value validateFieldAnnotation(properties.get(EXTENSION_ANNOTATION_NAMESPACE), new ExtensionSchemaAnnotation().schema()); @@ -262,12 +256,6 @@ private static void validateRestLiExtensionField(RecordDataSchema.Field field) private static void validateGrpcExtensionField(RecordDataSchema.Field field) throws InvalidExtensionSchemaException { Map properties = field.getProperties(); - // Validate that it doesn't also contain Rest.li downstream info - if (properties.containsKey(EXTENSION_ANNOTATION_NAMESPACE)) - { - throw new InvalidExtensionSchemaException("The extension schema field '" - + field.getName() + "' cannot be annotated with both 'extension' and 'grpcExtension'"); - } // Validate the actual content/structure of the annotation value validateFieldAnnotation(properties.get(GRPC_EXTENSION_ANNOTATION_NAMESPACE), new GrpcExtensionAnnotation().schema()); diff --git a/restli-tools/src/test/extensions/validCase/BazExtensions.pdl b/restli-tools/src/test/extensions/validCase/BazExtensions.pdl new file mode 100644 index 0000000000..d3c8198653 --- /dev/null +++ b/restli-tools/src/test/extensions/validCase/BazExtensions.pdl @@ -0,0 +1,10 @@ +/** + * Valid extension schema: + * The co-existence of @extension and @grpcExtension is allowed + */ +record BazExtensions includes Baz { + @extension.using = "finder: test" + @grpcExtension.rpc = "get" + @grpcExtension.versionSuffix = "V2" + testField: array[DummyKeyWithGrpc] +} diff --git a/restli-tools/src/test/pegasus/DummyKeyWithGrpc.pdl b/restli-tools/src/test/pegasus/DummyKeyWithGrpc.pdl new file mode 100644 index 0000000000..1555aa411f --- /dev/null +++ b/restli-tools/src/test/pegasus/DummyKeyWithGrpc.pdl @@ -0,0 +1,42 @@ +/** + * A test schema which is used as a field type in extension schema. + */ +@resourceKey = [ { + "keyConfig" : { + "keys" : { + "profilesId" : { + "assocKey" : { + "authorId" : "fabricName", + "objectId" : "sessionId" + } + } + } + }, + "entity" : "Profile", + "resourcePath" : "/profiles/{profilesId}" +}, { + "keyConfig" : { + "keys" : { + "profilesId" : { + "assocKey" : { + "authorId" : "fabricName", + "objectId" : "sessionId" + } + } + } + }, + "entity" : "ProfileV2", + "resourcePath" : "/profilesV2/{profilesId}", + "versionSuffix" : "V2" +} ] +@grpcService = [ { + "entity" : "proto.com.linkedin.Profile" + "rpc" : "get", + "service" : "proto.com.linkedin.ProfileService" +}, { + "entity" : "proto.com.linkedin.ProfileV2" + "rpc" : "get", + "service" : "proto.com.linkedin.ProfileServiceV2" + "versionSuffix": "V2" +} ] +typeref DummyKeyWithGrpc = string From 4d4a1ffc636008a4f568557b6ad010f9c5991545 Mon Sep 17 00:00:00 2001 From: Spencer Kwok Date: Thu, 11 Jul 2024 22:01:51 +0000 Subject: [PATCH 2/3] Update CHANGELOG.md to 29.58.0 --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 566aa0bcf4..0e23d59f4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and what APIs have changed, if applicable. ## [Unreleased] +## [29.58.0] - 2024-07-11 + ## [29.57.2] - 2024-06-17 - Update grpc version to 1.59.1 and protobuf to 3.24.0 @@ -5707,7 +5709,8 @@ patch operations can re-use these classes for generating patch messages. ## [0.14.1] -[Unreleased]: https://github.com/linkedin/rest.li/compare/v29.57.2...master +[Unreleased]: https://github.com/linkedin/rest.li/compare/v29.58.0...master +[29.58.0]: https://github.com/linkedin/rest.li/compare/v29.57.2...v29.58.0 [29.57.2]: https://github.com/linkedin/rest.li/compare/v29.57.1...v29.57.2 [29.57.1]: https://github.com/linkedin/rest.li/compare/v29.57.0...v29.57.1 [29.57.0]: https://github.com/linkedin/rest.li/compare/v29.56.1...v29.57.0 From 91af99b62b7fb5a5eff5d711d8cf31107d108ef3 Mon Sep 17 00:00:00 2001 From: Spencer Kwok Date: Sun, 14 Jul 2024 22:08:27 -0700 Subject: [PATCH 3/3] Add message to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e23d59f4a..33e8136ca1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and what APIs have changed, if applicable. ## [Unreleased] ## [29.58.0] - 2024-07-11 +- Allow both @extension and @grpcExtension extensions in schema validation ## [29.57.2] - 2024-06-17 - Update grpc version to 1.59.1 and protobuf to 3.24.0