microsoftgraph / microsoftgraph/msgraph-beta-sdk-php
PHP Enum do not support missing values, this causes my synchronization job schema get request to fail.
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 13
- Forks
- 8
- Avg merge
- 14h 58m
- Merged PRs (30d)
- 3
Description
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
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
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

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.
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;
}
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Enum.php around line 57 and the AttributeDefinitionMetadata example; inspect how an unknown value such as Secret is deserialized. Compare the PHP behavior with the Java forValue example cited, then verify that the synchronization schema request can handle the unknown enum value without failing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100