Skip to content

Commit

Permalink
fix: change schema.uid() method to schema.id() (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
smoya authored Oct 6, 2022
1 parent 4aaf6d0 commit 97c61cb
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/custom-operations/anonymous-naming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function assignNameToAnonymousMessages(document: AsyncAPIDocumentInterface) {
function assignUidToComponentParameterSchemas(document: AsyncAPIDocumentInterface) {
document.components().channelParameters().forEach(parameter => {
const schema = parameter.schema();
if (schema && !schema.uid()) {
if (schema && !schema.id()) {
setExtension(xParserSchemaId, parameter.id(), schema);
}
});
Expand All @@ -47,7 +47,7 @@ function assignUidToChannelParameterSchemas(document: AsyncAPIDocumentInterface)
document.channels().forEach(channel => {
channel.parameters().forEach(parameter => {
const schema = parameter.schema();
if (schema && !schema.uid()) {
if (schema && !schema.id()) {
setExtension(xParserSchemaId, parameter.id(), schema);
}
});
Expand All @@ -56,14 +56,14 @@ function assignUidToChannelParameterSchemas(document: AsyncAPIDocumentInterface)

function assignUidToComponentSchemas(document: AsyncAPIDocumentInterface) {
document.components().schemas().forEach(schema => {
setExtension(xParserSchemaId, schema.uid(), schema);
setExtension(xParserSchemaId, schema.id(), schema);
});
}

function assignUidToAnonymousSchemas(doc: AsyncAPIDocumentInterface) {
let anonymousSchemaCounter = 0;
function callback(schema: SchemaInterface) {
if (!schema.uid()) {
if (!schema.id()) {
setExtension(xParserSchemaId, `<anonymous-schema-${++anonymousSchemaCounter}>`, schema);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { ExtensionsMixinInterface, ExternalDocumentationMixinInterface } fr
import type { v2 } from '../spec-types';

export interface SchemaInterface extends BaseModel<v2.AsyncAPISchemaObject>, ExtensionsMixinInterface, ExternalDocumentationMixinInterface {
uid(): string;
$comment(): string | undefined;
$id(): string | undefined;
$schema(): string;
Expand All @@ -27,6 +26,7 @@ export interface SchemaInterface extends BaseModel<v2.AsyncAPISchemaObject>, Ext
exclusiveMaximum(): number | undefined;
exclusiveMinimum(): number | undefined;
format(): string | undefined;
id(): string;
isBooleanSchema(): boolean;
if(): SchemaInterface | undefined;
isCircular(): boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/models/v2/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Schema extends BaseModel<v2.AsyncAPISchemaObject, { id?: string, pa
super(_json, _meta);
}

uid(): string {
id(): string {
return this._meta.id || this.json(xParserSchemaId as any) as string;
}

Expand Down
2 changes: 1 addition & 1 deletion src/models/v2/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import type { SchemaInterface } from '../schema';

export class Schemas extends Collection<SchemaInterface> implements SchemasInterface {
override get(id: string): SchemaInterface | undefined {
return this.collections.find(schema => schema.uid() === id);
return this.collections.find(schema => schema.id() === id);
}
}
2 changes: 1 addition & 1 deletion test/models/v2/schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Channel model', function() {
it('should return id of model', function() {
const doc = {};
const d = new Schema(doc, { asyncapi: {} as any, pointer: '', id: 'schema' });
expect(d.uid()).toEqual('schema');
expect(d.id()).toEqual('schema');
});
});

Expand Down

0 comments on commit 97c61cb

Please sign in to comment.