asyncapi / asyncapi/cli

[BUG] Diff command doesn't work when circular reference

Open
#2,093 4 comments 1 reaction 0 assignees View on GitHub
bug stale
Dominant language
TypeScript
Stars
272
Forks
375
Avg merge
3h 22m
Merged PRs (30d)
8

Description

### Describe the bug.

The diff command doesn't work when there is a circular reference in the structure

### Expected behavior

No error exit code + skip circular properties if can not be handled by diff

### Screenshots

not needed

### How to Reproduce

Create a valid openapi 3.1.0 file with a circular reference:

```yaml
asyncapi: 3.1.0
info:
title: Testing
version: 1.0.0
channels:
my_entity_created:
messages:
entity-created:
payload:
$ref: '#/components/schemas/entity-created'
operations:
my_entity_created:
action: send
channel:
$ref: '#/channels/my_entity_created'
components:
schemas:
filters:
type: array
items:
anyOf:
- $ref: '#/components/schemas/filters'
- type: string
entity-created:
type: object
properties:
filters:
type: array
items:
$ref: '#/components/schemas/filters'
```

Ensure it's valid:
```shell
$ docker run -it --rm -v "$(pwd):/asyncapi" "asyncapi/cli:6.0.0" validate /asyncapi/file.yaml
# ...

File /asyncapi/file.yaml is valid! File /asyncapi/file.yaml and referenced documents don't have governance issues.

Skipping submitting anonymous metrics due to the following error: TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Object'
| property 'items' -> object with constructor 'Object'
| property 'anyOf' -> object with constructor 'Array'
--- index 0 closes the circle

$ echo $?
0
```

Run diff:
```shell
$ docker run -it --rm -v "$(pwd):/asyncapi" "asyncapi/cli:6.0.0" diff --log-diagnostics /asyncapi/file.yaml /asyncapi/file.yaml
Diagnostics for /asyncapi/file.yaml:

File /asyncapi/file.yaml is valid! File /asyncapi/file.yaml and referenced documents don't have governance issues.

Diagnostics for /asyncapi/file.yaml:

File /asyncapi/file.yaml is valid! File /asyncapi/file.yaml and referenced documents don't have governance issues.

ValidationError:
```

There is a `ValidationError` with no message.

Removing the circular ref, it works:
```shell
$ yq -i 'del(.components.schemas.filters.items.anyOf[0])' file.yaml
$ docker run -it --rm -v "$(pwd):/asyncapi" "asyncapi/cli:6.0.0" diff /asyncapi/file.yaml /asyncapi/file.yaml

changes: []
```

### 🖥️ Device Information [optional]

_No response_

### 👀 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 ?

None

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.