-
-
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: toc and operation reply (#523)
- Loading branch information
Showing
11 changed files
with
49,680 additions
and
14,860 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const OPERATION_TYPES = { | ||
V3: { | ||
REQUEST: 'request', | ||
SEND: 'send', | ||
REPLY: 'reply', | ||
RECEIVE: 'receive', | ||
}, | ||
// For v2, when you use publish operation it means | ||
// other publish to your application because your application is subscribing to it. | ||
V2: { | ||
REQUEST: 'publish', | ||
SEND: 'subscribe', | ||
REPLY: 'subscribe', | ||
RECEIVE: 'publish', | ||
} | ||
}; | ||
|
||
const getOperationTypesByVersion = (version) => { | ||
const [majorVersion] = version.split('.'); | ||
|
||
return OPERATION_TYPES[`V${majorVersion}`]; | ||
}; | ||
|
||
export class CommonHelpers { | ||
static getOperationType(operation, asyncApiDoc) { | ||
const operationsTypes = getOperationTypesByVersion(asyncApiDoc.version()); | ||
|
||
if (operation.isSend()) { | ||
if (operation.reply() !== undefined) { | ||
return operationsTypes.REQUEST; | ||
} | ||
return operationsTypes.SEND; | ||
} | ||
if (operation.isReceive() && operation.reply() !== undefined) { | ||
return operationsTypes.REPLY; | ||
} | ||
return operationsTypes.RECEIVE; | ||
} | ||
|
||
static isV3(asyncApiDoc) { | ||
return asyncApiDoc.version().split('.')[0] === '3'; | ||
} | ||
} |
Oops, something went wrong.