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 Apr 6, 2024
1 parent 3d9c222 commit 9416fa4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,16 @@ There are no internal references that MUST be `Reference Object`s.
Regexes of internal references that MUST be `Reference Object`s:

```
/#\/channels\/[a-zA-Z0-9]*\/servers/
/#\/operations\/[a-zA-Z0-9]*\/channel/
/#\/operations\/[a-zA-Z0-9]*\/messages/
/#\/operations\/[a-zA-Z0-9]*\/reply\/channel/
/#\/operations\/[a-zA-Z0-9]*\/reply\/messages/
/#\/components\/channels\/[a-zA-Z0-9]*\/servers/
/#\/components\/operations\/[a-zA-Z0-9]*\/channel/
/#\/components\/operations\/[a-zA-Z0-9]*\/messages/
/#\/components\/operations\/[a-zA-Z0-9]*\/reply\/channel/
/#\/components\/operations\/[a-zA-Z0-9]*\/reply\/messages/
/#\/channels\/,*\/servers/
/#\/operations\/.*\/channel/
/#\/operations\/.*\/messages/
/#\/operations\/.*\/reply\/channel/
/#\/operations\/,*\/reply\/messages/
/#\/components\/channels\/.*\/servers/
/#\/components\/operations\/.*\/channel/
/#\/components\/operations\/.*\/messages/
/#\/components\/operations\/.*\/reply\/channel/
/#\/components\/operations\/.*\/reply\/messages/
```


Expand All @@ -230,7 +230,7 @@ However, if a user doesn't need / doesn't want `x-origin` properties to be prese

### Movement of components to `components`

The movement of all AsyncAPI Specification-valid components to the `components` section of the AsyncAPI Document is done by the [`Optimizer`](https://github.com/asyncapi/optimizer) v1.0.0+.
The movement of all AsyncAPI Specification-valid components to the `components` section of the AsyncAPI Document starting from `Bundler` v0.5.0 is done by the [`Optimizer`](https://github.com/asyncapi/optimizer) v1.0.0+.

To get in CI/code an AsyncAPI Document, that is dereferenced [to its maximum possible extent](#dereference-of-the-external-references) with all of its components moved to the `components` section, the original AsyncAPI Document must be run through chain `Bundler -> Optimizer`.

Expand Down
4 changes: 2 additions & 2 deletions example/bundle-cjs.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const { readFileSync, writeFileSync } = require('fs');
const bundle = require('@asyncapi/bundler');

async function main() {
const document = await bundle(['./main151.yaml', './main153.yaml'].map( f => readFileSync(f, 'utf-8')), {
xOrigin: false,
const document = await bundle([readFileSync('./main.yaml', 'utf-8')], {
xOrigin: true,
});
if (document.yml()) {
writeFileSync('asyncapi.yaml', document.yml());
Expand Down
2 changes: 1 addition & 1 deletion example/bundle-cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function main() {
const filePaths = ['./camera.yml','./audio.yml'];
const document = await bundle(
filePaths.map(filePath => readFileSync(filePath, 'utf-8')), {
// base: readFileSync('./base.yml', 'utf-8'),
base: readFileSync('./base.yml', 'utf-8'),
xOrigin: true
}
);
Expand Down
23 changes: 12 additions & 11 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export async function parse(
case 2:
RefParserOptions = {
dereference: {
circular: false, // prettier-ignore
circular: false,
// prettier-ignore
excludedPathMatcher: (path: string): any => { // eslint-disable-line
return;
},
Expand All @@ -47,16 +48,16 @@ export async function parse(
excludedPathMatcher: (path: string): any => {
return (
// prettier-ignore
(/#\/channels\/[a-zA-Z0-9]*\/servers/).test(path) ||
(/#\/operations\/[a-zA-Z0-9]*\/channel/).test(path) ||
(/#\/operations\/[a-zA-Z0-9]*\/messages/).test(path) ||
(/#\/operations\/[a-zA-Z0-9]*\/reply\/channel/).test(path) ||
(/#\/operations\/[a-zA-Z0-9]*\/reply\/messages/).test(path) ||
(/#\/components\/channels\/[a-zA-Z0-9]*\/servers/).test(path) ||
(/#\/components\/operations\/[a-zA-Z0-9]*\/channel/).test(path) ||
(/#\/components\/operations\/[a-zA-Z0-9]*\/messages/).test(path) ||
(/#\/components\/operations\/[a-zA-Z0-9]*\/reply\/channel/).test(path) ||
(/#\/components\/operations\/[a-zA-Z0-9]*\/reply\/messages/).test(path)
(/#\/channels\/,*\/servers/).test(path) ||
(/#\/operations\/.*\/channel/).test(path) ||
(/#\/operations\/.*\/messages/).test(path) ||
(/#\/operations\/.*\/reply\/channel/).test(path) ||
(/#\/operations\/,*\/reply\/messages/).test(path) ||
(/#\/components\/channels\/.*\/servers/).test(path) ||
(/#\/components\/operations\/.*\/channel/).test(path) ||
(/#\/components\/operations\/.*\/messages/).test(path) ||
(/#\/components\/operations\/.*\/reply\/channel/).test(path) ||
(/#\/components\/operations\/.*\/reply\/messages/).test(path)
);
},
onDereference: (path: string, value: AsyncAPIObject) => {
Expand Down

0 comments on commit 9416fa4

Please sign in to comment.