From 6a350c64c8aaa74cc07e92f7d1f471736170e663 Mon Sep 17 00:00:00 2001 From: Deyaaeldeen Almahallawi Date: Fri, 17 Sep 2021 18:33:04 -0400 Subject: [PATCH] [Schema Registry] Apply Archboard requested renames (#17720) * [Schema Registry] Apply Archboard requested renames * edit * more renamings --- .../samples-dev/schemaRegistryAvroSample.ts | 4 +- .../src/schemaRegistryAvroSerializer.ts | 12 ++--- .../test/schemaRegistryAvroSerializer.spec.ts | 6 +-- .../test/utils/mockedRegistryClient.ts | 10 ++-- .../test/utils/mockedSerializer.ts | 4 +- .../schema-registry/CHANGELOG.md | 1 + .../review/schema-registry.api.md | 10 ++-- .../samples-dev/schemaRegistrySample.ts | 6 +-- .../samples/v1/javascript/package.json | 2 +- .../v1/javascript/schemaRegistrySample.js | 10 ++-- .../samples/v1/typescript/package.json | 2 +- .../v1/typescript/src/schemaRegistrySample.ts | 8 +-- .../schema-registry/src/conversions.ts | 10 ++-- .../schema-registry/src/index.ts | 2 +- .../schema-registry/src/models.ts | 14 ++--- .../src/schemaRegistryClient.ts | 14 ++--- .../test/schemaRegistry.spec.ts | 54 +++++++++---------- 17 files changed, 79 insertions(+), 90 deletions(-) diff --git a/sdk/schemaregistry/schema-registry-avro/samples-dev/schemaRegistryAvroSample.ts b/sdk/schemaregistry/schema-registry-avro/samples-dev/schemaRegistryAvroSample.ts index 853760eb1ecf..98ad0d934251 100644 --- a/sdk/schemaregistry/schema-registry-avro/samples-dev/schemaRegistryAvroSample.ts +++ b/sdk/schemaregistry/schema-registry-avro/samples-dev/schemaRegistryAvroSample.ts @@ -46,8 +46,8 @@ const schema = JSON.stringify(schemaObject); const schemaDescription: SchemaDescription = { name: `${schemaObject.namespace}.${schemaObject.name}`, groupName, - serializationType: "avro", - content: schema + format: "avro", + definition: schema }; export async function main() { diff --git a/sdk/schemaregistry/schema-registry-avro/src/schemaRegistryAvroSerializer.ts b/sdk/schemaregistry/schema-registry-avro/src/schemaRegistryAvroSerializer.ts index 6f73404ac2b7..831930f1634d 100644 --- a/sdk/schemaregistry/schema-registry-avro/src/schemaRegistryAvroSerializer.ts +++ b/sdk/schemaregistry/schema-registry-avro/src/schemaRegistryAvroSerializer.ts @@ -169,14 +169,14 @@ export class SchemaRegistryAvroSerializer { throw new Error(`Schema with ID '${schemaId}' not found.`); } - if (!schemaResponse.serializationType.match(/^avro$/i)) { + if (!schemaResponse.format.match(/^avro$/i)) { throw new Error( - `Schema with ID '${schemaResponse.id}' has serialization type '${schemaResponse.serializationType}', not 'avro'.` + `Schema with ID '${schemaResponse.id}' has format '${schemaResponse.format}', not 'avro'.` ); } - const avroType = this.getAvroTypeForSchema(schemaResponse.content); - return this.cache(schemaId, schemaResponse.content, avroType); + const avroType = this.getAvroTypeForSchema(schemaResponse.definition); + return this.cache(schemaId, schemaResponse.definition, avroType); } private async getSchemaByContent(schema: string): Promise { @@ -193,8 +193,8 @@ export class SchemaRegistryAvroSerializer { const description = { groupName: this.schemaGroup, name: avroType.name, - serializationType: "avro", - content: schema + format: "avro", + definition: schema }; let id: string; diff --git a/sdk/schemaregistry/schema-registry-avro/test/schemaRegistryAvroSerializer.spec.ts b/sdk/schemaregistry/schema-registry-avro/test/schemaRegistryAvroSerializer.spec.ts index 002c0bee39d3..5212248e97b8 100644 --- a/sdk/schemaregistry/schema-registry-avro/test/schemaRegistryAvroSerializer.spec.ts +++ b/sdk/schemaregistry/schema-registry-avro/test/schemaRegistryAvroSerializer.spec.ts @@ -28,13 +28,13 @@ describe("SchemaRegistryAvroSerializer", function() { await assert.isRejected(serializer.serialize({}, schema), /name/); }); - it("rejects a schema with different serialization type", async () => { + it("rejects a schema with different format", async () => { const registry = createTestRegistry(true); // true means never live, we can't register non-avro schema in live service const serializer = await createTestSerializer(false, registry); const schema = await registry.registerSchema({ name: "_", - content: "_", - serializationType: "NotAvro", + definition: "_", + format: "NotAvro", groupName: testGroup }); diff --git a/sdk/schemaregistry/schema-registry-avro/test/utils/mockedRegistryClient.ts b/sdk/schemaregistry/schema-registry-avro/test/utils/mockedRegistryClient.ts index 1f4ff1a9b8e1..813447bb4c3b 100644 --- a/sdk/schemaregistry/schema-registry-avro/test/utils/mockedRegistryClient.ts +++ b/sdk/schemaregistry/schema-registry-avro/test/utils/mockedRegistryClient.ts @@ -35,15 +35,15 @@ export function createTestRegistry(neverLive = false): SchemaRegistry { schema: SchemaDescription, _options?: RegisterSchemaOptions ): Promise { - let result = mapByContent.get(schema.content); + let result = mapByContent.get(schema.definition); if (!result) { result = { id: newId(), - content: schema.content, + definition: schema.definition, version: 1, - serializationType: schema.serializationType + format: schema.format }; - mapByContent.set(result.content, result); + mapByContent.set(result.definition, result); mapById.set(result.id, result); } return result; @@ -62,7 +62,7 @@ export function createTestRegistry(neverLive = false): SchemaRegistry { schema: SchemaDescription, _options?: GetSchemaPropertiesOptions ): Promise { - return mapByContent.get(schema.content); + return mapByContent.get(schema.definition); } async function getSchema(id: string, _options?: GetSchemaOptions): Promise { diff --git a/sdk/schemaregistry/schema-registry-avro/test/utils/mockedSerializer.ts b/sdk/schemaregistry/schema-registry-avro/test/utils/mockedSerializer.ts index f196ed3aa63a..03ae167ba015 100644 --- a/sdk/schemaregistry/schema-registry-avro/test/utils/mockedSerializer.ts +++ b/sdk/schemaregistry/schema-registry-avro/test/utils/mockedSerializer.ts @@ -20,8 +20,8 @@ export async function registerTestSchema(registry: SchemaRegistry): Promise( // is not modeled by the generated client. id: response.schemaId!, version: response.schemaVersion!, - serializationType: response.serializationType!, + format: response.serializationType!, ...additionalProperties }; } diff --git a/sdk/schemaregistry/schema-registry/src/index.ts b/sdk/schemaregistry/schema-registry/src/index.ts index 7d3af0266d57..28c49d008a42 100644 --- a/sdk/schemaregistry/schema-registry/src/index.ts +++ b/sdk/schemaregistry/schema-registry/src/index.ts @@ -3,4 +3,4 @@ export * from "./models"; export { SchemaRegistryClient } from "./schemaRegistryClient"; -export { KnownSerializationType } from "./generated"; +export { KnownSerializationType as KnownSchemaFormat } from "./generated"; diff --git a/sdk/schemaregistry/schema-registry/src/models.ts b/sdk/schemaregistry/schema-registry/src/models.ts index 34273f1058b9..53efc6bf681d 100644 --- a/sdk/schemaregistry/schema-registry/src/models.ts +++ b/sdk/schemaregistry/schema-registry/src/models.ts @@ -14,7 +14,7 @@ export interface SchemaProperties { * Serialization type of schema. * Currently only 'avro' is supported, but this is subject to change. */ - serializationType: string; + format: string; /** Automatically incremented version number of the schema. */ version: number; @@ -31,13 +31,13 @@ export interface SchemaDescription { name: string; /** - * Serialization type of schema. Must match serialization type of group. - * Currently only 'avro' is supported, but this is subject to change. + * The format of schema and it must match the serialization type of the schema's group. + * Please refer to {@link KnownSerializationType} for possible values. */ - serializationType: string; + format: string; /** String representation of schema. */ - content: string; + definition: string; } /** @@ -45,7 +45,7 @@ export interface SchemaDescription { */ export interface Schema extends SchemaProperties { /** String representation of schema. */ - content: string; + definition: string; } /** @@ -92,7 +92,7 @@ export interface SchemaRegistry { /** * Gets the ID of an existing schema with matching name, group, type, and - * content. + * definition. * * @param schema - Schema to match. * @returns Matched schema's ID or undefined if no matching schema was found. diff --git a/sdk/schemaregistry/schema-registry/src/schemaRegistryClient.ts b/sdk/schemaregistry/schema-registry/src/schemaRegistryClient.ts index ee694df9b940..dbccaf0f0e99 100644 --- a/sdk/schemaregistry/schema-registry/src/schemaRegistryClient.ts +++ b/sdk/schemaregistry/schema-registry/src/schemaRegistryClient.ts @@ -73,7 +73,7 @@ export class SchemaRegistryClient implements SchemaRegistry { private addToCache(schema: SchemaDescription, id: SchemaProperties): void { this.schemaToIdMap.set(schema, id); - this.idToSchemaMap.set(id.id, { ...id, content: schema.content }); + this.idToSchemaMap.set(id.id, { ...id, definition: schema.definition }); } /** @@ -91,7 +91,7 @@ export class SchemaRegistryClient implements SchemaRegistry { options?: RegisterSchemaOptions ): Promise { const id = await this.client.schema - .register(schema.groupName, schema.name, schema.serializationType, schema.content, options) + .register(schema.groupName, schema.name, schema.format, schema.definition, options) .then(convertSchemaIdResponse); this.addToCache(schema, id); return id; @@ -99,7 +99,7 @@ export class SchemaRegistryClient implements SchemaRegistry { /** * Gets the ID of an existing schema with matching name, group, type, and - * content. + * definition. * * @param schema - Schema to match. * @returns Matched schema's ID or undefined if no matching schema was found. @@ -113,13 +113,7 @@ export class SchemaRegistryClient implements SchemaRegistry { return cached; } const id = await this.client.schema - .queryIdByContent( - schema.groupName, - schema.name, - schema.serializationType, - schema.content, - options - ) + .queryIdByContent(schema.groupName, schema.name, schema.format, schema.definition, options) .then(convertSchemaIdResponse); this.addToCache(schema, id); return id; diff --git a/sdk/schemaregistry/schema-registry/test/schemaRegistry.spec.ts b/sdk/schemaregistry/schema-registry/test/schemaRegistry.spec.ts index 7d9f240a6a6b..a961136a5686 100644 --- a/sdk/schemaregistry/schema-registry/test/schemaRegistry.spec.ts +++ b/sdk/schemaregistry/schema-registry/test/schemaRegistry.spec.ts @@ -22,8 +22,8 @@ const options: OperationOptions = { const schema: SchemaDescription = { name: "azsdk_js_test", groupName: testEnv.SCHEMA_REGISTRY_GROUP, - serializationType: "avro", - content: JSON.stringify({ + format: "avro", + definition: JSON.stringify({ type: "record", name: "User", namespace: "com.azure.schemaregistry.samples", @@ -54,9 +54,9 @@ function assertIsValidSchemaId( ): asserts schemaId { assertIsNotNullUndefinedOrEmpty(schemaId); assertIsNotNullUndefinedOrEmpty(schemaId.id); - assertIsNotNullUndefinedOrEmpty(schemaId.serializationType); + assertIsNotNullUndefinedOrEmpty(schemaId.format); assert.isNotNull(schemaId.version); - assert.equal(schemaId.serializationType.toLowerCase(), expectedSerializationType.toLowerCase()); + assert.equal(schemaId.format.toLowerCase(), expectedSerializationType.toLowerCase()); } describe("SchemaRegistryClient", function() { @@ -82,12 +82,9 @@ describe("SchemaRegistryClient", function() { it("rejects schema registration with invalid args", async () => { await assert.isRejected(client.registerSchema({ ...schema, name: null! }), /null/); await assert.isRejected(client.registerSchema({ ...schema, groupName: null! }), /null/); - await assert.isRejected(client.registerSchema({ ...schema, content: null! }), /null/); - await assert.isRejected(client.registerSchema({ ...schema, serializationType: null! }), /null/); - await assert.isRejected( - client.registerSchema({ ...schema, serializationType: "not-valid" }), - /not-valid/ - ); + await assert.isRejected(client.registerSchema({ ...schema, definition: null! }), /null/); + await assert.isRejected(client.registerSchema({ ...schema, format: null! }), /null/); + await assert.isRejected(client.registerSchema({ ...schema, format: "not-valid" }), /not-valid/); }); it("registers schema", async () => { @@ -98,13 +95,10 @@ describe("SchemaRegistryClient", function() { it("fails to get schema ID when given invalid args", async () => { await assert.isRejected(client.getSchemaProperties({ ...schema, name: null! }), /null/); await assert.isRejected(client.getSchemaProperties({ ...schema, groupName: null! }), /null/); - await assert.isRejected(client.getSchemaProperties({ ...schema, content: null! }), /null/); - await assert.isRejected( - client.getSchemaProperties({ ...schema, serializationType: null! }), - /null/ - ); + await assert.isRejected(client.getSchemaProperties({ ...schema, definition: null! }), /null/); + await assert.isRejected(client.getSchemaProperties({ ...schema, format: null! }), /null/); await assert.isRejected( - client.getSchemaProperties({ ...schema, serializationType: "not-valid" }), + client.getSchemaProperties({ ...schema, format: "not-valid" }), /not-valid/ ); }); @@ -120,7 +114,7 @@ describe("SchemaRegistryClient", function() { const found = await client.getSchemaProperties(schema, options); assertIsValidSchemaId(found); - // NOTE: IDs may differ here as we could get a different version with same content. + // NOTE: IDs may differ here as we could get a different version with same definition. }); it("fails to get schema by ID when given invalid ID", async () => { @@ -137,7 +131,7 @@ describe("SchemaRegistryClient", function() { const found = await client.getSchema(registered.id, options); assertIsValidSchemaId(found); - assert.equal(found.content, schema.content); + assert.equal(found.definition, schema.definition); }); it("cache schema and ID", async () => { @@ -150,7 +144,7 @@ describe("SchemaRegistryClient", function() { } }); assertIsValidSchemaId(foundSchema); - assert.equal(foundSchema.content, schema.content); + assert.equal(foundSchema.definition, schema.definition); const foundId = await client.getSchemaProperties(schema, { onResponse: () => { @@ -164,7 +158,7 @@ describe("SchemaRegistryClient", function() { it("cache schema and ID if not registered by the current client instance", async () => { // register a schema without caching. const registered = await client["client"]["schema"] - .register(schema.groupName, schema.name, schema.serializationType, schema.content, options) + .register(schema.groupName, schema.name, schema.format, schema.definition, options) .then(convertSchemaIdResponse); assertIsValidSchemaId(registered); @@ -177,7 +171,7 @@ describe("SchemaRegistryClient", function() { }); assert.isTrue(firstCall, "Expected call to the service did not happen"); assertIsValidSchemaId(foundSchemaFirstCall); - assert.equal(foundSchemaFirstCall.content, schema.content); + assert.equal(foundSchemaFirstCall.definition, schema.definition); // second call returns the result from the cache const foundSchemaSecondCall = await client.getSchema(registered.id, { onResponse: () => { @@ -186,7 +180,7 @@ describe("SchemaRegistryClient", function() { }); assert.isTrue(firstCall, "Expected call to the service did not happen"); assertIsValidSchemaId(foundSchemaSecondCall); - assert.equal(foundSchemaSecondCall.content, schema.content); + assert.equal(foundSchemaSecondCall.definition, schema.definition); firstCall = false; // first call sends a request to the service and then cache the response @@ -214,15 +208,15 @@ describe("SchemaRegistryClient", function() { const schema2: SchemaDescription = { name: "azsdk_js_test2", groupName: testEnv.SCHEMA_REGISTRY_GROUP, - serializationType: "avro", - content: + format: "avro", + definition: "{\n" + ' "type": "record",\n' + ' "name": "Test",\n' + ' "fields": [{ "name": "X", "type": { "type": "string" } }]\n' + "}\n" }; - // content that is going to the service has whitespaces + // definition that is going to the service has whitespaces const registered = await client.registerSchema(schema2, options); assertIsValidSchemaId(registered); @@ -232,16 +226,16 @@ describe("SchemaRegistryClient", function() { } }); assertIsValidSchemaId(foundSchema); - assert.equal(foundSchema.content, schema2.content); + assert.equal(foundSchema.definition, schema2.definition); let ran = false; const foundId = await client.getSchemaProperties( { - // content that comes from the service does not have whitespaces - content: foundSchema.content, + // definition that comes from the service does not have whitespaces + definition: foundSchema.definition, groupName: schema2.groupName, name: schema2.name, - serializationType: foundSchema.serializationType + format: foundSchema.format }, { onResponse: () => { @@ -249,7 +243,7 @@ describe("SchemaRegistryClient", function() { } } ); - // the schema comes from the service normalized so that its content has no whitespace + // the schema comes from the service normalized so that its definition has no whitespace // which is different from the original schema that was registered first and lives // in the cache. There is a trade-off between the perf hit for doing client-side // normalization and the perf hit for doing an extra call to the service for the