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

Can't build valid EventSubscription create or update request in azure_mgmt_eventgrid #1270

Closed
JWT95 opened this issue Apr 26, 2023 · 3 comments
Labels
Event Grid The azure_messaging_eventgrid crate

Comments

@JWT95
Copy link
Contributor

JWT95 commented Apr 26, 2023

Problem

The Azure REST API documentation defines the properties.destination field in the Event Subscription as having type one of WebHookEventSubscriptionDestination, EventHubEventSubscriptionDestination, StorageQueueEventSubscriptionDestination... Each of these types contain an endpointType field and a properties field giving details of the endpoint.

The autogenerated azure_mgmt_eventgrid crate has the properties.destination field as having type EventSubscriptionDestination. This only contains the endpoint_type field and not the properties field. So it is impossible to use the crate to create an Event Subscription.

Ideas

I'm not sure if this is a bug in the Rust code autogenerator or the Azure REST API spec. The OpenAPI spec has:

    "EventSubscriptionProperties": {
        ...
        "destination": {
          "$ref": "#/definitions/EventSubscriptionDestination",
          "description": "Information about the destination where events have to be delivered for the event subscription.\r\nUses Azure Event Grid's identity to acquire the authentication tokens being used during delivery / dead-lettering."
        },

and

    "EventSubscriptionDestination": {
      "description": "Information about the destination for an event subscription.",
      "required": [
        "endpointType"
      ],
      "type": "object",
      "properties": {
        "endpointType": {
          "description": "Type of the endpoint for the event subscription destination.",
          "enum": [
            "WebHook",
            "EventHub",
            "StorageQueue",
            "HybridConnection",
            "ServiceBusQueue",
            "ServiceBusTopic",
            "AzureFunction"
          ],
          "type": "string",
          "x-ms-enum": {
            "name": "EndpointType",
            "modelAsString": true
          }
        }
      },
      "discriminator": "endpointType"
    },

and

    "StorageQueueEventSubscriptionDestination": {
      "description": "Information about the storage queue destination for an event subscription.",
      "type": "object",
      "allOf": [
        {
          "$ref": "#/definitions/EventSubscriptionDestination"
        }
      ],
      "properties": {
        "properties": {
          "$ref": "#/definitions/StorageQueueEventSubscriptionDestinationProperties",
          "description": "Storage Queue Properties of the event subscription destination.",
          "x-ms-client-flatten": true
        }
      },
      "x-ms-discriminator-value": "StorageQueue"
    },

So perhaps some combination of discriminator and AllOf that the generator doesn't handle?

The generated Rust code has the model for the StorageQueueEventSubscriptionDestination type but isn't using it in the EventSubscription create or update request.

@JWT95
Copy link
Contributor Author

JWT95 commented Apr 26, 2023

@johnbatty as discussed

@johnbatty johnbatty added the Event Grid The azure_messaging_eventgrid crate label May 24, 2023
@johnbatty
Copy link
Contributor

Further information on schema discriminators:

@cataggar
Copy link
Member

cataggar commented Oct 1, 2023

I added support for unions in #1414. It should be possible now.

https://docs.rs/azure_mgmt_eventgrid/0.16.0/azure_mgmt_eventgrid/package_2022_06/models/struct.EventSubscriptionProperties.html

pub struct EventSubscriptionProperties {
pub topic: Option<String>,
pub provisioning_state: Option<ProvisioningState>,
pub destination: Option<EventSubscriptionDestinationUnion>,
pub delivery_with_resource_identity: Option<DeliveryWithResourceIdentity>,
pub filter: Option<EventSubscriptionFilter>,
pub labels: Vec<String>,
pub expiration_time_utc: Option<OffsetDateTime>,
pub event_delivery_schema: Option<EventDeliverySchema>,
pub retry_policy: Option<RetryPolicy>,
pub dead_letter_destination: Option<DeadLetterDestinationUnion>,
pub dead_letter_with_resource_identity: Option<DeadLetterWithResourceIdentity>,
}

@cataggar cataggar closed this as completed Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Event Grid The azure_messaging_eventgrid crate
Projects
None yet
Development

No branches or pull requests

3 participants