Skip to content

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

@dabeck81

Description

@dabeck81

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"
        }
      ]
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions