-
-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Describe the bug.
I ran the optimizer on my valid asyncapi file and the output file still contained unused messages. I tried to reduce the issue to the minimum and realized it seems to be an issue with periods (.) in component names.
Here is a asyncapi file that reproduces the bug
asyncapi: 3.0.0
info:
title: my-app
version: 1.0.0
channels:
some_channel:
address: some_address
messages:
Some-Event:
$ref: '#/components/messages/Some-Event'
operations:
receiveEvent:
channel:
$ref: '#/channels/some_channel'
action: receive
components:
messages:
Some-Event:
payload:
type: object
properties:
id:
type: string
Unused-Event-1.0:
payload:
type: object
properties:
foo:
type: object
$ref: '#/components/schemas/Unused-Schema'
bar:
type: array
items:
$ref: '#/components/schemas/Unused-Schema-2.0'
schemas:
Unused-Schema:
type: object
properties:
name:
type: string
Unused-Schema-2.0:
type: object
properties:
name:
type: stringWhen running the optimizer, it correctly reports that some components can be removed
3 unused components can be removed.
the following changes will be made:
remove components.messages.Unused-Event-1.0.
remove components.schemas.Unused-Schema-1.0.
remove components.schemas.Unused-Schema.
But when applying (with the option "remove components"), the resulting yaml is as follows
asyncapi: 3.0.0
info:
title: my-app
version: 1.0.0
channels:
some_channel:
address: some_address
messages:
Some-Event:
$ref: '#/components/messages/Some-Event'
operations:
receiveEvent:
channel:
$ref: '#/channels/some_channel'
action: receive
components:
messages:
Some-Event:
payload:
type: object
properties:
id:
type: string
Unused-Event-1.0:
payload:
type: object
properties:
foo:
type: object
$ref: '#/components/schemas/Unused-Schema'
bar:
type: array
items:
$ref: '#/components/schemas/Unused-Schema-2.0'
schemas:
Unused-Schema-2.0:
type: object
properties:
name:
type: string(Notice it deleted the "Unused-Schema" but its reference is still in the messages because Unused-Event-1.0 wasn't deleted. this means the whole file is invalid)
I have not seen any mention in the asyncapi specification that says component names should not contain periods, so I think this should be expected to work.
Expected behavior
The output file should only contain used components
asyncapi: 3.0.0
info:
title: my-app
version: 1.0.0
channels:
some_channel:
address: some_address
messages:
Some-Event:
$ref: '#/components/messages/Some-Event'
operations:
receiveEvent:
channel:
$ref: '#/channels/some_channel'
action: receive
components:
messages:
Some-Event:
payload:
type: object
properties:
id:
type: stringHow to Reproduce
Run the optimiser on the given AsyncAPI file.
Are you willing to work on this issue ?
No, but I did notice there is periods used as delimiter in the code. Might be a lead
For instance:
Line 150 in fbc19f5
| const parentPath = childPath.substring(0, childPath.lastIndexOf('.')) |
optimizer/src/ComponentProvider.ts
Line 32 in fbc19f5
| .join('.') |