j-d-carmichael / boats

Beautiful Open Api Template System
MIT License
57 stars 8 forks source link

`inject` helper `excludeChannel` and `includeOnlyChannels` params don't work with AsyncAPI document #70

Closed gabormagyar closed 2 years ago

gabormagyar commented 2 years ago

Alternate title:

Injector mapIndex produces empty object for AsyncAPI document

Describe the bug inject([...]) filter functionality (excludeChannel, includeOnlyChannels) doesn't work, scope unclear.

To Reproduce I'm using a standard, valid asyncAPI document, I'm not sure if it works for other things.

Expected behavior excludeChannel, includeOnlyChannels params are respected

Additional context I'm debugging into Injector.ts, and the offending code seems to be the mapIndex function. With this particular example at least, the problem seems to be that the $ref field is selected twice, once by the Object.values(methods) call, and then a second time by the explicit methodToFileRef.$ref accessor.

You can see in the debugger that Object.values(methods) is already a string array:

Screenshot 2022-03-25 at 13 41 10

The result is that methodToFileRef is a string and methodToFileRef.$ref is undefined.

Screenshot 2022-03-25 at 13 29 53

Therefore nothing ever gets added to this.this.fileToRouteMap so nothing ever passes the filter whitelist or blacklists. They have no entries to filter against.

j-d-carmichael commented 2 years ago

I will take a look into this over the weekend

j-d-carmichael commented 2 years ago

@gabormagyar after examining this evening, it looks like the inject helper has never been working for async api channels! Thank your for reporting it!

This resolves the issue: https://github.com/j-d-carmichael/boats/blob/2.32.0/src/Injector.ts#L254

And tested here: https://github.com/j-d-carmichael/boats/blob/2.32.0/srcASYNC2/index.yml#L19

gabormagyar commented 2 years ago

Thanks for the quick fix!