@@ -256,6 +256,13 @@ function New-PSSwaggerModule
256256 return
257257 }
258258
259+ # Get the PowerShell Metadata if .psmeta.json file is available.
260+ $PSMetaJsonObject = $null
261+ $PSMetaFilePath = [regex ]::replace($SwaggerSpecPath , " .json$" , " .psmeta.json" )
262+ if (Test-Path - Path $PSMetaFilePath - PathType Leaf) {
263+ $PSMetaJsonObject = ConvertFrom-Json - InputObject ((Get-Content - Path $PSMetaFilePath ) -join [Environment ]::NewLine) - ErrorAction Stop
264+ }
265+
259266 if ($PSCmdlet.ParameterSetName -eq ' SwaggerPath' )
260267 {
261268 $jsonObject = ConvertFrom-Json - InputObject ((Get-Content - Path $SwaggerSpecPath ) -join [Environment ]::NewLine) - ErrorAction Stop
@@ -339,6 +346,7 @@ function New-PSSwaggerModule
339346 CustomAuthCommand = " "
340347 HostOverrideCommand = " "
341348 NoAuthChallenge = $false
349+ NameSpacePrefix = ' '
342350 }
343351
344352 # Parse the JSON and populate the dictionary
@@ -351,19 +359,22 @@ function New-PSSwaggerModule
351359 DefinitionFunctionsDetails = $DefinitionFunctionsDetails
352360 AzureSpec = $UseAzureCsharpGenerator
353361 PowerShellCodeGen = $PowerShellCodeGen
362+ PSMetaJsonObject = $PSMetaJsonObject
354363 }
355364 $swaggerDict = ConvertTo-SwaggerDictionary @ConvertToSwaggerDictionary_params
356365
357- Get-PowerShellCodeGenSettings - Path $SwaggerSpecPath - CodeGenSettings $PowerShellCodeGen
358- foreach ($additionalSwaggerSpecPath in $SwaggerSpecFilePaths ) {
359- Get-PowerShellCodeGenSettings - Path $additionalSwaggerSpecPath - CodeGenSettings $PowerShellCodeGen
366+ Get-PowerShellCodeGenSettings - Path $SwaggerSpecPath - CodeGenSettings $PowerShellCodeGen - PSMetaJsonObject $PSMetaJsonObject
367+ if (-not $PSMetaJsonObject ) {
368+ foreach ($additionalSwaggerSpecPath in $SwaggerSpecFilePaths ) {
369+ Get-PowerShellCodeGenSettings - Path $additionalSwaggerSpecPath - CodeGenSettings $PowerShellCodeGen
370+ }
360371 }
361372
362373 # Expand partner metadata
363374 if ($PowerShellCodeGen [' ServiceType' ]) {
364375 $partnerFilePath = Join-Path - Path $PSScriptRoot - ChildPath " ServiceTypes" | Join-Path - ChildPath " $ ( $PowerShellCodeGen [' ServiceType' ].ToLowerInvariant()) .PSMeta.json"
365- if (-not (Test-Path - Path $partnerFilePath )) {
366- Write-Warning - Message " Service type metadata file doesn't exist: $partnerFilePath "
376+ if (-not (Test-Path - Path $partnerFilePath - PathType Leaf )) {
377+ Write-Warning - Message ( $LocalizedData .ServiceTypeMetadataFileNotFound -f $partnerFilePath )
367378 } else {
368379 Get-PowerShellCodeGenSettings - Path $partnerFilePath - CodeGenSettings $PowerShellCodeGen
369380 }
@@ -388,8 +399,8 @@ function New-PSSwaggerModule
388399 }
389400 }
390401
391- $null = New-Item - ItemType Directory $outputDirectory - Force - ErrorAction Stop
392- $null = New-Item - ItemType Directory $SymbolPath - Force - ErrorAction Stop
402+ $null = New-Item - ItemType Directory $outputDirectory - Force - ErrorAction Stop - Confirm: $false - WhatIf: $false
403+ $null = New-Item - ItemType Directory $SymbolPath - Force - ErrorAction Stop - Confirm: $false - WhatIf: $false
393404
394405 $swaggerMetaDict = @ {
395406 OutputDirectory = $outputDirectory
@@ -424,7 +435,8 @@ function New-PSSwaggerModule
424435 - SwaggerDict $swaggerDict `
425436 - SwaggerMetaDict $swaggerMetaDict `
426437 - DefinitionFunctionsDetails $DefinitionFunctionsDetails `
427- - ParameterGroupCache $ParameterGroupCache
438+ - ParameterGroupCache $ParameterGroupCache `
439+ - PSMetaJsonObject $PSMetaJsonObject
428440 }
429441 }
430442
@@ -436,7 +448,9 @@ function New-PSSwaggerModule
436448 - SwaggerDict $swaggerDict `
437449 - SwaggerMetaDict $swaggerMetaDict `
438450 - DefinitionFunctionsDetails $DefinitionFunctionsDetails `
439- - ParameterGroupCache $ParameterGroupCache
451+ - ParameterGroupCache $ParameterGroupCache `
452+ - PSMetaJsonObject $PSMetaJsonObject
453+
440454 }
441455 }
442456 }
@@ -454,10 +468,14 @@ function New-PSSwaggerModule
454468 $PathFunctionDetails = $codePhaseResult.PathFunctionDetails
455469 $generatedCSharpFilePath = $codePhaseResult.GeneratedCSharpPath
456470
471+ # Need to expand the definitions early as parameter flattening feature requires the parameters list of the definition/model types.
472+ Expand-SwaggerDefinition - DefinitionFunctionsDetails $DefinitionFunctionsDetails - NameSpace $NameSpace - Models $Models
473+
457474 $FunctionsToExport = @ ()
458475 $FunctionsToExport += New-SwaggerSpecPathCommand - PathFunctionDetails $PathFunctionDetails `
459476 - SwaggerMetaDict $swaggerMetaDict `
460- - SwaggerDict $swaggerDict
477+ - SwaggerDict $swaggerDict `
478+ - DefinitionFunctionsDetails $DefinitionFunctionsDetails
461479
462480 $FunctionsToExport += New-SwaggerDefinitionCommand - DefinitionFunctionsDetails $DefinitionFunctionsDetails `
463481 - SwaggerMetaDict $swaggerMetaDict `
@@ -545,7 +563,7 @@ function ConvertTo-CsharpCode
545563
546564 $clrPath = Join-Path - Path $outputDirectory - ChildPath ' ref' | Join-Path - ChildPath ' fullclr'
547565 if (-not (Test-Path - Path $clrPath )) {
548- $null = New-Item - Path $clrPath - ItemType Directory
566+ $null = New-Item - Path $clrPath - ItemType Directory - Force - Confirm: $false - WhatIf: $false
549567 }
550568
551569 $outAssembly = " $NameSpace .dll"
@@ -705,7 +723,7 @@ function ConvertTo-CsharpCode
705723 }
706724
707725 if (-not (Test-Path - Path $clrPath )) {
708- $null = New-Item $clrPath - ItemType Directory
726+ $null = New-Item $clrPath - ItemType Directory - Force - Confirm: $false - WhatIf: $false
709727 }
710728 $dependencies = Get-PSSwaggerExternalDependencies - Azure:$codeCreatedByAzureGenerator - Framework ' netstandard1'
711729 $microsoftRestClientRuntimeAzureRequiredVersion = if ($dependencies.ContainsKey (' Microsoft.Rest.ClientRuntime.Azure' )) { $dependencies [' Microsoft.Rest.ClientRuntime.Azure' ].RequiredVersion } else { ' ' }
0 commit comments