asyncapi / asyncapi/parser-js

[BUG] incorrect x-parser-schema-id when having multiple files

Open
#1,063 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
144
Forks
144
Avg merge
6m
Merged PRs (30d)
11

Description

### Describe the bug.

I am encountering an issue with my `asyncapi.yml` file, which references schemas located in another file. When I generate the models, the generator creates generic names like `AnonymousSchema_1`, `AnonymousSchema_2`, `AnonymousSchema_3`, and so on for each schema in the referenced file.

After investigating the problem, I discovered that it seems to stem from the parser. Specifically, the `x-parser-schema-id` field in the `AsyncAPIDocumentInterface` object is returning values like ``.

### Expected behavior

I would expect the generated models to have the right name.

### Screenshots

![image](https://github.com/user-attachments/assets/0ab6dc35-6061-483c-acaf-5659cf9d08ab)
![image](https://github.com/user-attachments/assets/f01337bc-eb1d-4a11-a49e-8fba2040b045)

### How to Reproduce

I will leave a PR that reproduces the error with tests.
I can try fixing the error, but I need guidance here.

Here is the reproduction: https://github.com/asyncapi/parser-js/pull/1064

### 🥦 Browser

None

### 👀 Have you checked for similar open issues?

- [X] I checked and didn't find similar issue

### 🏢 Have you read the Contributing Guidelines?

- [X] I have read the [Contributing Guidelines](https://github.com/asyncapi/.github/blob/master/CONTRIBUTING.md)

### Are you willing to work on this issue ?

Yes I am willing to submit a PR!

Contributor guide

Open the contributing guide

Research direction

Start with the reproduction and tests in PR #1064, then trace how AsyncAPIDocumentInterface assigns x-parser-schema-id when schemas are referenced from another file. Done means the referenced schemas receive their correct names instead of AnonymousSchema_N values, with the reproduction tests passing.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.