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

PHP Enum do not support missing values, this causes my synchronization job schema get request to fail. #329

Open
dbollaer opened this issue Oct 10, 2024 · 0 comments
Labels
status:waiting-for-triage An issue that is yet to be reviewed or assigned ToTriage type:bug A broken experience

Comments

@dbollaer
Copy link

Describe the bug

I am trying to trigger on an on-demand provisioning job and need to get the synchronization rule ID to do so.

When I get query the api directly, I get a valid response

GET https://graph.microsoft.com/beta/servicePrincipals/xxxxxxx/synchronization/jobs/scim.7d175e27e908439982db3a45414e55e0.b36480ed-cde1-4a8f-aeab-a6a0b8f8d65d/schema?$select=id

Response

Xnip2024-10-10_17-15-13

The document I refer to is Get synchronizationSchema
https://learn.microsoft.com/en-us/graph/api/synchronization-synchronizationschema-get?view=graph-rest-beta&tabs=http

However, when I run it, I get the error: "Handling "App\Message\GetSynchronisationRuleIdMessage" failed: Invalid enum value Secret ".

Expected behavior

Graceful exception handling, when a missing enum value is present.

How to reproduce

public function handleGetSynchronisationRuleIdMessage(  
    GetSynchronisationRuleIdMessage $message  
): string  
{  
  
    $result = $this->graphServiceClient  
        ->servicePrincipals()  
        ->byServicePrincipalId($message->servicePrincipalId)  
        ->synchronization()  
        ->jobs()  
        ->bySynchronizationJobId($message->synchronizationJobId)  
        ->schema()  
        ->get()  
        ->wait();  
    return $result->getSynchronizationRules()[0]->getId() ??  
        throw new Exception(sprintf("No Rule found for job %s", $message->synchronizationJobId));  
}

SDK Version

2.19

Latest version known to work for scenario above?

No response

Known Workarounds

(failed)
Microsoft support informed me I can bypass the error by querying for the synchronizationRules only using one of the following:

$requestConfig = new MessagesRequestBuilderGetRequestConfiguration();

$requestConfig->queryParameters = MessagesRequestBuilderGetRequestConfiguration::createQueryParameters();

$requestConfig->queryParameters->select = ['synchronizationRules'];

// or with PHP 8

$requestConfig = new MessagesRequestBuilderGetRequestConfiguration(

    queryParameters: MessagesRequestBuilderGetRequestConfiguration::createQueryParameters(

        select: ['synchronizationRules']

    )

);

Reason: select is not supported for this endpoint.

Debug output

Pasted image 20241010141840

Click to expand log ``` Handling "App\Message\GetSynchronisationRuleIdMessage" failed: Invalid enum value Secret ".
</details>


### Configuration

_No response_

### Other information

### My Analyses

The problem I am having this error is because the way enums are handled inside php sdk.

### Enum.php

![Pasted image 20241010142045](https://github.com/user-attachments/assets/ec73a72a-6521-4b58-9c54-bac5299d60be)


See line: 57.



So when we receive a value, which is not supported. We get this exception.

```php


<?php  
  
namespace Microsoft\Graph\Beta\Generated\Models;  
  
use Microsoft\Kiota\Abstractions\Enum;  
  
class AttributeDefinitionMetadata extends Enum {  
    public const BASE_ATTRIBUTE_NAME = 'BaseAttributeName';  
    public const COMPLEX_OBJECT_DEFINITION = 'ComplexObjectDefinition';  
    public const IS_CONTAINER = 'IsContainer';  
    public const IS_CUSTOMER_DEFINED = 'IsCustomerDefined';  
    public const IS_DOMAIN_QUALIFIED = 'IsDomainQualified';  
    public const LINK_PROPERTY_NAMES = 'LinkPropertyNames';  
    public const LINK_TYPE_NAME = 'LinkTypeName';  
    public const MAXIMUM_LENGTH = 'MaximumLength';  
    public const REFERENCED_PROPERTY = 'ReferencedProperty';  
}

While If you look how java implements Enums.

This is my reasoning:

The Enum Requires that all values are defined.

"Secret"-value is not a defined value.

This bug is the php sdk, BUT in the Java SDK.
This problem is solved differently.

When an enum value does not exit.
It just return null.

source: https://raw.githubusercontent.com/microsoftgraph/msgraph-sdk-java/refs/heads/main/src/main/java/com/microsoft/graph/generated/models/AttributeDefinitionMetadata.java

package com.microsoft.graph.models;

import com.microsoft.kiota.serialization.ValuedEnum;
import java.util.Objects;

@jakarta.annotation.Generated("com.microsoft.kiota")
public enum AttributeDefinitionMetadata implements ValuedEnum {
    BaseAttributeName("BaseAttributeName"),
    ComplexObjectDefinition("ComplexObjectDefinition"),
    IsContainer("IsContainer"),
    IsCustomerDefined("IsCustomerDefined"),
    IsDomainQualified("IsDomainQualified"),
    LinkPropertyNames("LinkPropertyNames"),
    LinkTypeName("LinkTypeName"),
    MaximumLength("MaximumLength"),
    ReferencedProperty("ReferencedProperty");
    public final String value;
    AttributeDefinitionMetadata(final String value) {
        this.value = value;
    }
    @jakarta.annotation.Nonnull
    public String getValue() { return this.value; }
    @jakarta.annotation.Nullable
    public static AttributeDefinitionMetadata forValue(@jakarta.annotation.Nonnull final String searchValue) {
        Objects.requireNonNull(searchValue);
        switch(searchValue) {
            case "BaseAttributeName": return BaseAttributeName;
            case "ComplexObjectDefinition": return ComplexObjectDefinition;
            case "IsContainer": return IsContainer;
            case "IsCustomerDefined": return IsCustomerDefined;
            case "IsDomainQualified": return IsDomainQualified;
            case "LinkPropertyNames": return LinkPropertyNames;
            case "LinkTypeName": return LinkTypeName;
            case "MaximumLength": return MaximumLength;
            case "ReferencedProperty": return ReferencedProperty;
            default: return null;
        }
    }
}
@dbollaer dbollaer added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:waiting-for-triage An issue that is yet to be reviewed or assigned ToTriage type:bug A broken experience
Projects
None yet
Development

No branches or pull requests

1 participant