Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions PSSwagger/PSSwagger.Constants.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,7 @@ $TableColumnHeaderStr = @'

$DefaultGeneratedFileHeader = @'
Code generated by Microsoft (R) PSSwagger {0}
Changes may cause incorrect behavior and will be lost if the code is
regenerated.
Changes may cause incorrect behavior and will be lost if the code is regenerated.
'@

$PSCommentFormatString = "<#
Expand All @@ -533,4 +532,31 @@ $PSCommentFormatString = "<#
$XmlCommentFormatString = "<!--
{0}
-->
"
"

$DefaultGeneratedFileHeaderWithoutVersion = @'
Code generated by Microsoft (R) PSSwagger
Changes may cause incorrect behavior and will be lost if the code is regenerated.
'@

$MicrosoftApacheLicenseHeader = @'
Copyright (c) Microsoft and contributors. All rights reserved.

Licensed under the Apache License, Version 2.0 (the ""License"");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and
limitations under the License.
'@

$MicrosoftMitLicenseHeader = @'
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. See License.txt in the project root for license information.
'@

37 changes: 33 additions & 4 deletions PSSwagger/PSSwagger.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ Microsoft.PowerShell.Utility\Import-LocalizedData LocalizedData -filename PSSwa
.PARAMETER Header
Text to include as a header comment in the PSSwagger generated files.
It also can be a path to a .txt file with the content to be added as header in the PSSwagger generated files.
Specify 'NONE' to suppress the default header.

Supported predefined license header values:
- NONE: Suppresses the default header.
- MICROSOFT_MIT: Adds predefined Microsoft MIT license text with default PSSwagger code generation header content.
- MICROSOFT_MIT_NO_VERSION: Adds predefined Microsoft MIT license text with default PSSwagger code generation header content without version.
- MICROSOFT_MIT_NO_CODEGEN: Adds predefined Microsoft MIT license text without default PSSwagger code generation header content.
- MICROSOFT_APACHE: Adds predefined Microsoft Apache license text with default PSSwagger code generation header content.
- MICROSOFT_APACHE_NO_VERSION: Adds predefined Microsoft Apache license text with default PSSwagger code generation header content without version.
- MICROSOFT_APACHE_NO_CODEGEN: Adds predefined Microsoft Apache license text without default PSSwagger code generation header content.

.PARAMETER NoAssembly
Switch to disable saving the precompiled module assembly and instead enable dynamic compilation.
Expand Down Expand Up @@ -931,6 +939,30 @@ function Get-HeaderContent {
$Header = $swaggerDict['Info'].Header
$HeaderContent = ($DefaultGeneratedFileHeader -f $MyInvocation.MyCommand.Module.Version)
if ($Header) {
switch ($Header) {
'MICROSOFT_MIT' {
return $MicrosoftMitLicenseHeader + [Environment]::NewLine + [Environment]::NewLine + $HeaderContent
}
'MICROSOFT_MIT_NO_VERSION' {
return $MicrosoftMitLicenseHeader + [Environment]::NewLine + [Environment]::NewLine + $DefaultGeneratedFileHeaderWithoutVersion
}
'MICROSOFT_MIT_NO_CODEGEN' {
return $MicrosoftMitLicenseHeader
}
'MICROSOFT_APACHE' {
return $MicrosoftApacheLicenseHeader + [Environment]::NewLine + [Environment]::NewLine + $HeaderContent
}
'MICROSOFT_APACHE_NO_VERSION' {
return $MicrosoftApacheLicenseHeader + [Environment]::NewLine + [Environment]::NewLine + $DefaultGeneratedFileHeaderWithoutVersion
}
'MICROSOFT_APACHE_NO_CODEGEN' {
return $MicrosoftApacheLicenseHeader
}
'NONE' {
return ''
}
}

$HeaderFilePath = Resolve-Path -Path $Header -ErrorAction Ignore
if ($HeaderFilePath) {
# Selecting the first path when multiple paths are returned by Resolve-Path cmdlet.
Expand Down Expand Up @@ -958,9 +990,6 @@ function Get-HeaderContent {
Write-Error -Message $message -ErrorId 'HeaderFilePathNotFound' -Category InvalidArgument
return
}
elseif ($Header -eq 'NONE') {
$HeaderContent = $null
}
else {
$HeaderContent = $Header
}
Expand Down
28 changes: 28 additions & 0 deletions Tests/PSSwagger.Unit.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,34 @@ Describe "PSSwagger Unit Tests" -Tag @('BVT', 'DRT', 'UnitTest', 'P0') {
It "Get-HeaderContent should return content from the header file" {
Get-HeaderContent -SwaggerDict @{Info = @{Header = $ValidHeaderFilePath}} | Should BeExactly $HeaderFileContent
}

It "Get-HeaderContent should return MICROSOFT_MIT header content with '-Header MICROSOFT_MIT'" {
$ExpectedHeaderContent = $MicrosoftMitLicenseHeader + [Environment]::NewLine + [Environment]::NewLine + $DefaultGeneratedFileHeaderString
Get-HeaderContent -SwaggerDict @{Info = @{Header = 'MICROSOFT_MIT'}} | Should BeExactly $ExpectedHeaderContent
}

It "Get-HeaderContent should return MICROSOFT_MIT_NO_VERSION header content with '-Header MICROSOFT_MIT_NO_VERSION'" {
$ExpectedHeaderContent = $MicrosoftMitLicenseHeader + [Environment]::NewLine + [Environment]::NewLine + $DefaultGeneratedFileHeaderWithoutVersion
Get-HeaderContent -SwaggerDict @{Info = @{Header = 'MICROSOFT_MIT_NO_VERSION'}} | Should BeExactly $ExpectedHeaderContent
}

It "Get-HeaderContent should return MICROSOFT_MIT_NO_CODEGEN header content with '-Header MICROSOFT_MIT_NO_CODEGEN'" {
Get-HeaderContent -SwaggerDict @{Info = @{Header = 'MICROSOFT_MIT_NO_CODEGEN'}} | Should BeExactly $MicrosoftMitLicenseHeader
}

It "Get-HeaderContent should return MICROSOFT_APACHE header content with '-Header MICROSOFT_APACHE'" {
$ExpectedHeaderContent = $MicrosoftApacheLicenseHeader + [Environment]::NewLine + [Environment]::NewLine + $DefaultGeneratedFileHeaderString
Get-HeaderContent -SwaggerDict @{Info = @{Header = 'MICROSOFT_APACHE'}} | Should BeExactly $ExpectedHeaderContent
}

It "Get-HeaderContent should return MICROSOFT_APACHE_NO_VERSION header content with '-Header MICROSOFT_APACHE_NO_VERSION'" {
$ExpectedHeaderContent = $MicrosoftApacheLicenseHeader + [Environment]::NewLine + [Environment]::NewLine + $DefaultGeneratedFileHeaderWithoutVersion
Get-HeaderContent -SwaggerDict @{Info = @{Header = 'MICROSOFT_APACHE_NO_VERSION'}} | Should BeExactly $ExpectedHeaderContent
}

It "Get-HeaderContent should return MICROSOFT_APACHE_NO_CODEGEN header content with '-Header MICROSOFT_APACHE_NO_CODEGEN'" {
Get-HeaderContent -SwaggerDict @{Info = @{Header = 'MICROSOFT_APACHE_NO_CODEGEN'}} | Should BeExactly $MicrosoftApacheLicenseHeader
}
}

Context "Get-CSharpModelName Unit Tests" {
Expand Down
10 changes: 9 additions & 1 deletion docs/commands/New-PSSwaggerModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,15 @@ Accept wildcard characters: False
### -Header
Text to include as a header comment in the PSSwagger generated files.
It also can be a path to a .txt file with the content to be added as header in the PSSwagger generated files.
Specify 'NONE' to suppress the default header.

Supported predefined license header values:
- NONE: Suppresses the default header.
- MICROSOFT_MIT: Adds predefined Microsoft MIT license text with default PSSwagger code generation header content.
- MICROSOFT_MIT_NO_VERSION: Adds predefined Microsoft MIT license text with default PSSwagger code generation header content without version.
- MICROSOFT_MIT_NO_CODEGEN: Adds predefined Microsoft MIT license text without default PSSwagger code generation header content.
- MICROSOFT_APACHE: Adds predefined Microsoft Apache license text with default PSSwagger code generation header content.
- MICROSOFT_APACHE_NO_VERSION: Adds predefined Microsoft Apache license text with default PSSwagger code generation header content without version.
- MICROSOFT_APACHE_NO_CODEGEN: Adds predefined Microsoft Apache license text without default PSSwagger code generation header content.

```yaml
Type: String[]
Expand Down