Skip to content

Commit

Permalink
[Schema Registry] Rename definition to schemaDefinition (#17919)
Browse files Browse the repository at this point in the history
* [Schema Registry] Rename definition to schemaDefinition

* rename endpoint to fullyQualifiedNamespace

* rename endpoint everywhere

* more renamings

* renames in the avro lib

* unpublish samples

* unpublish samples
  • Loading branch information
deyaaeldeen authored Sep 28, 2021
1 parent 0ad4ea3 commit 49f8480
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 68 deletions.
2 changes: 1 addition & 1 deletion sdk/schemaregistry/schema-registry-avro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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
@@ -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 @@ -114,7 +114,7 @@ export class SchemaRegistryAvroSerializer {
* @returns A new buffer with the serialized value
*/
async serialize(value: unknown, schema: string): Promise<Uint8Array> {
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);

Expand Down Expand Up @@ -155,7 +155,7 @@ export class SchemaRegistryAvroSerializer {
return schema.type.fromBuffer(payloadBuffer);
}

private readonly cacheByContent = new Map<string, CacheEntry>();
private readonly cacheBySchemaDefinition = new Map<string, CacheEntry>();
private readonly cacheById = new Map<string, CacheEntry>();

private async getSchema(schemaId: string): Promise<CacheEntry> {
Expand All @@ -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<CacheEntry> {
const cached = this.cacheByContent.get(schema);
private async getSchemaByDefinition(schema: string): Promise<CacheEntry> {
const cached = this.cacheBySchemaDefinition.get(schema);
if (cached) {
return cached;
}
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 All @@ -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;
Expand All @@ -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;
}
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
22 changes: 11 additions & 11 deletions sdk/schemaregistry/schema-registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ npm install @azure/schema-registry
### Create and authenticate a `SchemaRegistryClient`

To create a client object to access the Schema Registry API, you will need the
`endpoint` of your Schema Registry resource and a `credential`. The Schema
fully qualified namespace of your Schema Registry resource and a `credential`. The Schema
Registry client uses Azure Active Directory credentials to authenticate.

You can authenticate with Azure Active Directory using the [Azure Identity
Expand All @@ -53,7 +53,7 @@ application as environment variables: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`,
const { DefaultAzureCredential } = require("@azure/identity");
const { SchemaRegistryClient } = require("@azure/schema-registry");

const client = new SchemaRegistryClient("<endpoint>", new DefaultAzureCredential());
const client = new SchemaRegistryClient("<fullyQualifiedNamespace>", new DefaultAzureCredential());
```

## Key concepts
Expand All @@ -77,13 +77,13 @@ schema registry.
const { DefaultAzureCredential } = require("@azure/identity");
const { SchemaRegistryClient } = require("@azure/schema-registry");

const client = new SchemaRegistryClient("<endpoint>", new DefaultAzureCredential());
const client = new SchemaRegistryClient("<fullyQualifiedNamespace>", new DefaultAzureCredential());

const description = {
name: "<name>",
groupName: "<group name>",
serializationType: "<serialization type>"
content: "<schema content>"
format: "<schema format>"
schemaDefinition: "<schema definition>"
}

const registered = await client.registerSchema(description);
Expand All @@ -96,13 +96,13 @@ console.log(registered.id);
const { DefaultAzureCredential } = require("@azure/identity");
const { SchemaRegistryClient } = require("@azure/schema-registry");

const client = new SchemaRegistryClient("<endpoint>", new DefaultAzureCredential());
const client = new SchemaRegistryClient("<fullyQualifiedNamespace>", new DefaultAzureCredential());

const description = {
name: "<name>",
groupName: "<group name>",
serializationType: "<serialization type>"
content: "<schema content>"
format: "<schema format>"
schemaDefinition: "<schema definition>"
}

const found = await client.getSchemaId(description);
Expand All @@ -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("<endpoint>", new DefaultAzureCredential());
const client = new SchemaRegistryClient("<fullyQualifiedNamespace>", new DefaultAzureCredential());
const foundSchema = await client.getSchema("<id>");
if (foundSchema) {
console.log(`Got schema content=${foundSchema.content}`);
console.log(`Got schema definition=${foundSchema.schemaDefinition}`);
}
```

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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,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<Schema>;
getSchemaProperties(schema: SchemaDescription, options?: GetSchemaPropertiesOptions): Promise<SchemaProperties>;
registerSchema(schema: SchemaDescription, options?: RegisterSchemaOptions): Promise<SchemaProperties>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"] || "<endpoint>";
const fullyQualifiedNamespace =
process.env["SCHEMA_REGISTRY_ENDPOINT"] || "<fullyQualifiedNamespace>";
const group = process.env["SCHEMA_REGISTRY_GROUP"] || "AzureSdkSampleGroup";

// Sample Avro Schema for user with first and last names
Expand All @@ -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);
Expand All @@ -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}`);
}
}

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
6 changes: 3 additions & 3 deletions sdk/schemaregistry/schema-registry/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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
Loading

0 comments on commit 49f8480

Please sign in to comment.