Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Schema Registry] Rename definition to schemaDefinition #17919

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const schemaDescription: SchemaDescription = {
name: `${schemaObject.namespace}.${schemaObject.name}`,
groupName,
format: "avro",
definition: schema
schemaDefinition: schema
};

export async function main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"@azure/schema-registry-avro": "next",
"dotenv": "latest",
"@azure/identity": "2.0.0-beta.5",
"@azure/schema-registry": "1.0.0-beta.2"
"@azure/identity": "2.0.0-beta.6",
"@azure/schema-registry": "1.0.0-beta.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dotenv.config();

// Set these environment variables or edit the following values
const endpoint = process.env["SCHEMA_REGISTRY_ENDPOINT"] || "<endpoint>";
const group = process.env["SCHEMA_REGISTRY_GROUP"] || "AzureSdkSampleGroup";
const groupName = process.env["SCHEMA_REGISTRY_GROUP"] || "AzureSdkSampleGroup";

// Sample Avro Schema for user with first and last names
const schemaObject = {
Expand All @@ -39,9 +39,9 @@ const schema = JSON.stringify(schemaObject);
// Description of the schema for registration
const schemaDescription = {
name: `${schemaObject.namespace}.${schemaObject.name}`,
group,
serializationType: "avro",
content: schema
groupName,
format: "avro",
schemaDefinition: schema
};

async function main() {
Expand All @@ -54,7 +54,7 @@ async function main() {
await client.registerSchema(schemaDescription);

// Create a new serializer backed by the client
const serializer = new SchemaRegistryAvroSerializer(client, group);
const serializer = new SchemaRegistryAvroSerializer(client, groupName);

// serialize an object that matches the schema
const value = { firstName: "Jane", lastName: "Doe" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"dependencies": {
"@azure/schema-registry-avro": "next",
"dotenv": "latest",
"@azure/identity": "2.0.0-beta.5",
"@azure/schema-registry": "1.0.0-beta.2"
"@azure/identity": "2.0.0-beta.6",
"@azure/schema-registry": "1.0.0-beta.3"
},
"devDependencies": {
"typescript": "~4.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dotenv.config();

// Set these environment variables or edit the following values
const endpoint = process.env["SCHEMA_REGISTRY_ENDPOINT"] || "<endpoint>";
const group = process.env["SCHEMA_REGISTRY_GROUP"] || "AzureSdkSampleGroup";
const groupName = process.env["SCHEMA_REGISTRY_GROUP"] || "AzureSdkSampleGroup";

// Sample Avro Schema for user with first and last names
const schemaObject = {
Expand Down Expand Up @@ -45,9 +45,9 @@ const schema = JSON.stringify(schemaObject);
// Description of the schema for registration
const schemaDescription: SchemaDescription = {
name: `${schemaObject.namespace}.${schemaObject.name}`,
group,
serializationType: "avro",
content: schema
groupName,
format: "avro",
schemaDefinition: schema
};

export async function main() {
Expand All @@ -60,7 +60,7 @@ export async function main() {
await client.registerSchema(schemaDescription);

// Create a new serializer backed by the client
const serializer = new SchemaRegistryAvroSerializer(client, group);
const serializer = new SchemaRegistryAvroSerializer(client, groupName);

// serialize an object that matches the schema
const value: User = { firstName: "Jane", lastName: "Doe" };
Expand All @@ -69,7 +69,7 @@ export async function main() {
console.log(buffer);

// deserialize the result back to an object
const deserializedValue = await serializer.deserialize<User>(buffer);
const deserializedValue = (await serializer.deserialize(buffer)) as User;
console.log("Deserialized:");
console.log(`${deserializedValue.firstName} ${deserializedValue.lastName}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -175,8 +175,8 @@ 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<CacheEntry> {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ export function createTestRegistry(neverLive = false): SchemaRegistry {
schema: SchemaDescription,
_options?: RegisterSchemaOptions
): Promise<SchemaProperties> {
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;
Expand All @@ -62,7 +62,7 @@ export function createTestRegistry(neverLive = false): SchemaRegistry {
schema: SchemaDescription,
_options?: GetSchemaPropertiesOptions
): Promise<SchemaProperties | undefined> {
return mapByContent.get(schema.definition);
return mapByContent.get(schema.schemaDefinition);
}

async function getSchema(id: string, _options?: GetSchemaOptions): Promise<Schema | undefined> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function registerTestSchema(registry: SchemaRegistry): Promise<stri
const schema = await registry.registerSchema({
name: `${testSchemaObject.namespace}.${testSchemaObject.name}`,
groupName: testGroup,
definition: testSchema,
schemaDefinition: testSchema,
format: "avro"
});
return schema.id;
Expand Down
2 changes: 1 addition & 1 deletion sdk/schemaregistry/schema-registry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- renames `getSchemaById` to `getSchema`
- renames `GetSchemaByIdOptions` to `GetSchemaOptions`
- `getSchema` and `getSchemaProperties` no longer return `undefined` if the schema was not registered
- renames `content` to `definition`, `serializationType` to `format`, and `KnownSerializationType` to `KnownSchemaFormat`
- renames `content` to `schemaDefinition`, `serializationType` to `format`, and `KnownSerializationType` to `KnownSchemaFormat`

### Bugs Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,7 +54,7 @@ export interface SchemaRegistry {

// @public
export class SchemaRegistryClient implements SchemaRegistry {
constructor(endpoint: string, credential: TokenCredential, options?: SchemaRegistryClientOptions);
constructor(fullyQualifiedNamespace: string, credential: TokenCredential, options?: SchemaRegistryClientOptions);
readonly endpoint: string;
getSchema(id: string, options?: GetSchemaOptions): Promise<Schema>;
getSchemaProperties(schema: SchemaDescription, options?: GetSchemaPropertiesOptions): Promise<SchemaProperties>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const schemaDescription: SchemaDescription = {
name: `${schemaObject.namespace}.${schemaObject.name}`,
groupName: group,
format: "avro",
definition: JSON.stringify(schemaObject)
schemaDefinition: JSON.stringify(schemaObject)
};

export async function main() {
Expand All @@ -59,7 +59,7 @@ export async function main() {
// Get content 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 content=${foundSchema.schemaDefinition}`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const schemaDescription = {
name: `${schemaObject.namespace}.${schemaObject.name}`,
groupName: group,
format: "avro",
definition: JSON.stringify(schemaObject)
schemaDefinition: JSON.stringify(schemaObject)
};

async function main() {
Expand All @@ -59,7 +59,7 @@ async function main() {
// Get content 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 content=${foundSchema.schemaDefinition}`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const schemaDescription: SchemaDescription = {
name: `${schemaObject.namespace}.${schemaObject.name}`,
groupName: group,
format: "avro",
definition: JSON.stringify(schemaObject)
schemaDefinition: JSON.stringify(schemaObject)
};

export async function main() {
Expand All @@ -59,7 +59,7 @@ export async function main() {
// Get content 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 content=${foundSchema.schemaDefinition}`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/schemaregistry/schema-registry/src/conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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! });
}

/**
Expand Down
4 changes: 2 additions & 2 deletions sdk/schemaregistry/schema-registry/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ export interface SchemaDescription {
format: string;

/** String representation of schema. */
definition: string;
schemaDefinition: string;
}

/**
* Schema definition with its unique ID, version, and location.
*/
export interface Schema extends SchemaProperties {
/** String representation of schema. */
definition: string;
schemaDefinition: string;
}

/**
Expand Down
18 changes: 12 additions & 6 deletions sdk/schemaregistry/schema-registry/src/schemaRegistryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.endpoint = fullyQualifiedNamespace;

const internalPipelineOptions: InternalPipelineOptions = {
...options,
Expand Down Expand Up @@ -81,7 +81,7 @@ export class SchemaRegistryClient implements SchemaRegistry {
options?: RegisterSchemaOptions
): Promise<SchemaProperties> {
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);
}

Expand All @@ -97,7 +97,13 @@ export class SchemaRegistryClient implements SchemaRegistry {
options?: GetSchemaPropertiesOptions
): Promise<SchemaProperties> {
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);
}

Expand Down
Loading