Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support @Hidden annotation to hide certain eventhandlers/listeners #874

Closed
dabeck81 opened this issue Jul 29, 2024 · 6 comments
Closed

Support @Hidden annotation to hide certain eventhandlers/listeners #874

dabeck81 opened this issue Jul 29, 2024 · 6 comments
Labels
enhancement New feature or request good first issue Good for newcomers staged for release

Comments

@dabeck81
Copy link
Contributor

Describe the feature request
Adding of the @Hidden (swagger) annotation would remove a RabbitHandler/listener from the spec

Motivation
I have one EventListener that can receive all kinds of messages. I have it implemented like the following:

@Component
@RequiredArgsConstructor
@Slf4j
@RabbitListener(id = "PetListener",
                containerFactory = "notificationContainerFactory",
                queues = "${spring.rabbitmq.notification.queue}")
public class PetQueueListener {

    @RabbitHandler
    public void receiveDog(@Payload Dog dog) {
        System.out.println("Received message with dog payload type " + dog);
    }

    @RabbitHandler
    public void receiveCat(@Payload Cat cat) {
        System.out.println("Received message with cat payload type " + cat);
    }

    @RabbitHandler(isDefault = true)
//    @Hidden   --> would remove this handler from the spec
    public void receiveDefault(@Payload Object object) {
        System.out.println("Received message with unknown payload type: " + object);
    }
}

When an unknown object is being received we go to the "receiveDefault" handler. What I would like to be able to do, is hide this RabbitHandler with the @Hidden annotation, so that it does not show up in the spec.

Technical details
see above.

As a matter of fact, above implementation (without the hidden-annotation) generates at this moment an invalid spec (tested it with springwolf-amqp:1.5.0):

The java.lang.Object is used and referenced as a Schema-component, but is not mentionned:

{
  "asyncapi": "3.0.0",
  "info": {
    "title": "Publication-service",
    "version": "version",
    "x-generator": "springwolf"
  },
  "defaultContentType": "application/json",
  "servers": {
    "amqp": {
      "host": "amqp:5672",
      "protocol": "amqp"
    }
  },
  "channels": {
    "my.notification.queue": {
      "address": "my.notification.queue",
      "messages": {
        "my.package.pet.Cat": {
          "$ref": "#/components/messages/my.package.pet.Cat"
        },
        "my.package.pet.Dog": {
          "$ref": "#/components/messages/my.package.pet.Dog"
        },
        "java.lang.Object": {
          "$ref": "#/components/messages/java.lang.Object"
        }
      },
      "bindings": {
        "amqp": {
          "is": "queue",
          "queue": {
            "name": "my.notification.queue",
            "durable": true,
            "exclusive": false,
            "autoDelete": false,
            "vhost": "/"
          },
          "bindingVersion": "0.3.0"
        }
      }
    }
  },
  "components": {
    "schemas": {
      "SpringRabbitListenerDefaultHeaders": {
        "type": "object",
        "properties": {},
        "examples": [
          {}
        ]
      },
      "my.package.pet.Cat": {
        "title": "Cat",
        "type": "object",
        "properties": {
          "meows": {
            "type": "boolean"
          },
          "name": {
            "type": "string"
          },
          "owner": {
            "type": "string"
          },
          "petType": {
            "type": "string",
            "enum": [
              "DOG",
              "CAT"
            ]
          }
        },
        "examples": [
          {
            "meows": true,
            "name": "string",
            "owner": "string",
            "petType": "DOG"
          }
        ]
      },
      "my.package.pet.Dog": {
        "title": "Dog",
        "type": "object",
        "properties": {
          "barks": {
            "type": "boolean"
          },
          "name": {
            "type": "string"
          },
          "owner": {
            "type": "string"
          },
          "petType": {
            "type": "string",
            "enum": [
              "DOG",
              "CAT"
            ]
          }
        },
        "examples": [
          {
            "barks": true,
            "name": "string",
            "owner": "string",
            "petType": "DOG"
          }
        ]
      }
    },
    "messages": {
      "my.package.pet.Cat": {
        "headers": {
          "$ref": "#/components/schemas/SpringRabbitListenerDefaultHeaders"
        },
        "payload": {
          "schemaFormat": "application/vnd.aai.asyncapi+json;version=3.0.0",
          "schema": {
            "$ref": "#/components/schemas/my.package.pet.Cat"
          }
        },
        "name": "my.package.pet.Cat",
        "title": "Cat",
        "bindings": {
          "amqp": {
            "bindingVersion": "0.3.0"
          }
        }
      },
      "my.package.pet.Dog": {
        "headers": {
          "$ref": "#/components/schemas/SpringRabbitListenerDefaultHeaders"
        },
        "payload": {
          "schemaFormat": "application/vnd.aai.asyncapi+json;version=3.0.0",
          "schema": {
            "$ref": "#/components/schemas/my.package.pet.Dog"
          }
        },
        "name": "my.package.pet.Dog",
        "title": "Dog",
        "bindings": {
          "amqp": {
            "bindingVersion": "0.3.0"
          }
        }
      },
      "java.lang.Object": {
        "headers": {
          "$ref": "#/components/schemas/SpringRabbitListenerDefaultHeaders"
        },
        "payload": {
          "schemaFormat": "application/vnd.aai.asyncapi+json;version=3.0.0",
          "schema": {
            "$ref": "#/components/schemas/java.lang.Object"   //---> referenced as a schema-component, but not mentionned under the schema-components
          }
        },
        "name": "java.lang.Object",
        "title": "java.lang.Object",
        "bindings": {
          "amqp": {
            "bindingVersion": "0.3.0"
          }
        }
      }
    }
  },
  "operations": {
    "my.notification.queue_receive_PetQueueListener": {
      "action": "receive",
      "channel": {
        "$ref": "#/channels/my.notification.queue"
      },
      "bindings": {
        "amqp": {
          "expiration": 0,
          "cc": [
            "my.notification.queue"
          ],
          "bindingVersion": "0.3.0"
        }
      },
      "messages": [
        {
          "$ref": "#/channels/my.notification.queue/messages/my.package.pet.Cat"
        },
        {
          "$ref": "#/channels/my.notification.queue/messages/my.package.pet.Dog"
        },
        {
          "$ref": "#/channels/my.notification.queue/messages/java.lang.Object"
        }
      ]
    }
  }
}
@dabeck81 dabeck81 added the enhancement New feature or request label Jul 29, 2024
Copy link

Welcome to Springwolf. Thanks a lot for reporting your first issue. Please check out our contributors guide and feel free to join us on discord.

@timonback timonback added the good first issue Good for newcomers label Jul 29, 2024
@timonback
Copy link
Member

Hi @dabeck81,
Thank you for the report of the bug and feature request:

  1. Congrats, you found another type (Object) that behaves different than other classes. I guess we need another case for Object.class at

    if (type.equals(String.class) || type.equals(Character.class) || type.equals(Byte.class)) {

  2. Adding support for the swagger @Hidden annotation is a nice enhancement. All/Most springwolf scanners filter in the beginning whether a method is considered, for example here: https://github.com/springwolf/springwolf-core/blob/07e38d92cce28c972751a53b0bf3b5f912e418d7/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/channels/annotations/SpringAnnotationMethodLevelChannelsScanner.java

Both are great good first issues for anyone interested.
We are happy to assist (via this issue or in Discord).

dabeck81 pushed a commit to dabeck81/springwolf-core that referenced this issue Jul 30, 2024
@dabeck81
Copy link
Contributor Author

Hi @timonback,

Thanks for the pointers on where to introduce changes.
I have created a pull-request with my changes. #885

David

timonback pushed a commit that referenced this issue Jul 30, 2024
fix issue #874
Also, adding of support for primitive type "Object"

Co-authored-by: David Beck <david.beck@iriscare.brussels>
@timonback
Copy link
Member

timonback commented Jul 30, 2024

Thank you @dabeck81,
great quality with tests already included!
Just merged it. The SNAPSHOT will be available in a couple minutes.

If you want, we are happy to feature your company as one of the users of Springwolf, just comment in #342

Copy link

The change is staged for release and will be part of the next release.

If you want to try and verify it in your application today,
use the latest 1.X.0-SNAPSHOT build as described in our README.md > Testing SNAPSHOT version

Thank you for the report/contribution!

Copy link

The change is available in the latest release. 🎉

Thank you for the report/contribution and making Springwolf better!

timonback pushed a commit to timonback/springwolf-core that referenced this issue Sep 7, 2024
timonback pushed a commit that referenced this issue Sep 13, 2024
* fix issue #874

* POC: adding polymorphism on payload

* POC: adding polymorphism on payload

* POC: refactoring for support for inline-schema's

* POC: refactoring for support for inline-schema's

* POC: refactoring for support for inline-schema's

* feat(ui): update server model

* feat(kafka): add ConsumerRecord to example

* test(core): align test setup

* test(core): minor changes

* resolving pull-request remarks

* chore: fixes after rebase

* feat(core): extract types using extractableClasses

* feat(ui): handle inline schemas

* test(ui): update ui tests

* feat(core): add inline schemas

also add to schemas section to allow publishing

* feat(ui): update mapping of example

* feat(e2e): refactor publishing and simplify payloadName retrieval

* feat(core): remove empty description

* trim newline on yaml-file in kafka-test

---------

Co-authored-by: David Beck <david.beck@iriscare.brussels>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers staged for release
Projects
None yet
Development

No branches or pull requests

2 participants