Skip to content

Commit

Permalink
feat: add x-origin property
Browse files Browse the repository at this point in the history
  • Loading branch information
aeworxet committed Mar 11, 2024
1 parent a9d96fb commit 9e34bd4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
27 changes: 16 additions & 11 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,22 @@ export async function parse(JSONSchema: AsyncAPIObject) {
const result = await parser.validate(
JSON.parse(JSON.stringify(dereferencedJSONSchema))
);

// If Parser's `validate()` function returns a non-empty array, that means
// there were errors during validation. Thus, the array is outputted as a list
// of remarks, and the program exits without doing anything further.
// if (result.length !== 0) {
// console.log(
// 'Validation of the resulting AsyncAPI Document failed.\nList of remarks:\n',
// result
// );
// throw new Error();
// }

// 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 exits without doing anything further.
if (
result.length !== 0 &&
result.map(element => element.severity).includes(0)
) {
console.log(
'Validation of the resulting AsyncAPI Document failed.\nList of remarks:\n',
result.filter(element => element.severity === 0)
);
throw new Error();
}

return result;
}
15 changes: 9 additions & 6 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,17 @@ export const resolve = async (
) => {
const docs = [];

for (const asyncapiDocument of asyncapiDocuments) {
if (options.referenceIntoComponents) {
try {
for (const asyncapiDocument of asyncapiDocuments) {
// if (options.referenceIntoComponents) {
// await parse(asyncapiDocument);
// }
addXOrigins(asyncapiDocument); // eslint-disable-line @typescript-eslint/no-use-before-define
await parse(asyncapiDocument);
// const bundledAsyncAPIDocument = await $RefParser.bundle(asyncapiDocument);
docs.push(asyncapiDocument);
}
addXOrigins(asyncapiDocument); // eslint-disable-line @typescript-eslint/no-use-before-define
const bundledAsyncAPIDocument = await $RefParser.bundle(asyncapiDocument);
docs.push(bundledAsyncAPIDocument);
}
} catch (e) {}

return docs;
};
Expand Down
15 changes: 10 additions & 5 deletions src/v3/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@ export async function parse(JSONSchema: AsyncAPIObject) {
JSON.parse(JSON.stringify(dereferencedJSONSchema))
);

// If Parser's `validate()` function returns a non-empty array, that means
// there were errors during validation. Thus, the array is outputted as a list
// of remarks, and the program exits without doing anything further.
if (result.length !== 0) {
// 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 exits without doing anything further.
if (
result.length !== 0 &&
result.map(element => element.severity).includes(0)
) {
console.log(
'Validation of the resulting AsyncAPI Document failed.\nList of remarks:\n',
result
result.filter(element => element.severity === 0)
);
throw new Error();
}
Expand Down

0 comments on commit 9e34bd4

Please sign in to comment.