Skip to content

Commit

Permalink
feat: add hook and parameter to inverse operations (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tenischev authored May 25, 2020
1 parent b1c45c1 commit a41b0f9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ components:

|Name|Description|Required|Default|
|---|---|---|---|
|inverseOperations|Generate an application that will publish messages to `publish` operation of channels and read messages from `subscribe` operation of channels. Literally this flag will simply swap `publish` and `subscribe` operations in the channels. <br> This flag will be useful when you want to generate a code of mock for your main application. Be aware, generation could be incomplete and manual changes will be required e.g. if bindings are defined only for case of main application.|No|`false`|
|listenerPollTimeout|Only for Kafka. Timeout in ms to use when polling the consumer.|No|`3000`|
|listenerConcurrency|Only for Kafka. Number of threads to run in the listener containers.|No|`3`|
|asyncapiFileDir| Path where original AsyncAPI file will be stored.|No|`src/main/resources/api/`|
Expand Down Expand Up @@ -143,7 +144,7 @@ See the list of features that are still missing in the component:
- [ ] [`security schemas`](https://github.com/asyncapi/asyncapi/blob/master/versions/2.0.0/asyncapi.md#securitySchemeObject) are not supported
- [ ] [`traits`](https://github.com/asyncapi/asyncapi/blob/master/versions/2.0.0/asyncapi.md#operationTraitObject) are not supported
- [ ] Json serializer/desirializer is used always, without taking into account real [`content type`](https://github.com/asyncapi/asyncapi/blob/master/versions/2.0.0/asyncapi.md#default-content-type)
- [ ] client side generation mode (in general just flip subscribe and publish channels)
- [x] client side generation mode (in general just flip subscribe and publish channels)
- [ ] template generation of docker-compose depending on protocol of server, now the rabbitmq is hardcoded

If you want to help us develop them, feel free to contribute.
Expand Down
19 changes: 19 additions & 0 deletions hooks/inverseOperations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
'generate:before': generator => {
if (generator.templateParams && generator.templateParams['inverseOperations'] === 'true') {
console.log("Operations are inverted!");
const asyncapi = generator.asyncapi;
for (let [key, value] of Object.entries(asyncapi.channels())) {
let publish = value._json.publish;
value._json.publish = value._json.subscribe;
value._json.subscribe = publish;
if (!value._json.subscribe) {
delete value._json.subscribe;
}
if (!value._json.publish) {
delete value._json.publish;
}
}
}
}
};
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
"**/*.jar"
],
"parameters": {
"inverseOperations": {
"description": "Generate application that will publish messages to `publish` operation of channels and read messages from `subscribe` operation of channels. Literally this flag just swap `publish` and `subscribe` operations in channels.",
"default": false,
"required": false
},
"listenerPollTimeout": {
"description": "Only for Kafka. Timeout to use when polling the consumer.",
"default": 3000,
Expand Down

0 comments on commit a41b0f9

Please sign in to comment.