microsoftgraph / msgraph-sdk-java

Microsoft Graph SDK for Java
https://docs.microsoft.com/en-us/graph/sdks/sdks-overview
MIT License
402 stars 134 forks source link

PlannerAssignment class does not exist in version 6.4.0 #1873

Open HermanShpryhau opened 9 months ago

HermanShpryhau commented 9 months ago

In the docs for creating a task the PlannerAssignment is mentioned in the code example, but this class is not present in the library.

Ndiritu commented 9 months ago

Thanks for reporting this @HermanShpryhau.

While this is being investigated, you can try using a HashMap to hold the plannerAssignment properties and values as follows. Lmk if this unblocks you:

PlannerAssignments assignments = new PlannerAssignments();
HashMap<String, Object> additionalData = new HashMap<>();
additionalData.put("[user-id]", "{'@odata.type':'#microsoft.graph.plannerAssignment','orderHint':' !'}");
assignments.setAdditionalData(additionalData);
Ndiritu commented 9 months ago

(Triage notes) PlannerAssignments is an open type. PlannerAssignment(no 's') is declared as a component in the OpenAPI spec but not generated by Kiota. Could this be because it's not references as an optional property of plannerAssignments?

HermanShpryhau commented 9 months ago

Unfortunately putting a map there results in following exception:

java.lang.IllegalStateException: Dangling name: 27a1c9e1-8745-43b6-b8e1-bd2493ed5ac8
    at com.google.gson.stream.JsonWriter.close(JsonWriter.java:346) ~[gson-2.10.1.jar:na]
    at com.google.gson.stream.JsonWriter.endObject(JsonWriter.java:321) ~[gson-2.10.1.jar:na]
    at com.microsoft.kiota.serialization.JsonSerializationWriter.writeObjectValue(JsonSerializationWriter.java:307) ~[microsoft-kiota-serialization-json-1.0.4.jar:na]
    at com.microsoft.graph.models.PlannerTask.serialize(PlannerTask.java:273) ~[microsoft-graph-6.4.0.jar:na]
    at com.microsoft.kiota.serialization.JsonSerializationWriter.writeObjectValue(JsonSerializationWriter.java:292) ~[microsoft-kiota-serialization-json-1.0.4.jar:na]
    at com.microsoft.kiota.RequestInformation.setContentFromParsable(RequestInformation.java:358) ~[microsoft-kiota-abstractions-1.0.4.jar:na]
    at com.microsoft.graph.planner.tasks.TasksRequestBuilder.toPostRequestInformation(TasksRequestBuilder.java:154) ~[microsoft-graph-6.4.0.jar:na]
    at com.microsoft.graph.planner.tasks.TasksRequestBuilder.post(TasksRequestBuilder.java:108) ~[microsoft-graph-6.4.0.jar:na]
    at com.microsoft.graph.planner.tasks.TasksRequestBuilder.post(TasksRequestBuilder.java:95) ~[microsoft-graph-6.4.0.jar:na]

I also tried creating a GSON json object and putting it there. Didn't help either.

Ndiritu commented 9 months ago

My apologies @HermanShpryhau. I meant to pass the JSON string value. Updated the sample.

HermanShpryhau commented 9 months ago

The string approach didn't work for me either. I don't have logs at hand currently unfortunately.

Eleirbag89 commented 8 months ago

The string approach didn't work. This is the error log:

Exception in thread "main" com.microsoft.graph.models.odataerrors.ODataError: An open type property has an invalid type.
    at com.microsoft.graph.models.odataerrors.ODataError.createFromDiscriminatorValue(ODataError.java:36)
    at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:210)
    at com.microsoft.kiota.http.OkHttpRequestAdapter.lambda$throwIfFailedResponse$0(OkHttpRequestAdapter.java:672)
    at com.microsoft.kiota.ApiExceptionBuilder.<init>(ApiExceptionBuilder.java:26)
    at com.microsoft.kiota.http.OkHttpRequestAdapter.throwIfFailedResponse(OkHttpRequestAdapter.java:671)
    at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:279)
    at com.microsoft.graph.planner.tasks.TasksRequestBuilder.post(TasksRequestBuilder.java:111)
    at com.microsoft.graph.planner.tasks.TasksRequestBuilder.post(TasksRequestBuilder.java:95)
    at org.example.Main.main(Main.java:39)
Ndiritu commented 8 months ago

(Triage notes) PlannerAssignments is an open type. PlannerAssignment(no 's') is declared as a component in the OpenAPI spec but not generated by Kiota. Could this be because it's not references as an optional property of plannerAssignments?

@baywet when you have some time, might you be able to share more on this?

Ndiritu commented 8 months ago

The string approach didn't work. This is the error log:

Exception in thread "main" com.microsoft.graph.models.odataerrors.ODataError: An open type property has an invalid type.
  at com.microsoft.graph.models.odataerrors.ODataError.createFromDiscriminatorValue(ODataError.java:36)
  at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:210)
  at com.microsoft.kiota.http.OkHttpRequestAdapter.lambda$throwIfFailedResponse$0(OkHttpRequestAdapter.java:672)
  at com.microsoft.kiota.ApiExceptionBuilder.<init>(ApiExceptionBuilder.java:26)
  at com.microsoft.kiota.http.OkHttpRequestAdapter.throwIfFailedResponse(OkHttpRequestAdapter.java:671)
  at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:279)
  at com.microsoft.graph.planner.tasks.TasksRequestBuilder.post(TasksRequestBuilder.java:111)
  at com.microsoft.graph.planner.tasks.TasksRequestBuilder.post(TasksRequestBuilder.java:95)
  at org.example.Main.main(Main.java:39)

Apologies @Eleirbag89 @HermanShpryhau . Realised this doesn't work because the body of the user-Id in the assignments property is sent as a JSON string instead of an object. Will investigate the root cause further

baywet commented 8 months ago

@Ndiritu I think this is one of the very few OData Dictionary usage across the API surface. @TarkanSevilmis is the architect for that API and could confirm that. PlannerAssignements is a dictionary key string value PlannerAssignment. But because OpenAPI.net doesn't support OAI 3.1 yet which brings support for dictionaries, openapi.net.odata cannot convert things properly. That means we don't have a reference to PlannerAssignment in the description, so it gets trimmed away by kiota during the generation. And whenever support for it in OpenAPI.net and OpenAPI.net.OData is added for it, adding support in kiota will be a breaking change (additions to the SerializationWriter and ParseNode interfaces).

All that to say:

We should probably direct the customer to make an arbitrary request for this one.

freelancer1845 commented 1 month ago

Is there an alternative to assign users to planner tasks? I'm having the same problem...

HermanShpryhau commented 1 month ago

As a temporary solution, I just constructed a json string according to the format in the docs, and sent a request with it via WebClient. Mind that you will need to do some kind of authentication yourself with this approach.

felipecrp commented 2 days ago

Hi,

I was trying to retrieve the users assigned to a task and I got a similar problem.

In the following:

https://github.com/microsoftgraph/msgraph-sdk-java/blob/c1aba5294c36df0d4372e5ee0ae177a3a15db177/src/main/java/com/microsoft/graph/generated/models/PlannerAssignments.java#L42C32-L42C49

We can observe that the getAdditionalData() uses an Object instead of PlannerAssignment .

How can I handle the getAdditionalData() to get the user information?

Regards, Felipe