Skip to content

Commit

Permalink
remove Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
aeworxet committed Aug 17, 2024
1 parent c24f84e commit 054b1e9
Show file tree
Hide file tree
Showing 9 changed files with 1,801 additions and 1,882 deletions.
3,165 changes: 1,336 additions & 1,829 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
],
"dependencies": {
"@apidevtools/json-schema-ref-parser": "^11.5.4",
"@asyncapi/parser": "^3.1.0",
"@types/json-schema": "^7.0.11",
"@ungap/structured-clone": "^1.2.0",
"js-yaml": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/document.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import yaml from 'js-yaml';

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

/**
* @class
Expand Down
33 changes: 2 additions & 31 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'path';
import { merge } from 'lodash';
import { Parser } from '@asyncapi/parser';
import {
resolve,
versionCheck,
Expand All @@ -10,8 +9,8 @@ import {

import { Document } from './document';

import type { AsyncAPIObject, Options } from './types';
export type { AsyncAPIObject, Options } from './types';
import type { AsyncAPIObject, Options } from './spec-types';
export type { AsyncAPIObject, Options } from './spec-types';

// remember the directory where execution of the program started
const originDir = String(process.cwd());
Expand Down Expand Up @@ -93,9 +92,6 @@ export default async function bundle(
options: Options = {}
) {
let bundledDocument: any = {};
let validationResult: any = [];

const parser = new Parser();

// if one string was passed, convert it to an array
if (typeof files === 'string') {
Expand Down Expand Up @@ -129,31 +125,6 @@ export default async function bundle(
// properties into a familiar form.
bundledDocument = orderPropsAccToAsyncAPISpec(bundledDocument);

// Option `noValidation: true` is used by the testing system, which
// intentionally feeds Bundler wrong AsyncAPI Documents, thus it is not
// documented.
if (!options.noValidation) {
validationResult = await parser.validate(
JSON.parse(JSON.stringify(bundledDocument))
);
}

// If Parser's `validate()` function returns a non-empty array with at least
// one `severity: 0`, that means there was at least one error during
// validation, not a `warning: 1`, `info: 2`, or `hint: 3`. Thus, array's
// elements with `severity: 0` are outputted as a list of remarks, and the
// program throws.
if (
validationResult.length !== 0 &&
validationResult.map((element: any) => element.severity).includes(0)
) {
console.log(
'Validation of the resulting AsyncAPI Document failed.\nList of remarks:\n',
validationResult.filter((element: any) => element.severity === 0)
);
throw new Error();
}

// return to the starting directory before finishing the execution
if (options.baseDir) {
process.chdir(originDir);
Expand Down
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import $RefParser from '@apidevtools/json-schema-ref-parser';

import type { ParserOptions as $RefParserOptions } from '@apidevtools/json-schema-ref-parser';
import type { AsyncAPIObject, Options as BundlerOptions } from './types';
import type { AsyncAPIObject, Options as BundlerOptions } from './spec-types';

let RefParserOptions: $RefParserOptions;

Expand Down
Loading

0 comments on commit 054b1e9

Please sign in to comment.