Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@asyncapi/parser

Package Overview
Dependencies
Maintainers
3
Versions
170
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asyncapi/parser - npm Package Compare versions

Comparing version 2.1.0-next-major-spec.3 to 2.1.0

cjs/ruleset/v2/functions/messageExamples-spectral-rule-v2.d.ts

4

cjs/custom-operations/apply-traits.d.ts

@@ -1,3 +0,3 @@

import type { v2, v3 } from '../spec-types';
import type { v2 } from '../spec-types';
export declare function applyTraitsV2(asyncapi: v2.AsyncAPIObject): void;
export declare function applyTraitsV3(asyncapi: v3.AsyncAPIObject): void;
export declare function applyTraitsV3(asyncapi: v2.AsyncAPIObject): void;

@@ -18,47 +18,21 @@ "use strict";

function applyTraitsV2(asyncapi) {
applyAllTraitsV2(asyncapi, v2TraitPaths);
applyAllTraits(asyncapi, v2TraitPaths);
}
exports.applyTraitsV2 = applyTraitsV2;
function applyAllTraitsV2(asyncapi, paths) {
const visited = new Set();
paths.forEach(path => {
(0, jsonpath_plus_1.JSONPath)({
path,
json: asyncapi,
resultType: 'value',
callback(value) {
if (visited.has(value)) {
return;
}
visited.add(value);
applyTraitsToObjectV2(value);
},
});
});
}
function applyTraitsToObjectV2(value) {
if (Array.isArray(value.traits)) {
for (const trait of value.traits) {
for (const key in trait) {
value[String(key)] = (0, utils_1.mergePatch)(value[String(key)], trait[String(key)]);
}
}
}
}
const v3TraitPaths = [
// operations
'$.operations.*',
'$.components.operations.*',
'$.channels.*.[publish,subscribe]',
'$.components.channels.*.[publish,subscribe]',
// messages
'$.channels.*.messages.*',
'$.operations.*.messages.*',
'$.components.channels.*.messages.*',
'$.components.operations.*.messages.*',
'$.channels.*.[publish,subscribe].message',
'$.channels.*.[publish,subscribe].message.oneOf.*',
'$.components.channels.*.[publish,subscribe].message',
'$.components.channels.*.[publish,subscribe].message.oneOf.*',
'$.components.messages.*',
];
function applyTraitsV3(asyncapi) {
applyAllTraitsV3(asyncapi, v3TraitPaths);
applyAllTraits(asyncapi, v3TraitPaths);
}
exports.applyTraitsV3 = applyTraitsV3;
function applyAllTraitsV3(asyncapi, paths) {
function applyAllTraits(asyncapi, paths) {
const visited = new Set();

@@ -75,3 +49,3 @@ paths.forEach(path => {

visited.add(value);
applyTraitsToObjectV3(value);
applyTraits(value);
},

@@ -81,18 +55,10 @@ });

}
function applyTraitsToObjectV3(value) {
if (!Array.isArray(value.traits)) {
return;
}
// shallow copy of object
const copy = Object.assign({}, value);
// reset the object but preserve the reference
for (const key in value) {
delete value[key];
}
// merge root object at the end
for (const trait of [...copy.traits, copy]) {
for (const key in trait) {
value[String(key)] = (0, utils_1.mergePatch)(value[String(key)], trait[String(key)]);
function applyTraits(value) {
if (Array.isArray(value.traits)) {
for (const trait of value.traits) {
for (const key in trait) {
value[String(key)] = (0, utils_1.mergePatch)(value[String(key)], trait[String(key)]);
}
}
}
}

@@ -14,6 +14,5 @@ "use strict";

const apply_traits_1 = require("./apply-traits");
const check_circular_refs_1 = require("./check-circular-refs");
const resolve_circular_refs_1 = require("./resolve-circular-refs");
const parse_schema_1 = require("./parse-schema");
const anonymous_naming_1 = require("./anonymous-naming");
const resolve_circular_refs_1 = require("./resolve-circular-refs");
function customOperations(parser, document, detailed, inventory, options) {

@@ -23,3 +22,3 @@ return __awaiter(this, void 0, void 0, function* () {

case 2: return operationsV2(parser, document, detailed, inventory, options);
case 3: return operationsV3(parser, document, detailed, inventory, options);
// case 3: return operationsV3(parser, document, detailed, options);
}

@@ -31,3 +30,2 @@ });

return __awaiter(this, void 0, void 0, function* () {
(0, check_circular_refs_1.checkCircularRefs)(document);
if (options.applyTraits) {

@@ -46,14 +44,1 @@ (0, apply_traits_1.applyTraitsV2)(detailed.parsed);

}
function operationsV3(parser, document, detailed, inventory, options) {
return __awaiter(this, void 0, void 0, function* () {
(0, check_circular_refs_1.checkCircularRefs)(document);
if (options.applyTraits) {
(0, apply_traits_1.applyTraitsV3)(detailed.parsed);
}
// TODO: Support schema parsing in v3
// if (options.parseSchemas) {
// await parseSchemasV2(parser, detailed);
// }
(0, anonymous_naming_1.anonymousNaming)(document);
});
}

@@ -12,4 +12,4 @@ "use strict";

return new models_1.AsyncAPIDocumentV2(asyncapi.parsed, { asyncapi, pointer: '/' });
case 3:
return new models_1.AsyncAPIDocumentV3(asyncapi.parsed, { asyncapi, pointer: '/' });
// case 3:
// return new AsyncAPIDocumentV3(asyncapi.parsed, { asyncapi, pointer: '/' });
default:

@@ -16,0 +16,0 @@ throw new Error(`Unsupported AsyncAPI version: ${asyncapi.semver.version}`);

@@ -11,4 +11,4 @@ import type { BaseModel } from './base';

import type { ServersInterface } from './servers';
import type { v2, v3 } from '../spec-types';
export interface AsyncAPIDocumentInterface extends BaseModel<v2.AsyncAPIObject | v3.AsyncAPIObject>, ExtensionsMixinInterface {
import type { v2 } from '../spec-types';
export interface AsyncAPIDocumentInterface extends BaseModel<v2.AsyncAPIObject>, ExtensionsMixinInterface {
version(): string;

@@ -15,0 +15,0 @@ defaultContentType(): string | undefined;

@@ -9,3 +9,3 @@ import type { BaseModel } from './base';

id(): string;
address(): string | null | undefined;
address(): string;
servers(): ServersInterface;

@@ -12,0 +12,0 @@ operations(): OperationsInterface;

@@ -8,4 +8,3 @@ import type { BaseModel } from './base';

id(): string;
hasSchemaFormat(): boolean;
schemaFormat(): string | undefined;
schemaFormat(): string;
hasMessageId(): boolean;

@@ -12,0 +11,0 @@ messageId(): string | undefined;

@@ -8,4 +8,2 @@ import type { BindingsInterface } from './bindings';

}
export interface CoreMixinInterface extends BindingsMixinInterface, DescriptionMixinInterface, ExtensionsMixinInterface, ExternalDocumentationMixinInterface, SummaryMixinInterface, TagsMixinInterface, TitleMixinInterface {
}
export interface DescriptionMixinInterface {

@@ -22,12 +20,4 @@ hasDescription(): boolean;

}
export interface SummaryMixinInterface {
hasSummary(): boolean;
summary(): string | undefined;
}
export interface TagsMixinInterface {
tags(): TagsInterface;
}
export interface TitleMixinInterface {
hasTitle(): boolean;
title(): string | undefined;
}

@@ -5,3 +5,3 @@ import type { BaseModel } from './base';

export interface OperationTraitInterface extends BaseModel, BindingsMixinInterface, DescriptionMixinInterface, ExtensionsMixinInterface, ExternalDocumentationMixinInterface, TagsMixinInterface {
id(): string | undefined;
id(): string;
hasOperationId(): boolean;

@@ -8,0 +8,0 @@ operationId(): string | undefined;

@@ -51,3 +51,2 @@ import type { BaseModel } from './base';

required(): Array<string> | undefined;
schemaFormat(): string;
then(): SchemaInterface | undefined;

@@ -54,0 +53,0 @@ title(): string | undefined;

@@ -11,5 +11,2 @@ import type { BaseModel } from './base';

url(): string;
host(): string;
hasPathname(): boolean;
pathname(): string | undefined;
protocol(): string;

@@ -16,0 +13,0 @@ protocolVersion(): string | undefined;

@@ -51,14 +51,11 @@ "use strict";

hasExternalDocs() {
const asyncapiV2 = this._meta.asyncapi.parsed;
return Object.keys(asyncapiV2.externalDocs || {}).length > 0;
return Object.keys(this._meta.asyncapi.parsed.externalDocs || {}).length > 0;
}
externalDocs() {
if (this.hasExternalDocs()) {
const asyncapiV2 = this._meta.asyncapi.parsed;
return this.createModel(external_docs_1.ExternalDocumentation, asyncapiV2.externalDocs, { pointer: '/externalDocs' });
return this.createModel(external_docs_1.ExternalDocumentation, this._meta.asyncapi.parsed.externalDocs, { pointer: '/externalDocs' });
}
}
tags() {
const asyncapiV2 = this._meta.asyncapi.parsed;
const tags = asyncapiV2.tags || [];
const tags = this._meta.asyncapi.parsed.tags || [];
return new tags_1.Tags(tags.map((tag, idx) => this.createModel(tag_1.Tag, tag, { pointer: `/tags/${idx}` })));

@@ -65,0 +62,0 @@ }

@@ -15,4 +15,3 @@ import { BaseModel } from '../base';

id(): string;
hasSchemaFormat(): boolean;
schemaFormat(): string | undefined;
schemaFormat(): string;
hasMessageId(): boolean;

@@ -19,0 +18,0 @@ messageId(): string | undefined;

@@ -10,4 +10,4 @@ "use strict";

const constants_1 = require("../../constants");
const schema_parser_1 = require("../../schema-parser");
const mixins_1 = require("./mixins");
const schema_parser_1 = require("../../schema-parser");
class MessageTrait extends base_1.BaseModel {

@@ -17,5 +17,2 @@ id() {

}
hasSchemaFormat() {
return this.schemaFormat() !== undefined;
}
schemaFormat() {

@@ -22,0 +19,0 @@ return this._json.schemaFormat || (0, schema_parser_1.getDefaultSchemaFormat)(this._meta.asyncapi.semver.version);

@@ -19,3 +19,3 @@ "use strict";

return undefined;
return this.createModel(schema_1.Schema, this._json.payload, { pointer: `${this._meta.pointer}/payload`, schemaFormat: this._json.schemaFormat });
return this.createModel(schema_1.Schema, this._json.payload, { pointer: `${this._meta.pointer}/payload` });
}

@@ -22,0 +22,0 @@ servers() {

@@ -9,3 +9,2 @@ import { BaseModel } from '../base';

parent?: Schema;
schemaFormat?: string;
}> implements SchemaInterface {

@@ -58,3 +57,2 @@ id(): string;

required(): Array<string> | undefined;
schemaFormat(): string;
then(): SchemaInterface | undefined;

@@ -61,0 +59,0 @@ title(): string | undefined;

@@ -7,3 +7,2 @@ "use strict";

const mixins_1 = require("./mixins");
const schema_parser_1 = require("../../schema-parser");
class Schema extends base_1.BaseModel {

@@ -275,5 +274,2 @@ id() {

}
schemaFormat() {
return this._meta.schemaFormat || (0, schema_parser_1.getDefaultSchemaFormat)(this._meta.asyncapi.semver.version);
}
then() {

@@ -280,0 +276,0 @@ if (typeof this._json === 'boolean' || typeof this._json.then !== 'object')

@@ -17,5 +17,2 @@ import { BaseModel } from '../base';

url(): string;
host(): string;
hasPathname(): boolean;
pathname(): string | undefined;
protocol(): string;

@@ -22,0 +19,0 @@ hasProtocolVersion(): boolean;

@@ -23,13 +23,2 @@ "use strict";

}
host() {
const url = new URL(this.url());
return url.host;
}
hasPathname() {
return !!this.pathname();
}
pathname() {
const url = new URL(this.url());
return url.pathname;
}
protocol() {

@@ -36,0 +25,0 @@ return this._json.protocol;

import { BaseModel } from '../base';
import type { AsyncAPIDocumentInterface } from '../asyncapi';
import type { InfoInterface } from '../info';
import type { ServersInterface } from '../servers';
import type { ChannelsInterface } from '../channels';
import type { OperationsInterface } from '../operations';
import type { MessagesInterface } from '../messages';
import type { ComponentsInterface } from '../components';
import type { SecuritySchemesInterface } from '../security-schemes';
import type { ExtensionsInterface } from '../extensions';
import type { SchemasInterface } from 'models/schemas';
import type { v3 } from '../../spec-types';
export declare class AsyncAPIDocument extends BaseModel<v3.AsyncAPIObject> implements AsyncAPIDocumentInterface {
export declare class AsyncAPIDocument extends BaseModel {
version(): string;
defaultContentType(): string | undefined;
hasDefaultContentType(): boolean;
info(): InfoInterface;
servers(): ServersInterface;
channels(): ChannelsInterface;
operations(): OperationsInterface;
messages(): MessagesInterface;
schemas(): any;
securitySchemes(): SecuritySchemesInterface;
components(): ComponentsInterface;
allServers(): ServersInterface;
allChannels(): ChannelsInterface;
allOperations(): OperationsInterface;
allMessages(): MessagesInterface;
allSchemas(): SchemasInterface;
extensions(): ExtensionsInterface;
private __schemas;
}

@@ -5,17 +5,2 @@ "use strict";

const base_1 = require("../base");
const info_1 = require("./info");
const servers_1 = require("./servers");
const server_1 = require("./server");
const channels_1 = require("./channels");
const channel_1 = require("./channel");
const operations_1 = require("./operations");
const operation_1 = require("./operation");
const messages_1 = require("./messages");
const security_schemes_1 = require("./security-schemes");
const security_scheme_1 = require("./security-scheme");
const components_1 = require("./components");
const schemas_1 = require("./schemas");
const mixins_1 = require("./mixins");
const utils_1 = require("../../utils");
const iterator_1 = require("../../iterator");
class AsyncAPIDocument extends base_1.BaseModel {

@@ -25,86 +10,3 @@ version() {

}
defaultContentType() {
return this._json.defaultContentType;
}
hasDefaultContentType() {
return !!this._json.defaultContentType;
}
info() {
return this.createModel(info_1.Info, this._json.info, { pointer: '/info' });
}
servers() {
return new servers_1.Servers(Object.entries(this._json.servers || {}).map(([serverName, server]) => this.createModel(server_1.Server, server, { id: serverName, pointer: `/servers/${(0, utils_1.tilde)(serverName)}` })));
}
channels() {
return new channels_1.Channels(Object.entries(this._json.channels || {}).map(([channelId, channel]) => this.createModel(channel_1.Channel, channel, { id: channelId, pointer: `/channels/${(0, utils_1.tilde)(channelId)}` })));
}
operations() {
return new operations_1.Operations(Object.entries(this._json.operations || {}).map(([operationId, operation]) => this.createModel(operation_1.Operation, operation, { id: operationId, pointer: `/operations/${(0, utils_1.tilde)(operationId)}` })));
}
messages() {
const messages = [];
const messagesData = [];
this.channels().forEach(channel => {
channel.messages().forEach(message => {
const messageData = message.json();
if (!messagesData.includes(messageData)) {
messagesData.push(messageData);
messages.push(message);
}
});
});
return new messages_1.Messages(messages);
}
schemas() {
return null;
}
securitySchemes() {
var _a;
return new security_schemes_1.SecuritySchemes(Object.entries(((_a = this._json.components) === null || _a === void 0 ? void 0 : _a.securitySchemes) || {}).map(([securitySchemeName, securityScheme]) => this.createModel(security_scheme_1.SecurityScheme, securityScheme, { id: securitySchemeName, pointer: `/components/securitySchemes/${securitySchemeName}` })));
}
components() {
return this.createModel(components_1.Components, this._json.components || {}, { pointer: '/components' });
}
allServers() {
const servers = this.servers();
this.components().servers().forEach(server => !servers.some(s => s.json() === server.json()) && servers.push(server));
return new servers_1.Servers(servers);
}
allChannels() {
const channels = this.channels();
this.components().channels().forEach(channel => !channels.some(c => c.json() === channel.json()) && channels.push(channel));
return new channels_1.Channels(channels);
}
allOperations() {
const operations = [];
this.allChannels().forEach(channel => operations.push(...channel.operations()));
return new operations_1.Operations(operations);
}
allMessages() {
const messages = [];
this.allOperations().forEach(operation => operation.messages().forEach(message => (!messages.some(m => m.json() === message.json()) && messages.push(message))));
this.components().messages().forEach(message => (!messages.some(m => m.json() === message.json()) && messages.push(message)));
return new messages_1.Messages(messages);
}
allSchemas() {
return this.__schemas(true);
}
extensions() {
return (0, mixins_1.extensions)(this);
}
__schemas(withComponents) {
const schemas = new Set();
function callback(schema) {
if (!schemas.has(schema.json())) {
schemas.add(schema);
}
}
let toIterate = Object.values(iterator_1.SchemaTypesToIterate);
if (!withComponents) {
toIterate = toIterate.filter(s => s !== iterator_1.SchemaTypesToIterate.Components);
}
(0, iterator_1.traverseAsyncApiDocument)(this, callback, toIterate);
return new schemas_1.Schemas(Array.from(schemas));
}
}
exports.AsyncAPIDocument = AsyncAPIDocument;
export { AsyncAPIDocument as AsyncAPIDocumentV3 } from './asyncapi';
export { Binding as BindingV3 } from './binding';
export { Bindings as BindingsV3 } from './bindings';
export { ChannelParameter as ChannelParameterV3 } from './channel-parameter';
export { ChannelParameters as ChannelParametersV3 } from './channel-parameters';
export { Channel as ChannelV3 } from './channel';
export { Channels as ChannelsV3 } from './channels';
export { Components as ComponentsV3 } from './components';
export { Contact as ContactV3 } from './contact';
export { CorrelationId as CorrelationIdV3 } from './correlation-id';
export { Extension as ExtensionV3 } from './extension';
export { Extensions as ExtensionsV3 } from './extensions';
export { ExternalDocumentation as ExternalDocumentationV3 } from './external-docs';
export { Info as InfoV3 } from './info';
export { License as LicenseV3 } from './license';
export { MessageExample as MessageExampleV3 } from './message-example';
export { MessageExamples as MessageExamplesV3 } from './message-examples';
export { MessageTrait as MessageTraitV3 } from './message-trait';
export { MessageTraits as MessageTraitsV3 } from './message-traits';
export { Message as MessageV3 } from './message';
export { Messages as MessagesV3 } from './messages';
export { OAuthFlow as OAuthFlowV3 } from './oauth-flow';
export { OAuthFlows as OAuthFlowsV3 } from './oauth-flows';
export { OperationTrait as OperationTraitV3 } from './operation-trait';
export { OperationTraits as OperationTraitsV3 } from './operation-traits';
export { OperationReplies as OperationRepliesV3 } from './operation-replies';
export { OperationReplyAddress as OperationReplyAddressV3 } from './operation-reply-address';
export { OperationReplyAddresses as OperationReplyAddressesV3 } from './operation-reply-addresses';
export { OperationReply as OperationReplyV3 } from './operation-reply';
export { Operation as OperationV3 } from './operation';
export { Operations as OperationsV3 } from './operations';
export { Schema as SchemaV3 } from './schema';
export { Schemas as SchemasV3 } from './schemas';
export { SecurityScheme as SecuritySchemeV3 } from './security-scheme';
export { SecuritySchemes as SecuritySchemesV3 } from './security-schemes';
export { ServerVariable as ServerVariableV3 } from './server-variable';
export { ServerVariables as ServerVariablesV3 } from './server-variables';
export { Server as ServerV3 } from './server';
export { Servers as ServersV3 } from './servers';
export { Tag as TagV3 } from './tag';
export { Tags as TagsV3 } from './tags';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TagsV3 = exports.TagV3 = exports.ServersV3 = exports.ServerV3 = exports.ServerVariablesV3 = exports.ServerVariableV3 = exports.SecuritySchemesV3 = exports.SecuritySchemeV3 = exports.SchemasV3 = exports.SchemaV3 = exports.OperationsV3 = exports.OperationV3 = exports.OperationReplyV3 = exports.OperationReplyAddressesV3 = exports.OperationReplyAddressV3 = exports.OperationRepliesV3 = exports.OperationTraitsV3 = exports.OperationTraitV3 = exports.OAuthFlowsV3 = exports.OAuthFlowV3 = exports.MessagesV3 = exports.MessageV3 = exports.MessageTraitsV3 = exports.MessageTraitV3 = exports.MessageExamplesV3 = exports.MessageExampleV3 = exports.LicenseV3 = exports.InfoV3 = exports.ExternalDocumentationV3 = exports.ExtensionsV3 = exports.ExtensionV3 = exports.CorrelationIdV3 = exports.ContactV3 = exports.ComponentsV3 = exports.ChannelsV3 = exports.ChannelV3 = exports.ChannelParametersV3 = exports.ChannelParameterV3 = exports.BindingsV3 = exports.BindingV3 = exports.AsyncAPIDocumentV3 = void 0;
exports.AsyncAPIDocumentV3 = void 0;
var asyncapi_1 = require("./asyncapi");
Object.defineProperty(exports, "AsyncAPIDocumentV3", { enumerable: true, get: function () { return asyncapi_1.AsyncAPIDocument; } });
var binding_1 = require("./binding");
Object.defineProperty(exports, "BindingV3", { enumerable: true, get: function () { return binding_1.Binding; } });
var bindings_1 = require("./bindings");
Object.defineProperty(exports, "BindingsV3", { enumerable: true, get: function () { return bindings_1.Bindings; } });
var channel_parameter_1 = require("./channel-parameter");
Object.defineProperty(exports, "ChannelParameterV3", { enumerable: true, get: function () { return channel_parameter_1.ChannelParameter; } });
var channel_parameters_1 = require("./channel-parameters");
Object.defineProperty(exports, "ChannelParametersV3", { enumerable: true, get: function () { return channel_parameters_1.ChannelParameters; } });
var channel_1 = require("./channel");
Object.defineProperty(exports, "ChannelV3", { enumerable: true, get: function () { return channel_1.Channel; } });
var channels_1 = require("./channels");
Object.defineProperty(exports, "ChannelsV3", { enumerable: true, get: function () { return channels_1.Channels; } });
var components_1 = require("./components");
Object.defineProperty(exports, "ComponentsV3", { enumerable: true, get: function () { return components_1.Components; } });
var contact_1 = require("./contact");
Object.defineProperty(exports, "ContactV3", { enumerable: true, get: function () { return contact_1.Contact; } });
var correlation_id_1 = require("./correlation-id");
Object.defineProperty(exports, "CorrelationIdV3", { enumerable: true, get: function () { return correlation_id_1.CorrelationId; } });
var extension_1 = require("./extension");
Object.defineProperty(exports, "ExtensionV3", { enumerable: true, get: function () { return extension_1.Extension; } });
var extensions_1 = require("./extensions");
Object.defineProperty(exports, "ExtensionsV3", { enumerable: true, get: function () { return extensions_1.Extensions; } });
var external_docs_1 = require("./external-docs");
Object.defineProperty(exports, "ExternalDocumentationV3", { enumerable: true, get: function () { return external_docs_1.ExternalDocumentation; } });
var info_1 = require("./info");
Object.defineProperty(exports, "InfoV3", { enumerable: true, get: function () { return info_1.Info; } });
var license_1 = require("./license");
Object.defineProperty(exports, "LicenseV3", { enumerable: true, get: function () { return license_1.License; } });
var message_example_1 = require("./message-example");
Object.defineProperty(exports, "MessageExampleV3", { enumerable: true, get: function () { return message_example_1.MessageExample; } });
var message_examples_1 = require("./message-examples");
Object.defineProperty(exports, "MessageExamplesV3", { enumerable: true, get: function () { return message_examples_1.MessageExamples; } });
var message_trait_1 = require("./message-trait");
Object.defineProperty(exports, "MessageTraitV3", { enumerable: true, get: function () { return message_trait_1.MessageTrait; } });
var message_traits_1 = require("./message-traits");
Object.defineProperty(exports, "MessageTraitsV3", { enumerable: true, get: function () { return message_traits_1.MessageTraits; } });
var message_1 = require("./message");
Object.defineProperty(exports, "MessageV3", { enumerable: true, get: function () { return message_1.Message; } });
var messages_1 = require("./messages");
Object.defineProperty(exports, "MessagesV3", { enumerable: true, get: function () { return messages_1.Messages; } });
var oauth_flow_1 = require("./oauth-flow");
Object.defineProperty(exports, "OAuthFlowV3", { enumerable: true, get: function () { return oauth_flow_1.OAuthFlow; } });
var oauth_flows_1 = require("./oauth-flows");
Object.defineProperty(exports, "OAuthFlowsV3", { enumerable: true, get: function () { return oauth_flows_1.OAuthFlows; } });
var operation_trait_1 = require("./operation-trait");
Object.defineProperty(exports, "OperationTraitV3", { enumerable: true, get: function () { return operation_trait_1.OperationTrait; } });
var operation_traits_1 = require("./operation-traits");
Object.defineProperty(exports, "OperationTraitsV3", { enumerable: true, get: function () { return operation_traits_1.OperationTraits; } });
var operation_replies_1 = require("./operation-replies");
Object.defineProperty(exports, "OperationRepliesV3", { enumerable: true, get: function () { return operation_replies_1.OperationReplies; } });
var operation_reply_address_1 = require("./operation-reply-address");
Object.defineProperty(exports, "OperationReplyAddressV3", { enumerable: true, get: function () { return operation_reply_address_1.OperationReplyAddress; } });
var operation_reply_addresses_1 = require("./operation-reply-addresses");
Object.defineProperty(exports, "OperationReplyAddressesV3", { enumerable: true, get: function () { return operation_reply_addresses_1.OperationReplyAddresses; } });
var operation_reply_1 = require("./operation-reply");
Object.defineProperty(exports, "OperationReplyV3", { enumerable: true, get: function () { return operation_reply_1.OperationReply; } });
var operation_1 = require("./operation");
Object.defineProperty(exports, "OperationV3", { enumerable: true, get: function () { return operation_1.Operation; } });
var operations_1 = require("./operations");
Object.defineProperty(exports, "OperationsV3", { enumerable: true, get: function () { return operations_1.Operations; } });
var schema_1 = require("./schema");
Object.defineProperty(exports, "SchemaV3", { enumerable: true, get: function () { return schema_1.Schema; } });
var schemas_1 = require("./schemas");
Object.defineProperty(exports, "SchemasV3", { enumerable: true, get: function () { return schemas_1.Schemas; } });
var security_scheme_1 = require("./security-scheme");
Object.defineProperty(exports, "SecuritySchemeV3", { enumerable: true, get: function () { return security_scheme_1.SecurityScheme; } });
var security_schemes_1 = require("./security-schemes");
Object.defineProperty(exports, "SecuritySchemesV3", { enumerable: true, get: function () { return security_schemes_1.SecuritySchemes; } });
var server_variable_1 = require("./server-variable");
Object.defineProperty(exports, "ServerVariableV3", { enumerable: true, get: function () { return server_variable_1.ServerVariable; } });
var server_variables_1 = require("./server-variables");
Object.defineProperty(exports, "ServerVariablesV3", { enumerable: true, get: function () { return server_variables_1.ServerVariables; } });
var server_1 = require("./server");
Object.defineProperty(exports, "ServerV3", { enumerable: true, get: function () { return server_1.Server; } });
var servers_1 = require("./servers");
Object.defineProperty(exports, "ServersV3", { enumerable: true, get: function () { return servers_1.Servers; } });
var tag_1 = require("./tag");
Object.defineProperty(exports, "TagV3", { enumerable: true, get: function () { return tag_1.Tag; } });
var tags_1 = require("./tags");
Object.defineProperty(exports, "TagsV3", { enumerable: true, get: function () { return tags_1.Tags; } });
import type { Format } from '@stoplight/spectral-core';
export declare const aas2: Format;
export declare const aas2_0: Format;
export declare const aas2_1: Format;
export declare const aas2_2: Format;
export declare const aas2_3: Format;
export declare const aas2_4: Format;
export declare const aas2_5: Format;
export declare const aas2_6: Format;
export declare const aas2All: Format<void>[];
export declare class Formats extends Map<string, Format> {
filterByMajorVersions(majorsToInclude: string[]): Formats;
excludeByVersions(versionsToExclude: string[]): Formats;
find(version: string): Format | undefined;
formats(): Format[];
}
export declare const AsyncAPIFormats: Formats;
"use strict";
/* eslint-disable security/detect-unsafe-regex */
Object.defineProperty(exports, "__esModule", { value: true });
exports.aas2All = exports.aas2_6 = exports.aas2_5 = exports.aas2_4 = exports.aas2_3 = exports.aas2_2 = exports.aas2_1 = exports.aas2_0 = exports.aas2 = void 0;
exports.AsyncAPIFormats = exports.Formats = void 0;
const utils_1 = require("../utils");
const aas2Regex = /^2\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/;
const aas2_0Regex = /^2\.0(?:\.[0-9]*)?$/;
const aas2_1Regex = /^2\.1(?:\.[0-9]*)?$/;
const aas2_2Regex = /^2\.2(?:\.[0-9]*)?$/;
const aas2_3Regex = /^2\.3(?:\.[0-9]*)?$/;
const aas2_4Regex = /^2\.4(?:\.[0-9]*)?$/;
const aas2_5Regex = /^2\.5(?:\.[0-9]*)?$/;
const aas2_6Regex = /^2\.6(?:\.[0-9]*)?$/;
const isAas2 = (document) => (0, utils_1.isObject)(document) && 'asyncapi' in document && aas2Regex.test(String(document.asyncapi));
exports.aas2 = isAas2;
exports.aas2.displayName = 'AsyncAPI 2.x';
const aas2_0 = (document) => isAas2(document) && aas2_0Regex.test(String(document.asyncapi));
exports.aas2_0 = aas2_0;
exports.aas2_0.displayName = 'AsyncAPI 2.0.x';
const aas2_1 = (document) => isAas2(document) && aas2_1Regex.test(String(document.asyncapi));
exports.aas2_1 = aas2_1;
exports.aas2_1.displayName = 'AsyncAPI 2.1.x';
const aas2_2 = (document) => isAas2(document) && aas2_2Regex.test(String(document.asyncapi));
exports.aas2_2 = aas2_2;
exports.aas2_2.displayName = 'AsyncAPI 2.2.x';
const aas2_3 = (document) => isAas2(document) && aas2_3Regex.test(String(document.asyncapi));
exports.aas2_3 = aas2_3;
exports.aas2_3.displayName = 'AsyncAPI 2.3.x';
const aas2_4 = (document) => isAas2(document) && aas2_4Regex.test(String(document.asyncapi));
exports.aas2_4 = aas2_4;
exports.aas2_4.displayName = 'AsyncAPI 2.4.x';
const aas2_5 = (document) => isAas2(document) && aas2_5Regex.test(String(document.asyncapi));
exports.aas2_5 = aas2_5;
exports.aas2_5.displayName = 'AsyncAPI 2.5.x';
const aas2_6 = (document) => isAas2(document) && aas2_6Regex.test(String(document.asyncapi));
exports.aas2_6 = aas2_6;
exports.aas2_6.displayName = 'AsyncAPI 2.6.x';
exports.aas2All = [exports.aas2_0, exports.aas2_1, exports.aas2_2, exports.aas2_3, exports.aas2_4, exports.aas2_5, exports.aas2_6];
const specs_1 = require("@asyncapi/specs");
class Formats extends Map {
filterByMajorVersions(majorsToInclude) {
return new Formats([...this.entries()].filter(element => { return majorsToInclude.includes(element[0].split('.')[0]); }));
}
excludeByVersions(versionsToExclude) {
return new Formats([...this.entries()].filter(element => { return !versionsToExclude.includes(element[0]); }));
}
find(version) {
return this.get(formatVersion(version));
}
formats() {
return [...this.values()];
}
}
exports.Formats = Formats;
exports.AsyncAPIFormats = new Formats(Object.entries(specs_1.schemas).reverse().map(([version]) => [version, createFormat(version)])); // reverse is used for giving newer versions a higher priority when matching
function isAsyncAPIVersion(versionToMatch, document) {
const asyncAPIDoc = document;
if (!asyncAPIDoc)
return false;
const documentVersion = String(asyncAPIDoc.asyncapi);
return (0, utils_1.isObject)(document) && 'asyncapi' in document
&& assertValidAsyncAPIVersion(documentVersion)
&& versionToMatch === formatVersion(documentVersion);
}
function assertValidAsyncAPIVersion(documentVersion) {
const semver = (0, utils_1.getSemver)(documentVersion);
const regexp = new RegExp(`^(${semver.major})\\.(${semver.minor})\\.(0|[1-9][0-9]*)$`); // eslint-disable-line security/detect-non-literal-regexp
return regexp.test(documentVersion);
}
function createFormat(version) {
const format = (document) => isAsyncAPIVersion(version, document);
const semver = (0, utils_1.getSemver)(version);
format.displayName = `AsyncAPI ${semver.major}.${semver.minor}.x`;
return format;
}
const formatVersion = function (version) {
const versionSemver = (0, utils_1.getSemver)(version);
return `${versionSemver.major}.${versionSemver.minor}.0`;
};

@@ -0,3 +1,5 @@

import type { Format } from '@stoplight/spectral-core';
export declare function getSchema(docFormats: Set<Format>): Record<string, any> | void;
export declare const documentStructure: import("@stoplight/spectral-core").RulesetFunctionWithValidator<unknown, {
resolved: boolean;
}>;

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.documentStructure = void 0;
exports.documentStructure = exports.getSchema = void 0;
const specs_1 = __importDefault(require("@asyncapi/specs"));

@@ -74,22 +74,10 @@ const spectral_core_1 = require("@stoplight/spectral-core");

}
function getSchema(formats) {
switch (true) {
case formats.has(formats_1.aas2_6):
return getSerializedSchema('2.6.0');
case formats.has(formats_1.aas2_5):
return getSerializedSchema('2.5.0');
case formats.has(formats_1.aas2_4):
return getSerializedSchema('2.4.0');
case formats.has(formats_1.aas2_3):
return getSerializedSchema('2.3.0');
case formats.has(formats_1.aas2_2):
return getSerializedSchema('2.2.0');
case formats.has(formats_1.aas2_1):
return getSerializedSchema('2.1.0');
case formats.has(formats_1.aas2_0):
return getSerializedSchema('2.0.0');
default:
return;
function getSchema(docFormats) {
for (const [version, format] of formats_1.AsyncAPIFormats) {
if (docFormats.has(format)) {
return getSerializedSchema(version);
}
}
}
exports.getSchema = getSchema;
exports.documentStructure = (0, spectral_core_1.createRulesetFunction)({

@@ -96,0 +84,0 @@ input: null,

@@ -6,3 +6,2 @@ "use strict";

const spectral_core_1 = require("@stoplight/spectral-core");
const formats_1 = require("../formats");
const utils_1 = require("../../utils");

@@ -24,5 +23,5 @@ exports.unusedComponent = (0, spectral_core_1.createRulesetFunction)({

Object.keys(components).forEach(componentType => {
// if component type is `securitySchemes` and we operate on AsyncAPI 2.x.x skip validation
// security schemes in 2.x.x are referenced by keys, not by object ref - for this case we have a separate `asyncapi2-unused-securityScheme` rule
if (componentType === 'securitySchemes' && (0, formats_1.aas2)(targetVal, null)) {
// if component type is `securitySchemes` we skip the validation
// security schemes in >=2.x.x are referenced by keys, not by object ref - for this case we have a separate `asyncapi2-unused-securityScheme` rule
if (componentType === 'securitySchemes') {
return;

@@ -29,0 +28,0 @@ }

@@ -172,2 +172,3 @@ export declare const coreRuleset: {

description: string;
formats: import("@stoplight/spectral-core").Format<void>[];
recommended: boolean;

@@ -174,0 +175,0 @@ resolved: boolean;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.recommendedRuleset = exports.coreRuleset = void 0;
const formats_1 = require("./formats");
const constants_1 = require("../constants");

@@ -11,5 +10,6 @@ const spectral_functions_1 = require("@stoplight/spectral-functions");

const unusedComponent_1 = require("./functions/unusedComponent");
const formats_1 = require("./formats");
exports.coreRuleset = {
description: 'Core AsyncAPI x.x.x ruleset.',
formats: [...formats_1.aas2All],
formats: formats_1.AsyncAPIFormats.filterByMajorVersions(['2']).formats(),
rules: {

@@ -84,3 +84,3 @@ /**

description: 'Recommended AsyncAPI x.x.x ruleset.',
formats: [...formats_1.aas2All],
formats: formats_1.AsyncAPIFormats.filterByMajorVersions(['2']).formats(),
rules: {

@@ -190,2 +190,3 @@ /**

description: 'Potentially unused component has been detected in AsyncAPI document.',
formats: formats_1.AsyncAPIFormats.filterByMajorVersions(['2']).formats(),
recommended: true,

@@ -192,0 +193,0 @@ resolved: false,

@@ -0,2 +1,10 @@

import { schema as schemaFn } from '@stoplight/spectral-functions';
import type { JsonPath } from '@stoplight/types';
import type { RulesetFunctionContext } from '@stoplight/spectral-core';
import type { v2 } from 'spec-types';
export declare function getMessageExamples(message: v2.MessageObject): Array<{
path: JsonPath;
value: v2.MessageExampleObject;
}>;
export declare function validate(value: unknown, path: JsonPath, type: 'payload' | 'headers', schema: unknown, ctx: RulesetFunctionContext): ReturnType<typeof schemaFn>;
export declare const messageExamples: import("@stoplight/spectral-core").RulesetFunctionWithValidator<v2.MessageObject, null>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.messageExamples = void 0;
exports.messageExamples = exports.validate = exports.getMessageExamples = void 0;
const spectral_core_1 = require("@stoplight/spectral-core");

@@ -37,2 +37,3 @@ const spectral_functions_1 = require("@stoplight/spectral-functions");

}
exports.getMessageExamples = getMessageExamples;
function validate(value, path, type, schema, ctx) {

@@ -44,2 +45,3 @@ return (0, spectral_functions_1.schema)(value, {

}
exports.validate = validate;
exports.messageExamples = (0, spectral_core_1.createRulesetFunction)({

@@ -46,0 +48,0 @@ input: {

@@ -148,3 +148,2 @@ import type { Parser } from '../../parser';

description: string;
formats: import("@stoplight/spectral-core").Format<void>[];
rules: {

@@ -188,2 +187,3 @@ 'asyncapi2-schemas': import("@stoplight/spectral-core").RuleDefinition;

};
'asyncapi2-message-examples-custom-format': import("@stoplight/spectral-core").RuleDefinition;
};

@@ -190,0 +190,0 @@ };

@@ -11,2 +11,3 @@ "use strict";

const messageExamples_1 = require("./functions/messageExamples");
const messageExamples_spectral_rule_v2_1 = require("./functions/messageExamples-spectral-rule-v2");
const messageIdUniqueness_1 = require("./functions/messageIdUniqueness");

@@ -22,3 +23,3 @@ const operationIdUniqueness_1 = require("./functions/operationIdUniqueness");

description: 'Core AsyncAPI 2.x.x ruleset.',
formats: [...formats_1.aas2All],
formats: formats_1.AsyncAPIFormats.filterByMajorVersions(['2']).formats(),
rules: {

@@ -122,5 +123,5 @@ /**

// messages
'$.channels.*.[publish,subscribe].[?(@property === \'message\' && @.schemaFormat === void 0)]',
'$.channels.*.[publish,subscribe][?(@property === \'message\' && @.schemaFormat === void 0)]',
'$.channels.*.[publish,subscribe].message.oneOf[?(!@null && @.schemaFormat === void 0)]',
'$.components.channels.*.[publish,subscribe].[?(@property === \'message\' && @.schemaFormat === void 0)]',
'$.components.channels.*.[publish,subscribe][?(@property === \'message\' && @.schemaFormat === void 0)]',
'$.components.channels.*.[publish,subscribe].message.oneOf[?(!@null && @.schemaFormat === void 0)]',

@@ -190,3 +191,2 @@ '$.components.messages[?(!@null && @.schemaFormat === void 0)]',

description: 'Schemas AsyncAPI 2.x.x ruleset.',
formats: [...formats_1.aas2All],
rules: {

@@ -238,2 +238,3 @@ 'asyncapi2-schemas': (0, spectral_rule_v2_1.asyncApi2SchemaParserRule)(parser),

},
'asyncapi2-message-examples-custom-format': (0, messageExamples_spectral_rule_v2_1.asyncApi2MessageExamplesParserRule)(parser),
}

@@ -245,3 +246,3 @@ };

description: 'Recommended AsyncAPI 2.x.x ruleset.',
formats: [...formats_1.aas2All],
formats: formats_1.AsyncAPIFormats.filterByMajorVersions(['2']).formats(),
rules: {

@@ -332,3 +333,3 @@ /**

recommended: true,
formats: formats_1.aas2All.slice(4),
formats: formats_1.AsyncAPIFormats.filterByMajorVersions(['2']).excludeByVersions(['2.0.0', '2.1.0', '2.2.0', '2.3.0']).formats(),
given: [

@@ -335,0 +336,0 @@ '$.channels.*.[publish,subscribe][?(@property === "message" && @.oneOf == void 0)]',

@@ -25,5 +25,5 @@ import type { Parser } from '../parser';

export declare function validateSchema(parser: Parser, input: ValidateSchemaInput): Promise<void | import("@stoplight/spectral-core").IFunctionResult[]>;
export declare function parseSchema(parser: Parser, input: ParseSchemaInput): Promise<AsyncAPISchema>;
export declare function parseSchema(parser: Parser, input: ParseSchemaInput): Promise<import("../spec-types/v2").AsyncAPISchemaObject>;
export declare function registerSchemaParser(parser: Parser, schemaParser: SchemaParser): void;
export declare function getSchemaFormat(schematFormat: string | undefined, asyncapiVersion: string): string;
export declare function getDefaultSchemaFormat(asyncapiVersion: string): string;
export * as v2 from './v2';
export * as v3 from './v3';

@@ -26,4 +26,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.v3 = exports.v2 = void 0;
exports.v2 = void 0;
exports.v2 = __importStar(require("./v2"));
exports.v3 = __importStar(require("./v3"));
import type { ISpectralDiagnostic, IFunctionResult } from '@stoplight/spectral-core';
import type { AsyncAPIDocumentInterface } from './models';
import type { v2, v3 } from './spec-types';
import type { v2 } from './spec-types';
export type MaybeAsyncAPI = {

@@ -23,3 +23,3 @@ asyncapi: string;

export type SchemaValidateResult = IFunctionResult;
export type AsyncAPIObject = v2.AsyncAPIObject | v3.AsyncAPIObject;
export type AsyncAPISchema = v2.AsyncAPISchemaObject | v3.AsyncAPISchemaObject;
export type AsyncAPIObject = v2.AsyncAPIObject;
export type AsyncAPISchema = v2.AsyncAPISchemaObject;

@@ -23,6 +23,2 @@ import { Document } from '@stoplight/spectral-core';

export declare function findSubArrayIndex(arr: Array<any>, subarr: Array<any>, fromIndex?: number): number;
export declare function resolveServerUrl(url: string): {
host: string;
pathname: string | undefined;
};
export declare function retrieveDeepData(value: Record<string, any>, path: Array<string | number>): Record<string, any> | undefined;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.retrieveDeepData = exports.resolveServerUrl = exports.findSubArrayIndex = exports.untilde = exports.tilde = exports.createUncaghtDiagnostic = exports.toJSONPathArray = exports.hasRef = exports.isObject = exports.mergePatch = exports.setExtension = exports.hasHintDiagnostic = exports.hasInfoDiagnostic = exports.hasWarningDiagnostic = exports.hasErrorDiagnostic = exports.normalizeInput = exports.getSemver = exports.createDetailedAsyncAPI = void 0;
exports.retrieveDeepData = exports.findSubArrayIndex = exports.untilde = exports.tilde = exports.createUncaghtDiagnostic = exports.toJSONPathArray = exports.hasRef = exports.isObject = exports.mergePatch = exports.setExtension = exports.hasHintDiagnostic = exports.hasInfoDiagnostic = exports.hasWarningDiagnostic = exports.hasErrorDiagnostic = exports.normalizeInput = exports.getSemver = exports.createDetailedAsyncAPI = void 0;
const spectral_core_1 = require("@stoplight/spectral-core");

@@ -145,15 +145,2 @@ const types_1 = require("@stoplight/types");

exports.findSubArrayIndex = findSubArrayIndex;
function resolveServerUrl(url) {
// eslint-disable-next-line prefer-const
let [maybeProtocol, maybeHost] = url.split('://');
if (!maybeHost) {
maybeHost = maybeProtocol;
}
const [host, ...pathnames] = maybeHost.split('/');
if (pathnames.length) {
return { host, pathname: `/${pathnames.join('/')}` };
}
return { host, pathname: undefined };
}
exports.resolveServerUrl = resolveServerUrl;
function retrieveDeepData(value, path) {

@@ -160,0 +147,0 @@ let index = 0;

@@ -1,3 +0,3 @@

import type { v2, v3 } from '../spec-types';
import type { v2 } from '../spec-types';
export declare function applyTraitsV2(asyncapi: v2.AsyncAPIObject): void;
export declare function applyTraitsV3(asyncapi: v3.AsyncAPIObject): void;
export declare function applyTraitsV3(asyncapi: v2.AsyncAPIObject): void;

@@ -15,45 +15,19 @@ import { JSONPath } from 'jsonpath-plus';

export function applyTraitsV2(asyncapi) {
applyAllTraitsV2(asyncapi, v2TraitPaths);
applyAllTraits(asyncapi, v2TraitPaths);
}
function applyAllTraitsV2(asyncapi, paths) {
const visited = new Set();
paths.forEach(path => {
JSONPath({
path,
json: asyncapi,
resultType: 'value',
callback(value) {
if (visited.has(value)) {
return;
}
visited.add(value);
applyTraitsToObjectV2(value);
},
});
});
}
function applyTraitsToObjectV2(value) {
if (Array.isArray(value.traits)) {
for (const trait of value.traits) {
for (const key in trait) {
value[String(key)] = mergePatch(value[String(key)], trait[String(key)]);
}
}
}
}
const v3TraitPaths = [
// operations
'$.operations.*',
'$.components.operations.*',
'$.channels.*.[publish,subscribe]',
'$.components.channels.*.[publish,subscribe]',
// messages
'$.channels.*.messages.*',
'$.operations.*.messages.*',
'$.components.channels.*.messages.*',
'$.components.operations.*.messages.*',
'$.channels.*.[publish,subscribe].message',
'$.channels.*.[publish,subscribe].message.oneOf.*',
'$.components.channels.*.[publish,subscribe].message',
'$.components.channels.*.[publish,subscribe].message.oneOf.*',
'$.components.messages.*',
];
export function applyTraitsV3(asyncapi) {
applyAllTraitsV3(asyncapi, v3TraitPaths);
applyAllTraits(asyncapi, v3TraitPaths);
}
function applyAllTraitsV3(asyncapi, paths) {
function applyAllTraits(asyncapi, paths) {
const visited = new Set();

@@ -70,3 +44,3 @@ paths.forEach(path => {

visited.add(value);
applyTraitsToObjectV3(value);
applyTraits(value);
},

@@ -76,18 +50,10 @@ });

}
function applyTraitsToObjectV3(value) {
if (!Array.isArray(value.traits)) {
return;
}
// shallow copy of object
const copy = Object.assign({}, value);
// reset the object but preserve the reference
for (const key in value) {
delete value[key];
}
// merge root object at the end
for (const trait of [...copy.traits, copy]) {
for (const key in trait) {
value[String(key)] = mergePatch(value[String(key)], trait[String(key)]);
function applyTraits(value) {
if (Array.isArray(value.traits)) {
for (const trait of value.traits) {
for (const key in trait) {
value[String(key)] = mergePatch(value[String(key)], trait[String(key)]);
}
}
}
}

@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
import { applyTraitsV2, applyTraitsV3 } from './apply-traits';
import { checkCircularRefs } from './check-circular-refs';
import { applyTraitsV2 } from './apply-traits';
import { resolveCircularRefs } from './resolve-circular-refs';
import { parseSchemasV2 } from './parse-schema';
import { anonymousNaming } from './anonymous-naming';
import { resolveCircularRefs } from './resolve-circular-refs';
export function customOperations(parser, document, detailed, inventory, options) {

@@ -20,3 +19,3 @@ return __awaiter(this, void 0, void 0, function* () {

case 2: return operationsV2(parser, document, detailed, inventory, options);
case 3: return operationsV3(parser, document, detailed, inventory, options);
// case 3: return operationsV3(parser, document, detailed, options);
}

@@ -27,3 +26,2 @@ });

return __awaiter(this, void 0, void 0, function* () {
checkCircularRefs(document);
if (options.applyTraits) {

@@ -42,14 +40,1 @@ applyTraitsV2(detailed.parsed);

}
function operationsV3(parser, document, detailed, inventory, options) {
return __awaiter(this, void 0, void 0, function* () {
checkCircularRefs(document);
if (options.applyTraits) {
applyTraitsV3(detailed.parsed);
}
// TODO: Support schema parsing in v3
// if (options.parseSchemas) {
// await parseSchemasV2(parser, detailed);
// }
anonymousNaming(document);
});
}

@@ -9,4 +9,4 @@ import { AsyncAPIDocumentV2, AsyncAPIDocumentV3 } from './models';

return new AsyncAPIDocumentV2(asyncapi.parsed, { asyncapi, pointer: '/' });
case 3:
return new AsyncAPIDocumentV3(asyncapi.parsed, { asyncapi, pointer: '/' });
// case 3:
// return new AsyncAPIDocumentV3(asyncapi.parsed, { asyncapi, pointer: '/' });
default:

@@ -13,0 +13,0 @@ throw new Error(`Unsupported AsyncAPI version: ${asyncapi.semver.version}`);

@@ -11,4 +11,4 @@ import type { BaseModel } from './base';

import type { ServersInterface } from './servers';
import type { v2, v3 } from '../spec-types';
export interface AsyncAPIDocumentInterface extends BaseModel<v2.AsyncAPIObject | v3.AsyncAPIObject>, ExtensionsMixinInterface {
import type { v2 } from '../spec-types';
export interface AsyncAPIDocumentInterface extends BaseModel<v2.AsyncAPIObject>, ExtensionsMixinInterface {
version(): string;

@@ -15,0 +15,0 @@ defaultContentType(): string | undefined;

@@ -9,3 +9,3 @@ import type { BaseModel } from './base';

id(): string;
address(): string | null | undefined;
address(): string;
servers(): ServersInterface;

@@ -12,0 +12,0 @@ operations(): OperationsInterface;

@@ -8,4 +8,3 @@ import type { BaseModel } from './base';

id(): string;
hasSchemaFormat(): boolean;
schemaFormat(): string | undefined;
schemaFormat(): string;
hasMessageId(): boolean;

@@ -12,0 +11,0 @@ messageId(): string | undefined;

@@ -8,4 +8,2 @@ import type { BindingsInterface } from './bindings';

}
export interface CoreMixinInterface extends BindingsMixinInterface, DescriptionMixinInterface, ExtensionsMixinInterface, ExternalDocumentationMixinInterface, SummaryMixinInterface, TagsMixinInterface, TitleMixinInterface {
}
export interface DescriptionMixinInterface {

@@ -22,12 +20,4 @@ hasDescription(): boolean;

}
export interface SummaryMixinInterface {
hasSummary(): boolean;
summary(): string | undefined;
}
export interface TagsMixinInterface {
tags(): TagsInterface;
}
export interface TitleMixinInterface {
hasTitle(): boolean;
title(): string | undefined;
}

@@ -5,3 +5,3 @@ import type { BaseModel } from './base';

export interface OperationTraitInterface extends BaseModel, BindingsMixinInterface, DescriptionMixinInterface, ExtensionsMixinInterface, ExternalDocumentationMixinInterface, TagsMixinInterface {
id(): string | undefined;
id(): string;
hasOperationId(): boolean;

@@ -8,0 +8,0 @@ operationId(): string | undefined;

@@ -51,3 +51,2 @@ import type { BaseModel } from './base';

required(): Array<string> | undefined;
schemaFormat(): string;
then(): SchemaInterface | undefined;

@@ -54,0 +53,0 @@ title(): string | undefined;

@@ -11,5 +11,2 @@ import type { BaseModel } from './base';

url(): string;
host(): string;
hasPathname(): boolean;
pathname(): string | undefined;
protocol(): string;

@@ -16,0 +13,0 @@ protocolVersion(): string | undefined;

@@ -48,14 +48,11 @@ import { BaseModel } from '../base';

hasExternalDocs() {
const asyncapiV2 = this._meta.asyncapi.parsed;
return Object.keys(asyncapiV2.externalDocs || {}).length > 0;
return Object.keys(this._meta.asyncapi.parsed.externalDocs || {}).length > 0;
}
externalDocs() {
if (this.hasExternalDocs()) {
const asyncapiV2 = this._meta.asyncapi.parsed;
return this.createModel(ExternalDocumentation, asyncapiV2.externalDocs, { pointer: '/externalDocs' });
return this.createModel(ExternalDocumentation, this._meta.asyncapi.parsed.externalDocs, { pointer: '/externalDocs' });
}
}
tags() {
const asyncapiV2 = this._meta.asyncapi.parsed;
const tags = asyncapiV2.tags || [];
const tags = this._meta.asyncapi.parsed.tags || [];
return new Tags(tags.map((tag, idx) => this.createModel(Tag, tag, { pointer: `/tags/${idx}` })));

@@ -62,0 +59,0 @@ }

@@ -15,4 +15,3 @@ import { BaseModel } from '../base';

id(): string;
hasSchemaFormat(): boolean;
schemaFormat(): string | undefined;
schemaFormat(): string;
hasMessageId(): boolean;

@@ -19,0 +18,0 @@ messageId(): string | undefined;

@@ -7,4 +7,4 @@ import { BaseModel } from '../base';

import { xParserMessageName } from '../../constants';
import { getDefaultSchemaFormat } from '../../schema-parser';
import { bindings, hasDescription, description, extensions, hasExternalDocs, externalDocs, tags } from './mixins';
import { getDefaultSchemaFormat } from '../../schema-parser';
export class MessageTrait extends BaseModel {

@@ -14,5 +14,2 @@ id() {

}
hasSchemaFormat() {
return this.schemaFormat() !== undefined;
}
schemaFormat() {

@@ -19,0 +16,0 @@ return this._json.schemaFormat || getDefaultSchemaFormat(this._meta.asyncapi.semver.version);

@@ -16,3 +16,3 @@ import { Channels } from './channels';

return undefined;
return this.createModel(Schema, this._json.payload, { pointer: `${this._meta.pointer}/payload`, schemaFormat: this._json.schemaFormat });
return this.createModel(Schema, this._json.payload, { pointer: `${this._meta.pointer}/payload` });
}

@@ -19,0 +19,0 @@ servers() {

@@ -9,3 +9,2 @@ import { BaseModel } from '../base';

parent?: Schema;
schemaFormat?: string;
}> implements SchemaInterface {

@@ -58,3 +57,2 @@ id(): string;

required(): Array<string> | undefined;
schemaFormat(): string;
then(): SchemaInterface | undefined;

@@ -61,0 +59,0 @@ title(): string | undefined;

import { BaseModel } from '../base';
import { xParserSchemaId } from '../../constants';
import { extensions, hasExternalDocs, externalDocs } from './mixins';
import { getDefaultSchemaFormat } from '../../schema-parser';
export class Schema extends BaseModel {

@@ -271,5 +270,2 @@ id() {

}
schemaFormat() {
return this._meta.schemaFormat || getDefaultSchemaFormat(this._meta.asyncapi.semver.version);
}
then() {

@@ -276,0 +272,0 @@ if (typeof this._json === 'boolean' || typeof this._json.then !== 'object')

@@ -17,5 +17,2 @@ import { BaseModel } from '../base';

url(): string;
host(): string;
hasPathname(): boolean;
pathname(): string | undefined;
protocol(): string;

@@ -22,0 +19,0 @@ hasProtocolVersion(): boolean;

@@ -20,13 +20,2 @@ import { BaseModel } from '../base';

}
host() {
const url = new URL(this.url());
return url.host;
}
hasPathname() {
return !!this.pathname();
}
pathname() {
const url = new URL(this.url());
return url.pathname;
}
protocol() {

@@ -33,0 +22,0 @@ return this._json.protocol;

import { BaseModel } from '../base';
import type { AsyncAPIDocumentInterface } from '../asyncapi';
import type { InfoInterface } from '../info';
import type { ServersInterface } from '../servers';
import type { ChannelsInterface } from '../channels';
import type { OperationsInterface } from '../operations';
import type { MessagesInterface } from '../messages';
import type { ComponentsInterface } from '../components';
import type { SecuritySchemesInterface } from '../security-schemes';
import type { ExtensionsInterface } from '../extensions';
import type { SchemasInterface } from 'models/schemas';
import type { v3 } from '../../spec-types';
export declare class AsyncAPIDocument extends BaseModel<v3.AsyncAPIObject> implements AsyncAPIDocumentInterface {
export declare class AsyncAPIDocument extends BaseModel {
version(): string;
defaultContentType(): string | undefined;
hasDefaultContentType(): boolean;
info(): InfoInterface;
servers(): ServersInterface;
channels(): ChannelsInterface;
operations(): OperationsInterface;
messages(): MessagesInterface;
schemas(): any;
securitySchemes(): SecuritySchemesInterface;
components(): ComponentsInterface;
allServers(): ServersInterface;
allChannels(): ChannelsInterface;
allOperations(): OperationsInterface;
allMessages(): MessagesInterface;
allSchemas(): SchemasInterface;
extensions(): ExtensionsInterface;
private __schemas;
}
import { BaseModel } from '../base';
import { Info } from './info';
import { Servers } from './servers';
import { Server } from './server';
import { Channels } from './channels';
import { Channel } from './channel';
import { Operations } from './operations';
import { Operation } from './operation';
import { Messages } from './messages';
import { SecuritySchemes } from './security-schemes';
import { SecurityScheme } from './security-scheme';
import { Components } from './components';
import { Schemas } from './schemas';
import { extensions } from './mixins';
import { tilde } from '../../utils';
import { SchemaTypesToIterate, traverseAsyncApiDocument } from '../../iterator';
export class AsyncAPIDocument extends BaseModel {

@@ -21,85 +6,2 @@ version() {

}
defaultContentType() {
return this._json.defaultContentType;
}
hasDefaultContentType() {
return !!this._json.defaultContentType;
}
info() {
return this.createModel(Info, this._json.info, { pointer: '/info' });
}
servers() {
return new Servers(Object.entries(this._json.servers || {}).map(([serverName, server]) => this.createModel(Server, server, { id: serverName, pointer: `/servers/${tilde(serverName)}` })));
}
channels() {
return new Channels(Object.entries(this._json.channels || {}).map(([channelId, channel]) => this.createModel(Channel, channel, { id: channelId, pointer: `/channels/${tilde(channelId)}` })));
}
operations() {
return new Operations(Object.entries(this._json.operations || {}).map(([operationId, operation]) => this.createModel(Operation, operation, { id: operationId, pointer: `/operations/${tilde(operationId)}` })));
}
messages() {
const messages = [];
const messagesData = [];
this.channels().forEach(channel => {
channel.messages().forEach(message => {
const messageData = message.json();
if (!messagesData.includes(messageData)) {
messagesData.push(messageData);
messages.push(message);
}
});
});
return new Messages(messages);
}
schemas() {
return null;
}
securitySchemes() {
var _a;
return new SecuritySchemes(Object.entries(((_a = this._json.components) === null || _a === void 0 ? void 0 : _a.securitySchemes) || {}).map(([securitySchemeName, securityScheme]) => this.createModel(SecurityScheme, securityScheme, { id: securitySchemeName, pointer: `/components/securitySchemes/${securitySchemeName}` })));
}
components() {
return this.createModel(Components, this._json.components || {}, { pointer: '/components' });
}
allServers() {
const servers = this.servers();
this.components().servers().forEach(server => !servers.some(s => s.json() === server.json()) && servers.push(server));
return new Servers(servers);
}
allChannels() {
const channels = this.channels();
this.components().channels().forEach(channel => !channels.some(c => c.json() === channel.json()) && channels.push(channel));
return new Channels(channels);
}
allOperations() {
const operations = [];
this.allChannels().forEach(channel => operations.push(...channel.operations()));
return new Operations(operations);
}
allMessages() {
const messages = [];
this.allOperations().forEach(operation => operation.messages().forEach(message => (!messages.some(m => m.json() === message.json()) && messages.push(message))));
this.components().messages().forEach(message => (!messages.some(m => m.json() === message.json()) && messages.push(message)));
return new Messages(messages);
}
allSchemas() {
return this.__schemas(true);
}
extensions() {
return extensions(this);
}
__schemas(withComponents) {
const schemas = new Set();
function callback(schema) {
if (!schemas.has(schema.json())) {
schemas.add(schema);
}
}
let toIterate = Object.values(SchemaTypesToIterate);
if (!withComponents) {
toIterate = toIterate.filter(s => s !== SchemaTypesToIterate.Components);
}
traverseAsyncApiDocument(this, callback, toIterate);
return new Schemas(Array.from(schemas));
}
}
export { AsyncAPIDocument as AsyncAPIDocumentV3 } from './asyncapi';
export { Binding as BindingV3 } from './binding';
export { Bindings as BindingsV3 } from './bindings';
export { ChannelParameter as ChannelParameterV3 } from './channel-parameter';
export { ChannelParameters as ChannelParametersV3 } from './channel-parameters';
export { Channel as ChannelV3 } from './channel';
export { Channels as ChannelsV3 } from './channels';
export { Components as ComponentsV3 } from './components';
export { Contact as ContactV3 } from './contact';
export { CorrelationId as CorrelationIdV3 } from './correlation-id';
export { Extension as ExtensionV3 } from './extension';
export { Extensions as ExtensionsV3 } from './extensions';
export { ExternalDocumentation as ExternalDocumentationV3 } from './external-docs';
export { Info as InfoV3 } from './info';
export { License as LicenseV3 } from './license';
export { MessageExample as MessageExampleV3 } from './message-example';
export { MessageExamples as MessageExamplesV3 } from './message-examples';
export { MessageTrait as MessageTraitV3 } from './message-trait';
export { MessageTraits as MessageTraitsV3 } from './message-traits';
export { Message as MessageV3 } from './message';
export { Messages as MessagesV3 } from './messages';
export { OAuthFlow as OAuthFlowV3 } from './oauth-flow';
export { OAuthFlows as OAuthFlowsV3 } from './oauth-flows';
export { OperationTrait as OperationTraitV3 } from './operation-trait';
export { OperationTraits as OperationTraitsV3 } from './operation-traits';
export { OperationReplies as OperationRepliesV3 } from './operation-replies';
export { OperationReplyAddress as OperationReplyAddressV3 } from './operation-reply-address';
export { OperationReplyAddresses as OperationReplyAddressesV3 } from './operation-reply-addresses';
export { OperationReply as OperationReplyV3 } from './operation-reply';
export { Operation as OperationV3 } from './operation';
export { Operations as OperationsV3 } from './operations';
export { Schema as SchemaV3 } from './schema';
export { Schemas as SchemasV3 } from './schemas';
export { SecurityScheme as SecuritySchemeV3 } from './security-scheme';
export { SecuritySchemes as SecuritySchemesV3 } from './security-schemes';
export { ServerVariable as ServerVariableV3 } from './server-variable';
export { ServerVariables as ServerVariablesV3 } from './server-variables';
export { Server as ServerV3 } from './server';
export { Servers as ServersV3 } from './servers';
export { Tag as TagV3 } from './tag';
export { Tags as TagsV3 } from './tags';
export { AsyncAPIDocument as AsyncAPIDocumentV3 } from './asyncapi';
export { Binding as BindingV3 } from './binding';
export { Bindings as BindingsV3 } from './bindings';
export { ChannelParameter as ChannelParameterV3 } from './channel-parameter';
export { ChannelParameters as ChannelParametersV3 } from './channel-parameters';
export { Channel as ChannelV3 } from './channel';
export { Channels as ChannelsV3 } from './channels';
export { Components as ComponentsV3 } from './components';
export { Contact as ContactV3 } from './contact';
export { CorrelationId as CorrelationIdV3 } from './correlation-id';
export { Extension as ExtensionV3 } from './extension';
export { Extensions as ExtensionsV3 } from './extensions';
export { ExternalDocumentation as ExternalDocumentationV3 } from './external-docs';
export { Info as InfoV3 } from './info';
export { License as LicenseV3 } from './license';
export { MessageExample as MessageExampleV3 } from './message-example';
export { MessageExamples as MessageExamplesV3 } from './message-examples';
export { MessageTrait as MessageTraitV3 } from './message-trait';
export { MessageTraits as MessageTraitsV3 } from './message-traits';
export { Message as MessageV3 } from './message';
export { Messages as MessagesV3 } from './messages';
export { OAuthFlow as OAuthFlowV3 } from './oauth-flow';
export { OAuthFlows as OAuthFlowsV3 } from './oauth-flows';
export { OperationTrait as OperationTraitV3 } from './operation-trait';
export { OperationTraits as OperationTraitsV3 } from './operation-traits';
export { OperationReplies as OperationRepliesV3 } from './operation-replies';
export { OperationReplyAddress as OperationReplyAddressV3 } from './operation-reply-address';
export { OperationReplyAddresses as OperationReplyAddressesV3 } from './operation-reply-addresses';
export { OperationReply as OperationReplyV3 } from './operation-reply';
export { Operation as OperationV3 } from './operation';
export { Operations as OperationsV3 } from './operations';
export { Schema as SchemaV3 } from './schema';
export { Schemas as SchemasV3 } from './schemas';
export { SecurityScheme as SecuritySchemeV3 } from './security-scheme';
export { SecuritySchemes as SecuritySchemesV3 } from './security-schemes';
export { ServerVariable as ServerVariableV3 } from './server-variable';
export { ServerVariables as ServerVariablesV3 } from './server-variables';
export { Server as ServerV3 } from './server';
export { Servers as ServersV3 } from './servers';
export { Tag as TagV3 } from './tag';
export { Tags as TagsV3 } from './tags';
import type { Format } from '@stoplight/spectral-core';
export declare const aas2: Format;
export declare const aas2_0: Format;
export declare const aas2_1: Format;
export declare const aas2_2: Format;
export declare const aas2_3: Format;
export declare const aas2_4: Format;
export declare const aas2_5: Format;
export declare const aas2_6: Format;
export declare const aas2All: Format<void>[];
export declare class Formats extends Map<string, Format> {
filterByMajorVersions(majorsToInclude: string[]): Formats;
excludeByVersions(versionsToExclude: string[]): Formats;
find(version: string): Format | undefined;
formats(): Format[];
}
export declare const AsyncAPIFormats: Formats;

@@ -1,28 +0,41 @@

/* eslint-disable security/detect-unsafe-regex */
import { isObject } from '../utils';
const aas2Regex = /^2\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/;
const aas2_0Regex = /^2\.0(?:\.[0-9]*)?$/;
const aas2_1Regex = /^2\.1(?:\.[0-9]*)?$/;
const aas2_2Regex = /^2\.2(?:\.[0-9]*)?$/;
const aas2_3Regex = /^2\.3(?:\.[0-9]*)?$/;
const aas2_4Regex = /^2\.4(?:\.[0-9]*)?$/;
const aas2_5Regex = /^2\.5(?:\.[0-9]*)?$/;
const aas2_6Regex = /^2\.6(?:\.[0-9]*)?$/;
const isAas2 = (document) => isObject(document) && 'asyncapi' in document && aas2Regex.test(String(document.asyncapi));
export const aas2 = isAas2;
aas2.displayName = 'AsyncAPI 2.x';
export const aas2_0 = (document) => isAas2(document) && aas2_0Regex.test(String(document.asyncapi));
aas2_0.displayName = 'AsyncAPI 2.0.x';
export const aas2_1 = (document) => isAas2(document) && aas2_1Regex.test(String(document.asyncapi));
aas2_1.displayName = 'AsyncAPI 2.1.x';
export const aas2_2 = (document) => isAas2(document) && aas2_2Regex.test(String(document.asyncapi));
aas2_2.displayName = 'AsyncAPI 2.2.x';
export const aas2_3 = (document) => isAas2(document) && aas2_3Regex.test(String(document.asyncapi));
aas2_3.displayName = 'AsyncAPI 2.3.x';
export const aas2_4 = (document) => isAas2(document) && aas2_4Regex.test(String(document.asyncapi));
aas2_4.displayName = 'AsyncAPI 2.4.x';
export const aas2_5 = (document) => isAas2(document) && aas2_5Regex.test(String(document.asyncapi));
aas2_5.displayName = 'AsyncAPI 2.5.x';
export const aas2_6 = (document) => isAas2(document) && aas2_6Regex.test(String(document.asyncapi));
aas2_6.displayName = 'AsyncAPI 2.6.x';
export const aas2All = [aas2_0, aas2_1, aas2_2, aas2_3, aas2_4, aas2_5, aas2_6];
import { getSemver, isObject } from '../utils';
import { schemas } from '@asyncapi/specs';
export class Formats extends Map {
filterByMajorVersions(majorsToInclude) {
return new Formats([...this.entries()].filter(element => { return majorsToInclude.includes(element[0].split('.')[0]); }));
}
excludeByVersions(versionsToExclude) {
return new Formats([...this.entries()].filter(element => { return !versionsToExclude.includes(element[0]); }));
}
find(version) {
return this.get(formatVersion(version));
}
formats() {
return [...this.values()];
}
}
export const AsyncAPIFormats = new Formats(Object.entries(schemas).reverse().map(([version]) => [version, createFormat(version)])); // reverse is used for giving newer versions a higher priority when matching
function isAsyncAPIVersion(versionToMatch, document) {
const asyncAPIDoc = document;
if (!asyncAPIDoc)
return false;
const documentVersion = String(asyncAPIDoc.asyncapi);
return isObject(document) && 'asyncapi' in document
&& assertValidAsyncAPIVersion(documentVersion)
&& versionToMatch === formatVersion(documentVersion);
}
function assertValidAsyncAPIVersion(documentVersion) {
const semver = getSemver(documentVersion);
const regexp = new RegExp(`^(${semver.major})\\.(${semver.minor})\\.(0|[1-9][0-9]*)$`); // eslint-disable-line security/detect-non-literal-regexp
return regexp.test(documentVersion);
}
function createFormat(version) {
const format = (document) => isAsyncAPIVersion(version, document);
const semver = getSemver(version);
format.displayName = `AsyncAPI ${semver.major}.${semver.minor}.x`;
return format;
}
const formatVersion = function (version) {
const versionSemver = getSemver(version);
return `${versionSemver.major}.${versionSemver.minor}.0`;
};

@@ -0,3 +1,5 @@

import type { Format } from '@stoplight/spectral-core';
export declare function getSchema(docFormats: Set<Format>): Record<string, any> | void;
export declare const documentStructure: import("@stoplight/spectral-core").RulesetFunctionWithValidator<unknown, {
resolved: boolean;
}>;
import specs from '@asyncapi/specs';
import { createRulesetFunction } from '@stoplight/spectral-core';
import { schema as schemaFn } from '@stoplight/spectral-functions';
import { aas2_0, aas2_1, aas2_2, aas2_3, aas2_4, aas2_5, aas2_6 } from '../formats';
import { AsyncAPIFormats } from '../formats';
function shouldIgnoreError(error) {

@@ -67,20 +67,7 @@ return (

}
function getSchema(formats) {
switch (true) {
case formats.has(aas2_6):
return getSerializedSchema('2.6.0');
case formats.has(aas2_5):
return getSerializedSchema('2.5.0');
case formats.has(aas2_4):
return getSerializedSchema('2.4.0');
case formats.has(aas2_3):
return getSerializedSchema('2.3.0');
case formats.has(aas2_2):
return getSerializedSchema('2.2.0');
case formats.has(aas2_1):
return getSerializedSchema('2.1.0');
case formats.has(aas2_0):
return getSerializedSchema('2.0.0');
default:
return;
export function getSchema(docFormats) {
for (const [version, format] of AsyncAPIFormats) {
if (docFormats.has(format)) {
return getSerializedSchema(version);
}
}

@@ -87,0 +74,0 @@ }

import { unreferencedReusableObject } from '@stoplight/spectral-functions';
import { createRulesetFunction } from '@stoplight/spectral-core';
import { aas2 } from '../formats';
import { isObject } from '../../utils';

@@ -20,5 +19,5 @@ export const unusedComponent = createRulesetFunction({

Object.keys(components).forEach(componentType => {
// if component type is `securitySchemes` and we operate on AsyncAPI 2.x.x skip validation
// security schemes in 2.x.x are referenced by keys, not by object ref - for this case we have a separate `asyncapi2-unused-securityScheme` rule
if (componentType === 'securitySchemes' && aas2(targetVal, null)) {
// if component type is `securitySchemes` we skip the validation
// security schemes in >=2.x.x are referenced by keys, not by object ref - for this case we have a separate `asyncapi2-unused-securityScheme` rule
if (componentType === 'securitySchemes') {
return;

@@ -25,0 +24,0 @@ }

@@ -172,2 +172,3 @@ export declare const coreRuleset: {

description: string;
formats: import("@stoplight/spectral-core").Format<void>[];
recommended: boolean;

@@ -174,0 +175,0 @@ resolved: boolean;

@@ -1,2 +0,1 @@

import { aas2All as aas2AllFormats } from './formats';
import { lastVersion } from '../constants';

@@ -8,5 +7,6 @@ import { truthy, schema } from '@stoplight/spectral-functions';

import { unusedComponent } from './functions/unusedComponent';
import { AsyncAPIFormats } from './formats';
export const coreRuleset = {
description: 'Core AsyncAPI x.x.x ruleset.',
formats: [...aas2AllFormats],
formats: AsyncAPIFormats.filterByMajorVersions(['2']).formats(),
rules: {

@@ -81,3 +81,3 @@ /**

description: 'Recommended AsyncAPI x.x.x ruleset.',
formats: [...aas2AllFormats],
formats: AsyncAPIFormats.filterByMajorVersions(['2']).formats(),
rules: {

@@ -187,2 +187,3 @@ /**

description: 'Potentially unused component has been detected in AsyncAPI document.',
formats: AsyncAPIFormats.filterByMajorVersions(['2']).formats(),
recommended: true,

@@ -189,0 +190,0 @@ resolved: false,

@@ -0,2 +1,10 @@

import { schema as schemaFn } from '@stoplight/spectral-functions';
import type { JsonPath } from '@stoplight/types';
import type { RulesetFunctionContext } from '@stoplight/spectral-core';
import type { v2 } from 'spec-types';
export declare function getMessageExamples(message: v2.MessageObject): Array<{
path: JsonPath;
value: v2.MessageExampleObject;
}>;
export declare function validate(value: unknown, path: JsonPath, type: 'payload' | 'headers', schema: unknown, ctx: RulesetFunctionContext): ReturnType<typeof schemaFn>;
export declare const messageExamples: import("@stoplight/spectral-core").RulesetFunctionWithValidator<v2.MessageObject, null>;

@@ -22,3 +22,3 @@ import { createRulesetFunction } from '@stoplight/spectral-core';

}
function getMessageExamples(message) {
export function getMessageExamples(message) {
var _a;

@@ -35,3 +35,3 @@ if (!Array.isArray(message.examples)) {

}
function validate(value, path, type, schema, ctx) {
export function validate(value, path, type, schema, ctx) {
return schemaFn(value, {

@@ -38,0 +38,0 @@ allErrors: true,

@@ -148,3 +148,2 @@ import type { Parser } from '../../parser';

description: string;
formats: import("@stoplight/spectral-core").Format<void>[];
rules: {

@@ -188,2 +187,3 @@ 'asyncapi2-schemas': import("@stoplight/spectral-core").RuleDefinition;

};
'asyncapi2-message-examples-custom-format': import("@stoplight/spectral-core").RuleDefinition;
};

@@ -190,0 +190,0 @@ };

/* eslint-disable sonarjs/no-duplicate-string */
import { aas2All as aas2AllFormats } from '../formats';
import { AsyncAPIFormats } from '../formats';
import { truthy, pattern } from '@stoplight/spectral-functions';

@@ -8,2 +8,3 @@ import { channelParameters } from './functions/channelParameters';

import { messageExamples } from './functions/messageExamples';
import { asyncApi2MessageExamplesParserRule } from './functions/messageExamples-spectral-rule-v2';
import { messageIdUniqueness } from './functions/messageIdUniqueness';

@@ -19,3 +20,3 @@ import { operationIdUniqueness } from './functions/operationIdUniqueness';

description: 'Core AsyncAPI 2.x.x ruleset.',
formats: [...aas2AllFormats],
formats: AsyncAPIFormats.filterByMajorVersions(['2']).formats(),
rules: {

@@ -119,5 +120,5 @@ /**

// messages
'$.channels.*.[publish,subscribe].[?(@property === \'message\' && @.schemaFormat === void 0)]',
'$.channels.*.[publish,subscribe][?(@property === \'message\' && @.schemaFormat === void 0)]',
'$.channels.*.[publish,subscribe].message.oneOf[?(!@null && @.schemaFormat === void 0)]',
'$.components.channels.*.[publish,subscribe].[?(@property === \'message\' && @.schemaFormat === void 0)]',
'$.components.channels.*.[publish,subscribe][?(@property === \'message\' && @.schemaFormat === void 0)]',
'$.components.channels.*.[publish,subscribe].message.oneOf[?(!@null && @.schemaFormat === void 0)]',

@@ -187,3 +188,2 @@ '$.components.messages[?(!@null && @.schemaFormat === void 0)]',

description: 'Schemas AsyncAPI 2.x.x ruleset.',
formats: [...aas2AllFormats],
rules: {

@@ -235,2 +235,3 @@ 'asyncapi2-schemas': asyncApi2SchemaParserRule(parser),

},
'asyncapi2-message-examples-custom-format': asyncApi2MessageExamplesParserRule(parser),
}

@@ -241,3 +242,3 @@ };

description: 'Recommended AsyncAPI 2.x.x ruleset.',
formats: [...aas2AllFormats],
formats: AsyncAPIFormats.filterByMajorVersions(['2']).formats(),
rules: {

@@ -328,3 +329,3 @@ /**

recommended: true,
formats: aas2AllFormats.slice(4),
formats: AsyncAPIFormats.filterByMajorVersions(['2']).excludeByVersions(['2.0.0', '2.1.0', '2.2.0', '2.3.0']).formats(),
given: [

@@ -331,0 +332,0 @@ '$.channels.*.[publish,subscribe][?(@property === "message" && @.oneOf == void 0)]',

@@ -25,5 +25,5 @@ import type { Parser } from '../parser';

export declare function validateSchema(parser: Parser, input: ValidateSchemaInput): Promise<void | import("@stoplight/spectral-core").IFunctionResult[]>;
export declare function parseSchema(parser: Parser, input: ParseSchemaInput): Promise<AsyncAPISchema>;
export declare function parseSchema(parser: Parser, input: ParseSchemaInput): Promise<import("../spec-types/v2").AsyncAPISchemaObject>;
export declare function registerSchemaParser(parser: Parser, schemaParser: SchemaParser): void;
export declare function getSchemaFormat(schematFormat: string | undefined, asyncapiVersion: string): string;
export declare function getDefaultSchemaFormat(asyncapiVersion: string): string;
export * as v2 from './v2';
export * as v3 from './v3';
export * as v2 from './v2';
export * as v3 from './v3';
import type { ISpectralDiagnostic, IFunctionResult } from '@stoplight/spectral-core';
import type { AsyncAPIDocumentInterface } from './models';
import type { v2, v3 } from './spec-types';
import type { v2 } from './spec-types';
export type MaybeAsyncAPI = {

@@ -23,3 +23,3 @@ asyncapi: string;

export type SchemaValidateResult = IFunctionResult;
export type AsyncAPIObject = v2.AsyncAPIObject | v3.AsyncAPIObject;
export type AsyncAPISchema = v2.AsyncAPISchemaObject | v3.AsyncAPISchemaObject;
export type AsyncAPIObject = v2.AsyncAPIObject;
export type AsyncAPISchema = v2.AsyncAPISchemaObject;

@@ -23,6 +23,2 @@ import { Document } from '@stoplight/spectral-core';

export declare function findSubArrayIndex(arr: Array<any>, subarr: Array<any>, fromIndex?: number): number;
export declare function resolveServerUrl(url: string): {
host: string;
pathname: string | undefined;
};
export declare function retrieveDeepData(value: Record<string, any>, path: Array<string | number>): Record<string, any> | undefined;

@@ -126,14 +126,2 @@ import { Document } from '@stoplight/spectral-core';

}
export function resolveServerUrl(url) {
// eslint-disable-next-line prefer-const
let [maybeProtocol, maybeHost] = url.split('://');
if (!maybeHost) {
maybeHost = maybeProtocol;
}
const [host, ...pathnames] = maybeHost.split('/');
if (pathnames.length) {
return { host, pathname: `/${pathnames.join('/')}` };
}
return { host, pathname: undefined };
}
export function retrieveDeepData(value, path) {

@@ -140,0 +128,0 @@ let index = 0;

{
"name": "@asyncapi/parser",
"version": "2.1.0-next-major-spec.3",
"version": "2.1.0",
"description": "JavaScript AsyncAPI parser.",

@@ -44,3 +44,3 @@ "bugs": {

"dependencies": {
"@asyncapi/specs": "^6.0.0-next-major-spec.2",
"@asyncapi/specs": "^5.1.0",
"@openapi-contrib/openapi-schema-to-json-schema": "~3.2.0",

@@ -64,2 +64,3 @@ "@stoplight/json-ref-resolver": "^3.1.5",

"devDependencies": {
"@asyncapi/avro-schema-parser": "^3.0.1",
"@jest/types": "^29.0.2",

@@ -66,0 +67,0 @@ "@swc/core": "^1.2.248",

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc