Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit f31ce37

Browse files
authored
Add support for AdditionalProperties Json schema with array type (#339)
* Added support for AdditionalProperties Json schema with array type. ```json "type": "string", "additionalProperties": { "type": "array", "items": { "type": "string" } } ``` Current error ```powershell Generating module for 'C:\temp\AzureSwaggerSpecs\SwaggerSpecs\network\applicationGateway.json'. WARNING: 'ParameterJsonObject' has unsupported properties. type additionalProperties description ---- -------------------- ----------- string @{type=array; items=; description=List of IP Addresses within the tag (key)} Mapping of tags to list of IP Addresses included within the tag. ``` * Added support for $ParameterJsonObject.AdditionalProperties.Items.'$ref'
1 parent 9891ec8 commit f31ce37

File tree

4 files changed

+161
-0
lines changed

4 files changed

+161
-0
lines changed

PSSwagger/Definitions.psm1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,44 @@ function Get-DefinitionParameterType
383383
Write-Warning -Message $Message
384384
}
385385
}
386+
elseif($ParameterJsonObject.Type -eq 'string') {
387+
if((Get-Member -InputObject $ParameterJsonObject.AdditionalProperties -Name 'Type') -and
388+
($ParameterJsonObject.AdditionalProperties.Type -eq 'array'))
389+
{
390+
if(Get-Member -InputObject $ParameterJsonObject.AdditionalProperties -Name 'Items')
391+
{
392+
if((Get-Member -InputObject $ParameterJsonObject.AdditionalProperties.Items -Name 'Type') -and
393+
$ParameterJsonObject.AdditionalProperties.Items.Type)
394+
{
395+
$ItemsType = Get-PSTypeFromSwaggerObject -JsonObject $ParameterJsonObject.AdditionalProperties.Items
396+
$ParameterType = "System.Collections.Generic.Dictionary[[string],[System.Collections.Generic.List[$ItemsType]]]"
397+
}
398+
elseif((Get-Member -InputObject $ParameterJsonObject.AdditionalProperties.Items -Name '$ref') -and
399+
$ParameterJsonObject.AdditionalProperties.Items.'$ref')
400+
{
401+
$ReferenceTypeValue = $ParameterJsonObject.AdditionalProperties.Items.'$ref'
402+
$ReferenceTypeName = Get-CSharpModelName -Name $ReferenceTypeValue.Substring( $( $ReferenceTypeValue.LastIndexOf('/') ) + 1 )
403+
$ItemsType = $DefinitionTypeNamePrefix + "$ReferenceTypeName"
404+
$ParameterType = "System.Collections.Generic.Dictionary[[string],[System.Collections.Generic.List[$ItemsType]]]"
405+
}
406+
else
407+
{
408+
$Message = $LocalizedData.UnsupportedSwaggerProperties -f ('ParameterJsonObject', $($ParameterJsonObject | Out-String))
409+
Write-Warning -Message $Message
410+
}
411+
}
412+
else
413+
{
414+
$Message = $LocalizedData.UnsupportedSwaggerProperties -f ('ParameterJsonObject', $($ParameterJsonObject | Out-String))
415+
Write-Warning -Message $Message
416+
}
417+
}
418+
else
419+
{
420+
$Message = $LocalizedData.UnsupportedSwaggerProperties -f ('ParameterJsonObject', $($ParameterJsonObject | Out-String))
421+
Write-Warning -Message $Message
422+
}
423+
}
386424
else {
387425
$Message = $LocalizedData.UnsupportedSwaggerProperties -f ('ParameterJsonObject', $($ParameterJsonObject | Out-String))
388426
Write-Warning -Message $Message

PSSwagger/SwaggerUtils.psm1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,44 @@ function Get-ParamType
987987
Write-Warning -Message $Message
988988
}
989989
}
990+
elseif($ParameterJsonObject.Type -eq 'string') {
991+
if((Get-Member -InputObject $ParameterJsonObject.AdditionalProperties -Name 'Type') -and
992+
($ParameterJsonObject.AdditionalProperties.Type -eq 'array'))
993+
{
994+
if(Get-Member -InputObject $ParameterJsonObject.AdditionalProperties -Name 'Items')
995+
{
996+
if((Get-Member -InputObject $ParameterJsonObject.AdditionalProperties.Items -Name 'Type') -and
997+
$ParameterJsonObject.AdditionalProperties.Items.Type)
998+
{
999+
$ItemsType = Get-PSTypeFromSwaggerObject -JsonObject $ParameterJsonObject.AdditionalProperties.Items
1000+
$paramType = "System.Collections.Generic.Dictionary[[string],[System.Collections.Generic.List[$ItemsType]]]"
1001+
}
1002+
elseif((Get-Member -InputObject $ParameterJsonObject.AdditionalProperties.Items -Name '$ref') -and
1003+
$ParameterJsonObject.AdditionalProperties.Items.'$ref')
1004+
{
1005+
$ReferenceTypeValue = $ParameterJsonObject.AdditionalProperties.Items.'$ref'
1006+
$ReferenceTypeName = Get-CSharpModelName -Name $ReferenceTypeValue.Substring( $( $ReferenceTypeValue.LastIndexOf('/') ) + 1 )
1007+
$ItemsType = $DefinitionTypeNamePrefix + "$ReferenceTypeName"
1008+
$paramType = "System.Collections.Generic.Dictionary[[string],[System.Collections.Generic.List[$ItemsType]]]"
1009+
}
1010+
else
1011+
{
1012+
$Message = $LocalizedData.UnsupportedSwaggerProperties -f ('ParameterJsonObject', $($ParameterJsonObject | Out-String))
1013+
Write-Warning -Message $Message
1014+
}
1015+
}
1016+
else
1017+
{
1018+
$Message = $LocalizedData.UnsupportedSwaggerProperties -f ('ParameterJsonObject', $($ParameterJsonObject | Out-String))
1019+
Write-Warning -Message $Message
1020+
}
1021+
}
1022+
else
1023+
{
1024+
$Message = $LocalizedData.UnsupportedSwaggerProperties -f ('ParameterJsonObject', $($ParameterJsonObject | Out-String))
1025+
Write-Warning -Message $Message
1026+
}
1027+
}
9901028
else {
9911029
$Message = $LocalizedData.UnsupportedSwaggerProperties -f ('ParameterJsonObject', $($ParameterJsonObject | Out-String))
9921030
Write-Warning -Message $Message

Tests/PSSwaggerScenario.Tests.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,19 @@ Describe "ParameterTypes tests" -Tag @('ParameterTypes','ScenarioTest') {
398398
$HelpInfo2.Description.Text | Should BeExactly $ExpectedText
399399
$HelpInfo2.Synopsis | Should BeExactly $ExpectedText
400400
}
401+
402+
It 'Test parameter types with array of items in AdditionalProperties json schema' {
403+
$ModuleName = 'Generated.ParamTypes.Module'
404+
$ev = $null
405+
$null = Get-Command -Module $ModuleName -Syntax -ErrorVariable ev
406+
$ev | Should BeNullOrEmpty
407+
408+
$OperationCommandInfo = Get-Command -name Get-EffectiveNetworkSecurityGroup -Module $ModuleName
409+
$OperationCommandInfo.Parameters.OperationTagMap.ParameterType.ToString() | Should BeExactly 'System.Collections.Generic.IDictionary`2[System.String,System.Collections.Generic.IList`1[System.String]]'
410+
411+
$NewObjectCommandInfo = Get-Command -Name New-EffectiveNetworkSecurityGroupObject -Module $ModuleName
412+
$NewObjectCommandInfo.Parameters.TagMap.ParameterType.ToString() | Should BeExactly 'System.Collections.Generic.Dictionary`2[System.String,System.Collections.Generic.List`1[System.String]]'
413+
}
401414
}
402415

403416
AfterAll {

Tests/data/ParameterTypes/ParameterTypesSpec.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,58 @@
298298
}
299299
}
300300
}
301+
},
302+
"/PathWithEffectiveNetworkSecurityGroup": {
303+
"get": {
304+
"summary": "List all dinosaurs matching parameters",
305+
"operationId": "EffectiveNetworkSecurityGroup_Get",
306+
"description": "List all dinosaurs matching parameters",
307+
"parameters": [
308+
{
309+
"$ref": "#/parameters/ApiVersionParameter"
310+
},
311+
{
312+
"$ref": "#/parameters/SubscriptionIdParameter"
313+
},
314+
{
315+
"name": "OperationTagMap",
316+
"in": "query",
317+
"required": false,
318+
"type": "string",
319+
"additionalProperties": {
320+
"type": "array",
321+
"items": {
322+
"type": "string"
323+
},
324+
"description": "List of IP Addresses within the tag (key)"
325+
},
326+
"description": "Mapping of tags to list of IP Addresses included within the tag."
327+
},
328+
{
329+
"name": "EffectiveNetworkSecurityGroup",
330+
"in": "body",
331+
"required": true,
332+
"schema": {
333+
"$ref": "#/definitions/EffectiveNetworkSecurityGroup"
334+
},
335+
"description": "Group filtering parameters."
336+
}
337+
],
338+
"responses": {
339+
"200": {
340+
"description": "OK",
341+
"schema": {
342+
"$ref": "#/definitions/Namespace"
343+
}
344+
},
345+
"default": {
346+
"description": "Error",
347+
"schema": {
348+
"$ref": "#/definitions/Error"
349+
}
350+
}
351+
}
352+
}
301353
}
302354
},
303355
"definitions": {
@@ -538,6 +590,26 @@
538590
}
539591
},
540592
"description": "The response of the List Namespace operation."
593+
},
594+
"EffectiveNetworkSecurityGroup": {
595+
"properties": {
596+
"id": {
597+
"type": "string",
598+
"description": "Unique identifier"
599+
},
600+
"tagMap": {
601+
"type": "string",
602+
"additionalProperties": {
603+
"type": "array",
604+
"items": {
605+
"type": "string"
606+
},
607+
"description": "List of IP Addresses within the tag (key)"
608+
},
609+
"description": "Mapping of tags to list of IP Addresses included within the tag."
610+
}
611+
},
612+
"description": "Effective network security group."
541613
}
542614
},
543615
"parameters": {

0 commit comments

Comments
 (0)