Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add x-origin property #147

Merged
merged 11 commits into from
Apr 19, 2024

Conversation

aeworxet
Copy link
Collaborator

@aeworxet aeworxet commented Jan 19, 2024

This PR adds the generation of the property x-origin during the dereferencing process.
Property x-origin is used for origin tracing in Bundler and component naming in Optimizer.

It originated from this comment in a year-long discussion: 

The $ref usually also carries a semantical meaning to understand easier what it is (example "$ref : financial-system.yaml#/components/schemas/bankAccountIdentifier"). If the bundling just resolves this ref inline, the semantical meaning of the $ref pointer gets lost and cannot be recovered in later steps. The optimizer would need to invent an artificial component name for the "bankAccountIdentifier" when moving it to the components section.

Thus, property x-origin contains historical values of dereferenced $refs, which are also used by Optimizer starting from its version v1.0.0, to give meaningful names to components it moves through the AsyncAPI Document.

Partial resolution of #141

@aeworxet
Copy link
Collaborator Author

@KhudaDad414 @derberg
@asyncapi/bounty_team

@aeworxet aeworxet linked an issue Jan 29, 2024 that may be closed by this pull request
@aeworxet aeworxet marked this pull request as ready for review February 10, 2024 07:31
@aeworxet aeworxet self-assigned this Feb 14, 2024
@aeworxet aeworxet force-pushed the feat-add-x-origin-property branch from e141d82 to 30a0f3c Compare February 19, 2024 10:42
@aeworxet aeworxet removed their assignment Feb 20, 2024
@aeworxet aeworxet force-pushed the feat-add-x-origin-property branch from db76cf3 to e41e46c Compare February 22, 2024 12:34
Copy link
Member

@KhudaDad414 KhudaDad414 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aeworxet Tests are failing for some reason. 🤔

src/util.ts Outdated Show resolved Hide resolved
@savvyintegrations
Copy link

savvyintegrations commented Mar 19, 2024

For anyone waiting on this PR who doesn't want to fork, and doesn't need x-origin per se (but simply better deref), you can use @apidevtools/json-schema-ref-parser in your local script before calling bundler, i.e., just dereference first, e.g.:

import bundle from '@asyncapi/bundler';
import $RefParser from "@apidevtools/json-schema-ref-parser";
import { writeFileSync } from 'fs';
import { resolve } from "node:path"
import { mkdir } from "node:fs/promises"

process.chdir("specs")

const srcFileName = 'events.asyncapi.yml';
const outputBase = resolve("../generated/docs/specs") + "/"
const outputPath = `${outputBase}${srcFileName}`;

try {
    await mkdir(outputBase, {recursive: true})
    const clonedSchema = await $RefParser.dereference(srcFileName, {
        dereference: {
            excludedPathMatcher: (path) => path.includes("operations")
        },
        mutateInputSchema: false
    });
    const document = await bundle([clonedSchema], {
        referenceIntoComponents: true,
    });
    writeFileSync(outputPath, document.yml());
    console.log(`Bundled ${srcFileName} to ${outputPath}`)
} catch (err) {
    console.error(err);
}

@aeworxet aeworxet force-pushed the feat-add-x-origin-property branch 18 times, most recently from 3f8201a to 682de39 Compare March 24, 2024 11:37
@aeworxet aeworxet force-pushed the feat-add-x-origin-property branch 2 times, most recently from 92b449e to a54dc11 Compare April 11, 2024 08:26
@aeworxet
Copy link
Collaborator Author

This PR is ready for merge, but it should be merged only AFTER asyncapi/optimizer#216 is merged (it will be merged only to next not master) and Optimizer 1.0.0 is released, due to the transfer of functionality of moving components into components to Optimizer starting from its version v1.0.0.

Copy link
Member

@Souvikns Souvikns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you should remove some of the previous changes.

src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
@aeworxet aeworxet force-pushed the feat-add-x-origin-property branch 2 times, most recently from b10b1af to 0892753 Compare April 18, 2024 13:40
@aeworxet aeworxet force-pushed the feat-add-x-origin-property branch 2 times, most recently from 18673fb to 72aafe3 Compare April 19, 2024 04:07
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Member

@Souvikns Souvikns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@aeworxet
Copy link
Collaborator Author

/rtm

@asyncapi-bot asyncapi-bot merged commit e47ee49 into asyncapi:master Apr 19, 2024
10 checks passed
@aeworxet aeworxet deleted the feat-add-x-origin-property branch April 19, 2024 11:24
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 0.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

Refine AsyncAPI Bundling with Origin Tracing and Component Naming
5 participants