-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(table of contents): use new
CommonHelpers
class for `Operation…
…` types heading
- Loading branch information
Showing
4 changed files
with
39 additions
and
43 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
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
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 |
---|---|---|
@@ -1,15 +1,37 @@ | ||
const OPERATION_TYPES = { | ||
V3: { | ||
REQUEST: 'request', | ||
SEND: 'send', | ||
REPLY: 'reply', | ||
RECEIVE: 'receive', | ||
}, | ||
V2: { | ||
REQUEST: 'request', | ||
SEND: 'publish', | ||
REPLY: 'reply', | ||
RECEIVE: 'subscribe', | ||
} | ||
}; | ||
|
||
const getOperationTypesByVersion = (version) => { | ||
const [majorVersion] = version.split('.'); | ||
|
||
return OPERATION_TYPES[`V${majorVersion}`]; | ||
}; | ||
|
||
export class CommonHelpers { | ||
static getOperationType(operation) { | ||
static getOperationType(operation, asyncApiDoc) { | ||
const operationsTypes = getOperationTypesByVersion(asyncApiDoc.version()); | ||
|
||
if (operation.isSend()) { | ||
if (operation.reply() !== undefined) { | ||
return 'request'; | ||
return operationsTypes.REQUEST; | ||
} | ||
return 'send'; | ||
return operationsTypes.SEND; | ||
} | ||
if (operation.isReceive() && operation.reply() !== undefined) { | ||
return 'reply'; | ||
return operationsTypes.REPLY; | ||
} | ||
return 'receive'; | ||
return operationsTypes.RECEIVE; | ||
} | ||
} |
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