Skip to content

Commit

Permalink
[Schema Registry] Apply Archboard requested renames (#17720)
Browse files Browse the repository at this point in the history
* [Schema Registry] Apply Archboard requested renames

* edit

* more renamings
  • Loading branch information
deyaaeldeen authored Sep 17, 2021
1 parent 3a610f2 commit 6a350c6
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CacheEntry> {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

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.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;
Expand All @@ -62,7 +62,7 @@ export function createTestRegistry(neverLive = false): SchemaRegistry {
schema: SchemaDescription,
_options?: GetSchemaPropertiesOptions
): Promise<SchemaProperties | undefined> {
return mapByContent.get(schema.content);
return mapByContent.get(schema.definition);
}

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,8 +20,8 @@ export async function registerTestSchema(registry: SchemaRegistry): Promise<stri
const schema = await registry.registerSchema({
name: `${testSchemaObject.namespace}.${testSchemaObject.name}`,
groupName: testGroup,
content: testSchema,
serializationType: "avro"
definition: testSchema,
format: "avro"
});
return schema.id;
}
1 change: 1 addition & 0 deletions sdk/schemaregistry/schema-registry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +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`

### Bugs Fixed

Expand Down
10 changes: 5 additions & 5 deletions sdk/schemaregistry/schema-registry/review/schema-registry.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface GetSchemaPropertiesOptions extends OperationOptions {
}

// @public
export const enum KnownSerializationType {
export const enum KnownSchemaFormat {
Avro = "avro"
}

Expand All @@ -27,21 +27,21 @@ export interface RegisterSchemaOptions extends OperationOptions {

// @public
export interface Schema extends SchemaProperties {
content: string;
definition: string;
}

// @public
export interface SchemaDescription {
content: string;
definition: string;
format: string;
groupName: string;
name: string;
serializationType: string;
}

// @public
export interface SchemaProperties {
format: string;
id: string;
serializationType: string;
version: number;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const schemaObject = {
const schemaDescription: SchemaDescription = {
name: `${schemaObject.namespace}.${schemaObject.name}`,
groupName: group,
serializationType: "avro",
content: JSON.stringify(schemaObject)
format: "avro",
definition: 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.content}`);
console.log(`Got schema content=${foundSchema.definition}`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"dependencies": {
"@azure/schema-registry": "next",
"dotenv": "latest",
"@azure/identity": "2.0.0-beta.4"
"@azure/identity": "2.0.0-beta.6"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ const schemaObject = {
// Description of the schema for registration
const schemaDescription = {
name: `${schemaObject.namespace}.${schemaObject.name}`,
group,
serializationType: "avro",
content: JSON.stringify(schemaObject)
groupName: group,
format: "avro",
definition: JSON.stringify(schemaObject)
};

async function main() {
Expand All @@ -51,15 +51,15 @@ async function main() {

// Get ID for existing schema by its description.
// Note that this would throw if it had not been previously registered.
const found = await client.getSchemaId(schemaDescription);
const found = await client.getSchemaProperties(schemaDescription);
if (found) {
console.log(`Got schema ID=${found.id}`);
}

// Get content of existing schema by its ID
const foundSchema = await client.getSchema(registered.id);
if (foundSchema) {
console.log(`Got schema content=${foundSchema.content}`);
console.log(`Got schema content=${foundSchema.definition}`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@azure/schema-registry": "next",
"dotenv": "latest",
"@azure/identity": "2.0.0-beta.5"
"@azure/identity": "2.0.0-beta.6"
},
"devDependencies": {
"typescript": "~4.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ const schemaObject = {
// Description of the schema for registration
const schemaDescription: SchemaDescription = {
name: `${schemaObject.namespace}.${schemaObject.name}`,
group,
serializationType: "avro",
content: JSON.stringify(schemaObject)
groupName: group,
format: "avro",
definition: 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.content}`);
console.log(`Got schema content=${foundSchema.definition}`);
}
}

Expand Down
10 changes: 5 additions & 5 deletions sdk/schemaregistry/schema-registry/src/conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import { SchemaProperties, Schema } from "./models";
import {
SchemaGetByIdResponse,
SchemaRegisterResponse,
SchemaQueryIdByContentResponse
SchemaQueryIdByContentResponse as SchemaQueryIdByDefinitionResponse
} from "./generated/models";
import { FullOperationResponse } from "@azure/core-client";

/**
* Union of generated client's responses that return schema content.
* Union of generated client's responses that return schema definition.
*/
type GeneratedSchemaResponse = SchemaGetByIdResponse;

/**
* Union of generated client's responses that return schema ID.
*/
type GeneratedSchemaIdResponse = SchemaRegisterResponse | SchemaQueryIdByContentResponse;
type GeneratedSchemaIdResponse = SchemaRegisterResponse | SchemaQueryIdByDefinitionResponse;

/**
* Union of all generated client's responses.
Expand All @@ -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, { content: rawResponse.bodyAsText! });
return convertResponse(response, { definition: rawResponse.bodyAsText! });
}

/**
Expand All @@ -60,7 +60,7 @@ function convertResponse<T>(
// is not modeled by the generated client.
id: response.schemaId!,
version: response.schemaVersion!,
serializationType: response.serializationType!,
format: response.serializationType!,
...additionalProperties
};
}
2 changes: 1 addition & 1 deletion sdk/schemaregistry/schema-registry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

export * from "./models";
export { SchemaRegistryClient } from "./schemaRegistryClient";
export { KnownSerializationType } from "./generated";
export { KnownSerializationType as KnownSchemaFormat } from "./generated";
14 changes: 7 additions & 7 deletions sdk/schemaregistry/schema-registry/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,21 +31,21 @@ 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;
}

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

/**
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 4 additions & 10 deletions sdk/schemaregistry/schema-registry/src/schemaRegistryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

/**
Expand All @@ -91,15 +91,15 @@ export class SchemaRegistryClient implements SchemaRegistry {
options?: RegisterSchemaOptions
): Promise<SchemaProperties> {
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;
}

/**
* 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.
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 6a350c6

Please sign in to comment.