diff --git a/sdk/schemaregistry/schema-registry-avro/README.md b/sdk/schemaregistry/schema-registry-avro/README.md index e3b8ed474e11..43520a2fa295 100644 --- a/sdk/schemaregistry/schema-registry-avro/README.md +++ b/sdk/schemaregistry/schema-registry-avro/README.md @@ -36,7 +36,7 @@ npm install @azure/schema-registry-avro Provides API to serialize to and deserialize from Avro Binary Encoding plus a header with schema ID. Uses `SchemaRegistryClient` from the [@azure/schema-registry](https://www.npmjs.com/package/@azure/schema-registry) package -to get schema IDs from schema content or vice versa. The provided API has internal cache to avoid calling the schema registry service when possible. +to get schema IDs from schema definition or vice versa. The provided API has internal cache to avoid calling the schema registry service when possible. ### Message format diff --git a/sdk/schemaregistry/schema-registry-avro/samples-dev/schemaRegistryAvroSample.ts b/sdk/schemaregistry/schema-registry-avro/samples-dev/schemaRegistryAvroSample.ts index 98ad0d934251..3dafe4dd173f 100644 --- a/sdk/schemaregistry/schema-registry-avro/samples-dev/schemaRegistryAvroSample.ts +++ b/sdk/schemaregistry/schema-registry-avro/samples-dev/schemaRegistryAvroSample.ts @@ -47,7 +47,7 @@ const schemaDescription: SchemaDescription = { name: `${schemaObject.namespace}.${schemaObject.name}`, groupName, format: "avro", - definition: schema + schemaDefinition: 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 831930f1634d..ceb1bdc79e8d 100644 --- a/sdk/schemaregistry/schema-registry-avro/src/schemaRegistryAvroSerializer.ts +++ b/sdk/schemaregistry/schema-registry-avro/src/schemaRegistryAvroSerializer.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { SchemaRegistry } from "@azure/schema-registry"; +import { SchemaDescription, SchemaRegistry } from "@azure/schema-registry"; import * as avro from "avsc"; import { toUint8Array } from "./utils/buffer"; @@ -114,7 +114,7 @@ export class SchemaRegistryAvroSerializer { * @returns A new buffer with the serialized value */ async serialize(value: unknown, schema: string): Promise { - const entry = await this.getSchemaByContent(schema); + const entry = await this.getSchemaByDefinition(schema); const payload = entry.type.toBuffer(value); const buffer = Buffer.alloc(PAYLOAD_OFFSET + payload.length); @@ -155,7 +155,7 @@ export class SchemaRegistryAvroSerializer { return schema.type.fromBuffer(payloadBuffer); } - private readonly cacheByContent = new Map(); + private readonly cacheBySchemaDefinition = new Map(); private readonly cacheById = new Map(); private async getSchema(schemaId: string): Promise { @@ -175,12 +175,12 @@ export class SchemaRegistryAvroSerializer { ); } - const avroType = this.getAvroTypeForSchema(schemaResponse.definition); - return this.cache(schemaId, schemaResponse.definition, avroType); + const avroType = this.getAvroTypeForSchema(schemaResponse.schemaDefinition); + return this.cache(schemaId, schemaResponse.schemaDefinition, avroType); } - private async getSchemaByContent(schema: string): Promise { - const cached = this.cacheByContent.get(schema); + private async getSchemaByDefinition(schema: string): Promise { + const cached = this.cacheBySchemaDefinition.get(schema); if (cached) { return cached; } @@ -190,11 +190,11 @@ export class SchemaRegistryAvroSerializer { throw new Error("Schema must have a name."); } - const description = { + const description: SchemaDescription = { groupName: this.schemaGroup, name: avroType.name, format: "avro", - definition: schema + schemaDefinition: schema }; let id: string; @@ -204,7 +204,7 @@ export class SchemaRegistryAvroSerializer { const response = await this.registry.getSchemaProperties(description); if (!response) { throw new Error( - `Schema '${description.name}' not found in registry group '${description.groupName}', or not found to have matching content.` + `Schema '${description.name}' not found in registry group '${description.groupName}', or not found to have matching definition.` ); } id = response.id; @@ -215,7 +215,7 @@ export class SchemaRegistryAvroSerializer { private cache(id: string, schema: string, type: avro.Type): CacheEntry { const entry = { id, type }; - this.cacheByContent.set(schema, entry); + this.cacheBySchemaDefinition.set(schema, entry); this.cacheById.set(id, entry); return entry; } diff --git a/sdk/schemaregistry/schema-registry-avro/test/schemaRegistryAvroSerializer.spec.ts b/sdk/schemaregistry/schema-registry-avro/test/schemaRegistryAvroSerializer.spec.ts index 5212248e97b8..65b03eb6db60 100644 --- a/sdk/schemaregistry/schema-registry-avro/test/schemaRegistryAvroSerializer.spec.ts +++ b/sdk/schemaregistry/schema-registry-avro/test/schemaRegistryAvroSerializer.spec.ts @@ -33,7 +33,7 @@ describe("SchemaRegistryAvroSerializer", function() { const serializer = await createTestSerializer(false, registry); const schema = await registry.registerSchema({ name: "_", - definition: "_", + schemaDefinition: "_", 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 813447bb4c3b..c5d29066d9a9 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.definition); + let result = mapByContent.get(schema.schemaDefinition); if (!result) { result = { id: newId(), - definition: schema.definition, + schemaDefinition: schema.schemaDefinition, version: 1, format: schema.format }; - mapByContent.set(result.definition, result); + mapByContent.set(result.schemaDefinition, 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.definition); + return mapByContent.get(schema.schemaDefinition); } 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 03ae167ba015..0882d8704238 100644 --- a/sdk/schemaregistry/schema-registry-avro/test/utils/mockedSerializer.ts +++ b/sdk/schemaregistry/schema-registry-avro/test/utils/mockedSerializer.ts @@ -20,7 +20,7 @@ export async function registerTestSchema(registry: SchemaRegistry): Promise", new DefaultAzureCredential()); +const client = new SchemaRegistryClient("", new DefaultAzureCredential()); ``` ## Key concepts @@ -77,13 +77,13 @@ schema registry. const { DefaultAzureCredential } = require("@azure/identity"); const { SchemaRegistryClient } = require("@azure/schema-registry"); -const client = new SchemaRegistryClient("", new DefaultAzureCredential()); +const client = new SchemaRegistryClient("", new DefaultAzureCredential()); const description = { name: "", groupName: "", - serializationType: "" - content: "" + format: "" + schemaDefinition: "" } const registered = await client.registerSchema(description); @@ -96,13 +96,13 @@ console.log(registered.id); const { DefaultAzureCredential } = require("@azure/identity"); const { SchemaRegistryClient } = require("@azure/schema-registry"); -const client = new SchemaRegistryClient("", new DefaultAzureCredential()); +const client = new SchemaRegistryClient("", new DefaultAzureCredential()); const description = { name: "", groupName: "", - serializationType: "" - content: "" + format: "" + schemaDefinition: "" } const found = await client.getSchemaId(description); @@ -111,16 +111,16 @@ if (found) { } ``` -### Get content of existing schema by ID +### Get definition of existing schema by ID ```javascript const { DefaultAzureCredential } = require("@azure/identity"); const { SchemaRegistryClient } = require("@azure/schema-registry"); -const client = new SchemaRegistryClient("", new DefaultAzureCredential()); +const client = new SchemaRegistryClient("", new DefaultAzureCredential()); const foundSchema = await client.getSchema(""); if (foundSchema) { - console.log(`Got schema content=${foundSchema.content}`); + console.log(`Got schema definition=${foundSchema.schemaDefinition}`); } ``` diff --git a/sdk/schemaregistry/schema-registry/recordings/browsers/schemaregistryclient/recording_sets_endpoint_in_constructor.json b/sdk/schemaregistry/schema-registry/recordings/browsers/schemaregistryclient/recording_sets_fully_qualified_name_space_in_constructor.json similarity index 65% rename from sdk/schemaregistry/schema-registry/recordings/browsers/schemaregistryclient/recording_sets_endpoint_in_constructor.json rename to sdk/schemaregistry/schema-registry/recordings/browsers/schemaregistryclient/recording_sets_fully_qualified_name_space_in_constructor.json index fce1b8571f31..6ae6b35679fc 100644 --- a/sdk/schemaregistry/schema-registry/recordings/browsers/schemaregistryclient/recording_sets_endpoint_in_constructor.json +++ b/sdk/schemaregistry/schema-registry/recordings/browsers/schemaregistryclient/recording_sets_fully_qualified_name_space_in_constructor.json @@ -4,5 +4,5 @@ "uniqueName": {}, "newDate": {} }, - "hash": "83dc1ff00845f199c7eb4bc9c91c3cf9" + "hash": "7915ecf70c0ddb88a6144f25578be8ec" } \ No newline at end of file diff --git a/sdk/schemaregistry/schema-registry/recordings/node/schemaregistryclient/recording_sets_endpoint_in_constructor.js b/sdk/schemaregistry/schema-registry/recordings/node/schemaregistryclient/recording_sets_fully_qualified_name_space_in_constructor.js similarity index 60% rename from sdk/schemaregistry/schema-registry/recordings/node/schemaregistryclient/recording_sets_endpoint_in_constructor.js rename to sdk/schemaregistry/schema-registry/recordings/node/schemaregistryclient/recording_sets_fully_qualified_name_space_in_constructor.js index e20ce3df5f2d..83a3e5755621 100644 --- a/sdk/schemaregistry/schema-registry/recordings/node/schemaregistryclient/recording_sets_endpoint_in_constructor.js +++ b/sdk/schemaregistry/schema-registry/recordings/node/schemaregistryclient/recording_sets_fully_qualified_name_space_in_constructor.js @@ -1,5 +1,5 @@ let nock = require('nock'); -module.exports.hash = "46c11a0b5cbacff73a981772862a4d39"; +module.exports.hash = "fd64a414b3181fffa22063279cd52e54"; module.exports.testInfo = {"uniqueName":{},"newDate":{}} diff --git a/sdk/schemaregistry/schema-registry/review/schema-registry.api.md b/sdk/schemaregistry/schema-registry/review/schema-registry.api.md index 577e849a5f2c..1e79bcebf0ca 100644 --- a/sdk/schemaregistry/schema-registry/review/schema-registry.api.md +++ b/sdk/schemaregistry/schema-registry/review/schema-registry.api.md @@ -27,15 +27,15 @@ export interface RegisterSchemaOptions extends OperationOptions { // @public export interface Schema extends SchemaProperties { - definition: string; + schemaDefinition: string; } // @public export interface SchemaDescription { - definition: string; format: string; groupName: string; name: string; + schemaDefinition: string; } // @public @@ -54,8 +54,8 @@ export interface SchemaRegistry { // @public export class SchemaRegistryClient implements SchemaRegistry { - constructor(endpoint: string, credential: TokenCredential, options?: SchemaRegistryClientOptions); - readonly endpoint: string; + constructor(fullyQualifiedNamespace: string, credential: TokenCredential, options?: SchemaRegistryClientOptions); + readonly fullyQualifiedNamespace: string; getSchema(id: string, options?: GetSchemaOptions): Promise; getSchemaProperties(schema: SchemaDescription, options?: GetSchemaPropertiesOptions): Promise; registerSchema(schema: SchemaDescription, options?: RegisterSchemaOptions): Promise; diff --git a/sdk/schemaregistry/schema-registry/samples-dev/schemaRegistrySample.ts b/sdk/schemaregistry/schema-registry/samples-dev/schemaRegistrySample.ts index b24a54bd5247..c0bfe8f7aacb 100644 --- a/sdk/schemaregistry/schema-registry/samples-dev/schemaRegistrySample.ts +++ b/sdk/schemaregistry/schema-registry/samples-dev/schemaRegistrySample.ts @@ -13,7 +13,8 @@ import * as dotenv from "dotenv"; dotenv.config(); // Set these environment variables or edit the following values -const endpoint = process.env["SCHEMA_REGISTRY_ENDPOINT"] || ""; +const fullyQualifiedNamespace = + process.env["SCHEMA_REGISTRY_ENDPOINT"] || ""; const group = process.env["SCHEMA_REGISTRY_GROUP"] || "AzureSdkSampleGroup"; // Sample Avro Schema for user with first and last names @@ -38,12 +39,12 @@ const schemaDescription: SchemaDescription = { name: `${schemaObject.namespace}.${schemaObject.name}`, groupName: group, format: "avro", - definition: JSON.stringify(schemaObject) + schemaDefinition: JSON.stringify(schemaObject) }; export async function main() { // Create a new client - const client = new SchemaRegistryClient(endpoint, new DefaultAzureCredential()); + const client = new SchemaRegistryClient(fullyQualifiedNamespace, new DefaultAzureCredential()); // Register a schema and get back its ID. const registered = await client.registerSchema(schemaDescription); @@ -56,10 +57,10 @@ export async function main() { console.log(`Got schema ID=${found.id}`); } - // Get content of existing schema by its ID + // Get definition of existing schema by its ID const foundSchema = await client.getSchema(registered.id); if (foundSchema) { - console.log(`Got schema content=${foundSchema.definition}`); + console.log(`Got schema definition=${foundSchema.schemaDefinition}`); } } diff --git a/sdk/schemaregistry/schema-registry/src/conversions.ts b/sdk/schemaregistry/schema-registry/src/conversions.ts index 1c227e9e3c79..5d78445302af 100644 --- a/sdk/schemaregistry/schema-registry/src/conversions.ts +++ b/sdk/schemaregistry/schema-registry/src/conversions.ts @@ -37,7 +37,7 @@ export function convertSchemaResponse( // https://github.com/Azure/azure-sdk-for-js/issues/11649 // Although response.body is typed as string, it is a parsed JSON object, // so we use _response.bodyAsText instead as a workaround. - return convertResponse(response, { definition: rawResponse.bodyAsText! }); + return convertResponse(response, { schemaDefinition: rawResponse.bodyAsText! }); } /** diff --git a/sdk/schemaregistry/schema-registry/src/models.ts b/sdk/schemaregistry/schema-registry/src/models.ts index 53efc6bf681d..a8847c2abaf7 100644 --- a/sdk/schemaregistry/schema-registry/src/models.ts +++ b/sdk/schemaregistry/schema-registry/src/models.ts @@ -21,7 +21,7 @@ export interface SchemaProperties { } /** - * Schema definition with its group, name, and serialization type. + * Schema definition with its name, format, and group. */ export interface SchemaDescription { /** Schema group under which schema is or should be registered. */ @@ -37,7 +37,7 @@ export interface SchemaDescription { format: string; /** String representation of schema. */ - definition: string; + schemaDefinition: string; } /** @@ -45,7 +45,7 @@ export interface SchemaDescription { */ export interface Schema extends SchemaProperties { /** String representation of schema. */ - definition: string; + schemaDefinition: string; } /** diff --git a/sdk/schemaregistry/schema-registry/src/schemaRegistryClient.ts b/sdk/schemaregistry/schema-registry/src/schemaRegistryClient.ts index 1cdf59548ca5..8093a11dee8d 100644 --- a/sdk/schemaregistry/schema-registry/src/schemaRegistryClient.ts +++ b/sdk/schemaregistry/schema-registry/src/schemaRegistryClient.ts @@ -27,8 +27,8 @@ import { getRawResponse } from "./utils"; * Client for Azure Schema Registry service. */ export class SchemaRegistryClient implements SchemaRegistry { - /** The Schema Registry service endpoint URL. */ - readonly endpoint: string; + /** The Schema Registry service fully qualified namespace URL. */ + readonly fullyQualifiedNamespace: string; /** Underlying autorest generated client. */ private readonly client: GeneratedSchemaRegistryClient; @@ -36,17 +36,17 @@ export class SchemaRegistryClient implements SchemaRegistry { /** * Creates a new client for Azure Schema Registry service. * - * @param endpoint - The Schema Registry service endpoint URL, for example - * https://mynamespace.servicebus.windows.net. + * @param fullyQualifiedNamespace - The Schema Registry service qualified namespace URL, for example + * https://mynamespace.servicebus.windows.net. * @param credential - Credential to authenticate requests to the service. * @param options - Options to configure API requests to the service. */ constructor( - endpoint: string, + fullyQualifiedNamespace: string, credential: TokenCredential, options: SchemaRegistryClientOptions = {} ) { - this.endpoint = endpoint; + this.fullyQualifiedNamespace = fullyQualifiedNamespace; const internalPipelineOptions: InternalPipelineOptions = { ...options, @@ -57,8 +57,8 @@ export class SchemaRegistryClient implements SchemaRegistry { } }; - this.client = new GeneratedSchemaRegistryClient(this.endpoint, { - endpoint: this.endpoint, + this.client = new GeneratedSchemaRegistryClient(this.fullyQualifiedNamespace, { + endpoint: this.fullyQualifiedNamespace, ...internalPipelineOptions }); @@ -81,7 +81,7 @@ export class SchemaRegistryClient implements SchemaRegistry { options?: RegisterSchemaOptions ): Promise { return this.client.schema - .register(schema.groupName, schema.name, schema.format, schema.definition, options) + .register(schema.groupName, schema.name, schema.format, schema.schemaDefinition, options) .then(convertSchemaIdResponse); } @@ -97,7 +97,13 @@ export class SchemaRegistryClient implements SchemaRegistry { options?: GetSchemaPropertiesOptions ): Promise { return this.client.schema - .queryIdByContent(schema.groupName, schema.name, schema.format, schema.definition, options) + .queryIdByContent( + schema.groupName, + schema.name, + schema.format, + schema.schemaDefinition, + options + ) .then(convertSchemaIdResponse); } diff --git a/sdk/schemaregistry/schema-registry/test/public/schemaRegistry.spec.ts b/sdk/schemaregistry/schema-registry/test/public/schemaRegistry.spec.ts index b0cca118d3a1..c35165ac44fd 100644 --- a/sdk/schemaregistry/schema-registry/test/public/schemaRegistry.spec.ts +++ b/sdk/schemaregistry/schema-registry/test/public/schemaRegistry.spec.ts @@ -47,7 +47,7 @@ describe("SchemaRegistryClient", function() { name: "azsdk_js_test", groupName: env.SCHEMA_REGISTRY_GROUP, format: "avro", - definition: JSON.stringify({ + schemaDefinition: JSON.stringify({ type: "record", name: "User", namespace: "com.azure.schemaregistry.samples", @@ -69,18 +69,18 @@ describe("SchemaRegistryClient", function() { await recorder.stop(); }); - it("sets endpoint in constructor", () => { - const endpoint = "https://example.com/schemaregistry/"; + it("sets fully qualified name space in constructor", () => { + const fullyQualifiedNamespace = "https://example.com/schemaregistry/"; const credential = new ClientSecretCredential("x", "y", "z"); - const customClient = new SchemaRegistryClient(endpoint, credential); - assert.equal(customClient.endpoint, endpoint); + const customClient = new SchemaRegistryClient(fullyQualifiedNamespace, credential); + assert.equal(customClient.fullyQualifiedNamespace, fullyQualifiedNamespace); }); 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, definition: null! }), /null/); + await assert.isRejected(client.registerSchema({ ...schema, schemaDefinition: null! }), /null/); await assert.isRejected(client.registerSchema({ ...schema, format: null! }), /null/); await assert.isRejected(client.registerSchema({ ...schema, format: "not-valid" }), /not-valid/); }); @@ -93,7 +93,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, definition: null! }), /null/); + await assert.isRejected( + client.getSchemaProperties({ ...schema, schemaDefinition: null! }), + /null/ + ); await assert.isRejected(client.getSchemaProperties({ ...schema, format: null! }), /null/); await assert.isRejected( client.getSchemaProperties({ ...schema, format: "not-valid" }), @@ -129,7 +132,7 @@ describe("SchemaRegistryClient", function() { const found = await client.getSchema(registered.id, options); assertIsValidSchemaId(found); - assert.equal(found.definition, schema.definition); + assert.equal(found.schemaDefinition, schema.schemaDefinition); }); it("schema with whitespace", async () => { @@ -137,7 +140,7 @@ describe("SchemaRegistryClient", function() { name: "azsdk_js_test2", groupName: env.SCHEMA_REGISTRY_GROUP, format: "avro", - definition: + schemaDefinition: "{\n" + ' "type": "record",\n' + ' "name": "Test",\n' + @@ -151,11 +154,11 @@ describe("SchemaRegistryClient", function() { const foundSchema = await client.getSchema(registered.id); assertIsValidSchemaId(foundSchema); // the schema comes from the service normalized - assert.equal(foundSchema.definition, schema2.definition.replace(/\s/g, "")); + assert.equal(foundSchema.schemaDefinition, schema2.schemaDefinition.replace(/\s/g, "")); const foundId = await client.getSchemaProperties({ - // content that comes from the service does not have whitespaces - definition: foundSchema.definition, + // definition that comes from the service does not have whitespaces + schemaDefinition: foundSchema.schemaDefinition, groupName: schema2.groupName, name: schema2.name, format: foundSchema.format