Skip to content

Commit

Permalink
refactor: fix some bugs and smells (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
smoya authored and derberg committed Oct 4, 2022
1 parent 912b876 commit 7d650d8
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/models/v2/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class Channel extends BaseModel<v2.ChannelObject, { id: string, address:
servers(): ServersInterface {
const servers: ServerInterface[] = [];
const allowedServers: string[] = this._json.servers || [];
Object.entries(this._meta.asyncapi?.parsed.servers || {}).map(([serverName, server]) => {
Object.entries(this._meta.asyncapi?.parsed.servers || {}).forEach(([serverName, server]) => {
if (allowedServers.length === 0 || allowedServers.includes(serverName)) {
servers.push(this.createModel(Server, server, { id: serverName, pointer: `/servers/${serverName}` }));
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/v2/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class Server extends BaseModel<v2.ServerObject, { id: string }> implement

channels(): ChannelsInterface {
const channels: ChannelInterface[] = [];
Object.entries(this._meta.asyncapi?.parsed.channels || {}).map(([channelAddress, channel]: [string, any]) => {
Object.entries(this._meta.asyncapi?.parsed.channels || {}).forEach(([channelAddress, channel]: [string, any]) => {
const allowedServers: string[] = channel.servers || [];
if (allowedServers.length === 0 || allowedServers.includes(this._meta.id)) {
channels.push(this.createModel(Channel, channel, { id: channelAddress, address: channelAddress, pointer: `/channels/${tilde(channelAddress)}` }));
Expand Down
4 changes: 2 additions & 2 deletions src/schema-parser/avro-schema-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { AsyncAPISchema, SchemaValidateResult } from '../types';

import type { v2 } from '../spec-types';

type AvroSchema = Schema & { [key: string]: any } & any;
type AvroSchema = Schema & { [key: string]: any };

export function AvroSchemaParser(): SchemaParser {
return {
Expand Down Expand Up @@ -321,7 +321,7 @@ async function processRecordSchema(avroDefinition: AvroSchema, recordCache: Reco
async function processUnionSchema(jsonSchema: v2.AsyncAPISchemaDefinition, avroDefinition: AvroSchema, isTopLevel: boolean, recordCache: Record<string, v2.AsyncAPISchemaDefinition>): Promise<v2.AsyncAPISchemaDefinition> {
jsonSchema.oneOf = [];
let nullDef = null;
for (const avroDef of avroDefinition) {
for (const avroDef of avroDefinition as any) {
const def = await convertAvroToJsonSchema(avroDef, isTopLevel, recordCache);
// avroDef can be { type: 'int', default: 1 } and this is why avroDef.type has priority here
const defType = avroDef.type || avroDef;
Expand Down
2 changes: 1 addition & 1 deletion src/spec-types/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export interface AsyncAPISchemaDefinition extends SpecificationExtensions {
default?: JSONSchema7Type;
readOnly?: boolean;
writeOnly?: boolean;
examples?: Array<JSONSchema7Type> | undefined;
examples?: Array<JSONSchema7Type>;

discriminator?: string;
externalDocs?: ExternalDocumentationObject;
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function untilde(str: string) {
});
}

export function retrievePossibleRef(data: any & { $ref?: string }, pathOfData: string, spec: any = {}): any {
export function retrievePossibleRef(data: any, pathOfData: string, spec: any = {}): any {
if (!hasRef(data)) {
return data;
}
Expand Down

0 comments on commit 7d650d8

Please sign in to comment.