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

Get-AzApiManagementApiSchema cmdlet failing on schema type of OpenApi #10626

Closed
bremnes opened this issue Nov 28, 2019 · 5 comments
Closed

Get-AzApiManagementApiSchema cmdlet failing on schema type of OpenApi #10626

bremnes opened this issue Nov 28, 2019 · 5 comments
Assignees
Labels
API Management customer-reported Service Attention This issue is responsible by Azure service team.

Comments

@bremnes
Copy link

bremnes commented Nov 28, 2019

Description

When running the cmdlet Get-AzApiManagementApiSchema on an API with a content type of application/vnd.oai.openapi.components+json (OpenAPI v3), the command fails:

PS C:\Users\username> Get-AzApiManagementApiSchema -ApiId swagger-petstore-openapi -Context $apiMgmtContext
Get-AzApiManagementApiSchema : Error mapping types.
Mapping types:
List`1 -> IList`1
System.Collections.Generic.List`1[[Microsoft.Azure.Management.ApiManagement.Models.SchemaContract, Microsoft.Azure.Mana
gement.ApiManagement, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] -> System.Collections.Generic
.IList`1[[Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementApiSchema, Microsoft.Azure.Pow
erShell.Cmdlets.ApiManagement.ServiceManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]
At line:1 char:1
+ Get-AzApiManagementApiSchema -ApiId swagger-petstore-openapi -Context ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzApiManagementApiSchema], AutoMapperMappingException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.GetAzureApiManagementA
   piSchema

Steps to reproduce

If you need to create an OpenApi v3 api, uncomment the line below to import the petstore example

$apim = Get-AzApiManagement # only works if there is one apim instance in the subscription
$apiMgmtContext = New-AzApiManagementContext -ResourceGroupName $apim.ResourceGroupName -ServiceName $apim.Name

# TODO: change the id if necessary
$openApiApiId = 'swagger-petstore-openapi'

# TODO: run this if you need to create an api to test with
#Import-AzApiManagementApi -Context $apiMgmtContext -ApiId $openApiApiId -SpecificationUrl https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml -Protocol https -Path petstore-openapi-test -SpecificationFormat OpenApi

Get-AzApiManagementApiSchema -ApiId $openApiApiId -Context $apiMgmtContext

Environment data

Name                           Value
----                           -----
PSVersion                      5.1.18362.145
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.18362.145
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Module versions

Script     1.3.2      Az.ApiManagement                    {Add-AzApiManagementApiToProduct, Add-AzApiManagementProdu...

Debug output

(subset as most of the rest was related to authenticating)

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
...
Body:
{
  "value": [
    {
      "id":
"/subscriptions/.../apis/swagger-petstore-openapi/schemas/5ddfb94b34ddc31398a44439"
,
      "type": "Microsoft.ApiManagement/service/apis/schemas",
      "name": "5ddfb94b34ddc31398a44439",
      "properties": {
        "contentType": "application/vnd.oai.openapi.components+json",
        "document": {
          "components": {
            "schemas": {
              "Pet": {
                "required": [
                  "id",
                  "name"
                ],
                "type": "object",
                "properties": {
                  "id": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "name": {
                    "type": "string"
                  },
                  "tag": {
                    "type": "string"
                  }
                }
              },
              "Pets": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Pet"
                }
              },
              "Error": {
                "required": [
                  "code",
                  "message"
                ],
                "type": "object",
                "properties": {
                  "code": {
                    "type": "integer",
                    "format": "int32"
                  },
                  "message": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    }
  ],
  "count": 1
}

Get-AzApiManagementApiSchema : Error mapping types.
Mapping types:
List`1 -> IList`1
System.Collections.Generic.List`1[[Microsoft.Azure.Management.ApiManagement.Models.SchemaContract, Microsoft.Azure.Management.ApiManagement, Version=4.0.0.0, Culture=neutral, PublicKeyToken
=31bf3856ad364e35]] -> System.Collections.Generic.IList`1[[Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementApiSchema, Microsoft.Azure.PowerShell.Cmdlets.ApiMa
nagement.ServiceManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]
At line:1 char:1
+ Get-AzApiManagementApiSchema -ApiId  swagger-petstore-openapi -Context $ApiMgmtCo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzApiManagementApiSchema], AutoMapperMappingException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.GetAzureApiManagementApiSchema

DEBUG: AzureQoSEvent: CommandName - Get-AzApiManagementApiSchema; IsSuccess - False; Duration - 00:00:01.6012943; Exception - AutoMapper.AutoMapperMappingException: Error mapping types.

Mapping types:
List`1 -> IList`1
System.Collections.Generic.List`1[[Microsoft.Azure.Management.ApiManagement.Models.SchemaContract, Microsoft.Azure.Management.ApiManagement, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35]] -> System.Collections.Generic.IList`1[[Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementApiSchema,
Microsoft.Azure.PowerShell.Cmdlets.ApiManagement.ServiceManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] ---> System.Exception: Unable for parse Schema
Document for ContentType application/vnd.oai.openapi.components+json. ---> System.NullReferenceException: Objektreferanse er ikke satt til en objektforekomst.
   ved Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Utils.GetSchemaDocumentValue(SchemaContract schemaContract)
   --- Slutten på sporingen av intern unntaksstakk ---
   ved Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Utils.GetSchemaDocumentValue(SchemaContract schemaContract)
   ved Microsoft.Azure.Commands.ApiManagement.ServiceManagement.ApiManagementClient.<>c.<ConfigureMappings>b__12_221(SchemaContract src, PsApiManagementApiSchema dest)
   ved lambda_method(Closure , List`1 , IList`1 , ResolutionContext )
   --- Slutten på sporingen av intern unntaksstakk ---
   ved lambda_method(Closure , List`1 , IList`1 , ResolutionContext )
   ved lambda_method(Closure , Object , Object , ResolutionContext )
   ved AutoMapper.Mapper.AutoMapper.IMapper.Map[TDestination](Object source)
   ved Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.GetAzureApiManagementApiSchema.ExecuteApiManagementCmdlet()
   ved Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.AzureApiManagementCmdletBase.ExecuteCmdlet();
DEBUG: Finish sending metric.
DEBUG: 13:17:25 - GetAzureApiManagementApiSchema end processing.
DEBUG: 13:17:25 - GetAzureApiManagementApiSchema end processing.

Error output

Message        : Error mapping types.
                 
                 Mapping types:
                 List`1 -> IList`1
                 System.Collections.Generic.List`1[[Microsoft.Azure.Management.ApiManagement.Models.SchemaContract, Microsoft.Azure.Management.ApiManagement, Version=4.0.0.0, Culture=neutra
                 l, PublicKeyToken=31bf3856ad364e35]] -> System.Collections.Generic.IList`1[[Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementApiSchema, Micros
                 oft.Azure.PowerShell.Cmdlets.ApiManagement.ServiceManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]
StackTrace     :    ved lambda_method(Closure , List`1 , IList`1 , ResolutionContext )
                    ved lambda_method(Closure , Object , Object , ResolutionContext )
                    ved AutoMapper.Mapper.AutoMapper.IMapper.Map[TDestination](Object source)
                    ved Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.GetAzureApiManagementApiSchema.ExecuteApiManagementCmdlet()
                    ved Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.AzureApiManagementCmdletBase.ExecuteCmdlet()
Exception      : AutoMapper.AutoMapperMappingException
InvocationInfo : {Get-AzApiManagementApiSchema}
Line           : Get-AzApiManagementApiSchema -ApiId  swagger-petstore-openapi -Context $apiMgmtContext
Position       : At line:1 char:1
                 + Get-AzApiManagementApiSchema -ApiId  swagger-petstore-openapi -Context $apiMgmtCo ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 22

Message        : Unable for parse Schema Document for ContentType application/vnd.oai.openapi.components+json.
StackTrace     :    ved Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Utils.GetSchemaDocumentValue(SchemaContract schemaContract)
                    ved Microsoft.Azure.Commands.ApiManagement.ServiceManagement.ApiManagementClient.<>c.<ConfigureMappings>b__12_221(SchemaContract src, PsApiManagementApiSchema dest)
                    ved lambda_method(Closure , List`1 , IList`1 , ResolutionContext )
Exception      : System.Exception
InvocationInfo : {Get-AzApiManagementApiSchema}
Line           : Get-AzApiManagementApiSchema -ApiId  swagger-petstore-openapi -Context $apiMgmtContext
Position       : At line:1 char:1
                 + Get-AzApiManagementApiSchema -ApiId  swagger-petstore-openapi -Context $apiMgmtCo ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 22

Message        : Objektreferanse er ikke satt til en objektforekomst.
StackTrace     :    ved Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Utils.GetSchemaDocumentValue(SchemaContract schemaContract)
Exception      : System.NullReferenceException
InvocationInfo : {Get-AzApiManagementApiSchema}
Line           : Get-AzApiManagementApiSchema -ApiId  swagger-petstore-openapi -Context $apiMgmtContext
Position       : At line:1 char:1
                 + Get-AzApiManagementApiSchema -ApiId  swagger-petstore-openapi -Context $apiMgmtCo ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 22
@bremnes bremnes added the triage label Nov 28, 2019
@bremnes
Copy link
Author

bremnes commented Nov 28, 2019

See method Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Utils.GetSchemaDocumentValue for where the error is. We've seen the same errors in the APIM DevOps project.

The json returned by Azure's rest api is different for openapi because it doesn't return the "value" property which is expected. It returns "components" for application/vnd.oai.openapi.components+json.

@VeryEarly VeryEarly added API Management Service Attention This issue is responsible by Azure service team. and removed triage labels Nov 29, 2019
@ghost
Copy link

ghost commented Nov 29, 2019

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @mjconnection

1 similar comment
@ghost
Copy link

ghost commented Nov 29, 2019

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @mjconnection

@VeryEarly
Copy link
Contributor

thanks for the feedback, forwarded to api management team

@solankisamir
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Management customer-reported Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

3 participants