-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new Spectral rule to check for null addresses in channels associa…
…ted with operations defining reply
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { IFunction, IFunctionResult } from '@stoplight/spectral-core'; | ||
import { IAsyncAPIOperation, IAsyncAPIChannel } from '@stoplight/types'; | ||
import { Operations } from 'models/v2/operations'; | ||
|
||
const checkNullAddressInOperations: IFunction = (document, opts) => { | ||
const results: IFunctionResult[] = []; | ||
|
||
const channels: Record<string, IAsyncAPIChannel> = document.channels ?? {}; | ||
|
||
for(const channelKey in channels){ | ||
const channel = channels[channelKey]; | ||
|
||
//check if channel has operation defined | ||
if(channel.operations) { | ||
for(const operationKey in channel.operations) { | ||
const operation = channel.operations[operationKey]; | ||
|
||
//check if the operation defines a reply and the channel is null or undefined | ||
if(operation.reply && (!channel.address || channel.address === 'null')) { | ||
results.push({ | ||
message: `Channel "${channelKey}" associated with operation "${operationKey}" has a null or undefined address.`, | ||
path: ['channels', channelKey, 'operations', operationKey, 'reply'], | ||
severity: 'error' | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
return results; | ||
} | ||
|
||
export default checkNullAddressInOperations; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters