Skip to content

responses from functions with returntype collection are not being parsed as openApiDocs YML are not representing function return types correctly as OData message bodies #665

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

Closed
markwahl-msft opened this issue May 15, 2021 · 3 comments · Fixed by #1324

Comments

@markwahl-msft
Copy link
Contributor

markwahl-msft commented May 15, 2021

For example Get-MgReportCredentialUsageSummary -Period "D30" -Verbose -Debug
sends the correct request according to https://docs.microsoft.com/en-us/graph/api/reportroot-getcredentialusagesummary?view=graph-rest-beta&tabs=http
The metadata indicates that function returns <ReturnType Type="Collection(graph.credentialUsageSummary)" Nullable="false" /> and the response is formatted according to OData 4,

Each message body is represented as a single JSON object. This object is either ... or it contains a name/value pair whose name MUST be value and whose value is the correct representation for ... a collection of entities, or a collection of objects that represent changes to a previous result.

However this cmdlet fails to process the response from Microsoft graph

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#Collection(credentialUsageSummary)",
    "value": [
        {
            "@odata.type": "#microsoft.graph.credentialUsageSummary",
            "id": "11933632-39ca-4e44-a97a-6bc86aafb5c2",

with an error of

DEBUG: CmdletException: InvalidCastException - Unable to cast object of type
'Microsoft.Graph.PowerShell.Runtime.Json.JsonObject' to type 'Microsoft.Graph.PowerShell.Runtime.Json.JsonArray'. : at Microsoft.Graph.PowerShell.Runtime.Json.JsonArray.Parse(String text)
at Microsoft.Graph.PowerShell.Reports.<>c.<ReportsGetCredentialUsageSummary_Call>b__158_0(Task`1 body)

that causes the cmdlet to fail.

Get-MgReportCredentialUsageSummary_Get: Unable to cast object of type 'Microsoft.Graph.PowerShell.Runtime.Json.JsonObject' to type 'Microsoft.Graph.PowerShell.Runtime.Json.JsonArray'.

I observed the same behavior with an identity governance cmdlet Invoke-MgFilterEntitlementManagementAccessPackage -On "'allowedRequestor'" also failing with the same error, and observed that the stack trace included a call to JsonArray.Parse in IdentityGovernance.cs

body => If( Microsoft.Graph.PowerShell.Runtime.Json.JsonArray.Parse(body.Result) 

I believe this may be due to an issue in the openapidocs/*.yml files. I observed the functions had a response pattern that looked like

        content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/microsoft.graph.accessPackage'

rather than

          content:
            application/json:
              schema:
                title: Collection of accessPackage
                type: object
                properties:
                  value:
                    type: array
                    items:
                      $ref: '#/components/schemas/microsoft.graph.accessPackage'
                  '@odata.nextLink':
                    type: string
                additionalProperties:
                  type: object

and similarly Reports.yml had

          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/microsoft.graph.credentialUsageSummary'

whereas I would have expected

          content:
            application/json:
              schema:
                title: Collection of credentialUsageSummary
                type: object
                properties:
                  value:
                    type: array
                    items:
                      $ref: '#/components/schemas/microsoft.graph.credentialUsageSummary'
                  '@odata.nextLink':
                    type: string
                additionalProperties:
                  type: object

AB#9483

@ghost ghost added the ToTriage label May 15, 2021
@markwahl-msft
Copy link
Contributor Author

markwahl-msft commented May 17, 2021

FYI also see this in YML response to, for example, https://graphexplorerapi.azurewebsites.net/openapi?operationIds=reports.getCredentialUsageSummary&openApiVersion=3&graphVersion=beta&format=yaml
added there as microsoftgraph/microsoft-graph-devx-api#571

@Tiberriver256
Copy link

Any update on this? I'm receiving the same error message on Get-MgUserById

@mblaschke
Copy link

got the same problem with Get-MgDirectoryObjectById

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants