Azure / Azure/azure-powershell

Export-AzApiManagementApi exports int32 field max/min values as decimal numbers

Open
#24,175 2 comments 0 reactions 0 assignees View on GitHub
act-observability-squad API Management bug customer-reported Service Attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

### Description

APIM contains API with following openapi specification and Export-AzApiManagementApi command used to export openapi specification as yaml format. Exported specification contains decimal numbers even specification declared fields to be int32. See amount maximum and minimum properties. If openapi specification is exported via portal then numbers are correctly in int32 format. In demonstration I am using WSL2 Ubuntu 20.04.

APIM openapi specification:
```
openapi: 3.0.1
info:
title: demoapi
description: This is demo API
version: '1.0'
servers:
-
paths:
/amount:
get:
summary: This is demo endpoint
description: This is demo endpoint
operationId: get-amount
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/AmountResponse'
example:
amount: 300
components:
schemas:
AmountResponse:
type: object
properties:
amount:
maximum: 300
minimum: 1
type: integer
format: int32
description: Amount response
securitySchemes:
apiKeyHeader:
type: apiKey
name: Ocp-Apim-Subscription-Key
in: header
apiKeyQuery:
type: apiKey
name: subscription-key
in: query
security:
- apiKeyHeader: []
- apiKeyQuery: []
```

Exported openapi specification:

```
openapi: 3.0.1
info:
title: demoapi
description: This is demo API
version: '1.0'
servers:
-
paths:
/amount:
get:
summary: This is demo endpoint
description: This is demo endpoint
operationId: get-amount
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/AmountResponse'
example:
amount: 300
components:
schemas:
AmountResponse:
type: object
properties:
amount:
maximum: 300.0
minimum: 1.0
type: integer
format: int32
description: Amount response
securitySchemes:
apiKeyHeader:
type: apiKey
name: Ocp-Apim-Subscription-Key
in: header
apiKeyQuery:
type: apiKey
name: subscription-key
in: query
security:
- apiKeyHeader: [ ]
- apiKeyQuery: [ ]
```

### Issue script & Debug output

Initial:

```PowerShell
$apiId = "demoapi"
$subscriptionId = ""
$resourceGroupName = ""
$apimName = ""
$serviceName = ""

Connect-AzAccount
Set-AzContext -Subscription $subscriptionId
```

Script:

```
$DebugPreference='Continue'
$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName $resourceGroupName -ServiceName $serviceName
Export-AzApiManagementApi -Context $ApiMgmtContext -ApiId $apiId -SpecificationFormat OpenApi -SaveAs specification.yaml -Force
```

Output:

```
DEBUG: 15:56:46 - NewAzureApiManagementContext begin processing with ParameterSet 'ContextParameterSet'.
DEBUG: 15:56:46 - using account id ''...
DEBUG: 15:56:46 - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 15:56:46 - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 15:56:46 - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: AzureQoSEvent: Module: Az.ApiManagement:4.0.2; CommandName: New-AzApiManagementContext; PSVersion: 7.4.1; IsSuccess: True; Duration: 00:00:00.0030144
DEBUG: 15:56:46 - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 15:56:46 - NewAzureApiManagementContext end processing.

DEBUG: 15:57:11 - ExportAzureApiManagementApi begin processing with ParameterSet 'ExportToFile'.
DEBUG: 15:57:11 - using account id ''...
DEBUG: 15:57:11 - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: [Common.Authentication]: Authenticating using Account: '', environment: 'AzureCloud', tenant: ''
DEBUG: 15:57:11 - [ConfigManager] Got nothing from [EnableLoginByWam], Module = [], Cmdlet = []. Returning default value [False].
DEBUG: 15:57:11 - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync - TenantId:'', Scopes:'https://management.core.windows.net//.default', AuthorityHost:'https://login.microsoftonline.com/', UserId:''
DEBUG: SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId:
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z] Found 1 cache accounts and 0 broker accounts
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z] Returning 1 accounts
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] MSAL MSAL.CoreCLR with assembly version '4.56.0.0'. CorrelationId()
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] === AcquireTokenSilent Parameters ===
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] LoginHint provided: False
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] Account provided: True
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] ForceRefresh: False
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ]
=== Request Data ===
Authority Provided? - True
Scopes - https://management.core.windows.net//.default
Extra Query Params Keys (space separated) -
ApiId - AcquireTokenSilent
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - False
HomeAccountId - False
CorrelationId -
UserAssertion set: False
LongRunningOboCacheKey set: False
Region configured:

DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] === Token Acquisition (SilentRequest) started:
Scopes: https://management.core.windows.net//.default
Authority Host: login.microsoftonline.com
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] Access token is not expired. Returning the found cache entry. [Current time (02/19/2024 13:57:11) - Expiration Time (02/19/2024 14:59:36 +00:00) - Extended Expiration Time (02/19/2024 14:59:36 +00:00)]
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] Returning access token found in cache. RefreshOn exists ? False
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ]
=== Token Acquisition finished successfully:
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.1 Ubuntu 20.04.6 LTS [2024-02-19 13:57:11Z - ] AT expiration time: 02/19/2024 14:59:36 +00:00, scopes: https://management.core.windows.net//user_impersonation https://management.core.windows.net//.default. source: Cache
DEBUG: SharedTokenCacheCredential.GetToken succeeded. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId: ExpiresOn: 2024-02-19T14:59:36.0000000+00:00
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: '', UserId: ''
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//apis/demoapi?format=openapi-link&export=true&api-version=2021-08-01

Headers:
Accept-Language : en-US
x-ms-client-request-id :

Body:

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

Status Code:
OK

Headers:
Cache-Control : no-cache
Pragma : no-cache
ETag : "AAAAAAACaeY="
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
x-ms-request-id :
Server : Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-reads: 11987
x-ms-correlation-request-id :
x-ms-routing-request-id : SWEDENCENTRAL:20240219T135714Z:
Date : Mon, 19 Feb 2024 13:57:13 GMT

Body:
{
"id": "/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//apis/demoapi",
"format": "openapi-link",
"value": {
"link": "https://.blob.core.windows.net/api-export/demoapi.yaml?sv=2017-04-17&sr=b&sig=&se=2024-02-19T14:02:14Z&sp=r"
}
}

DEBUG: 15:57:13 - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 15:57:13 - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: AzureQoSEvent: Module: Az.ApiManagement:4.0.2; CommandName: Export-AzApiManagementApi; PSVersion: 7.4.1; IsSuccess: True; Duration: 00:00:01.5715022
DEBUG: 15:57:13 - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 15:57:13 - ExportAzureApiManagementApi end processing.

```

### Environment data

```PowerShell
Name Value
---- -----
PSVersion 7.4.1
PSEdition Core
GitCommitId 7.4.1
OS Ubuntu 20.04.6 LTS
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```

### Module versions

```PowerShell
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.15.1 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script 4.0.2 Az.ApiManagement {Add-AzApiManagementApiToGateway, Add-AzApiManagementApiToProduct, Add-AzApiManagement…
```

### Error output

```PowerShell
DEBUG: 15:57:38 - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 15:57:38 - using account id ''...
DEBUG: 15:57:38 - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].

DEBUG: 15:57:38 - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 15:57:38 - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: AzureQoSEvent: Module: Az.Accounts:2.15.1; CommandName: Resolve-AzError; PSVersion: 7.4.1; IsSuccess: True; Duration: 00:00:00.0017554
DEBUG: 15:57:38 - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 15:57:38 - ResolveError end processing.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.