Skip to content

Commit 33fc386

Browse files
Ensure empty descriptions notes, inputs, outputs and links create an accurate YAML (#720)
1 parent c6fa7c1 commit 33fc386

File tree

4 files changed

+115
-5
lines changed

4 files changed

+115
-5
lines changed

src/YamlWriter/CommandHelpYamlWriter.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ internal override void WriteInputsOutputs(List<InputOutput> inputsoutputs, bool
211211
}
212212
else
213213
{
214-
sb.AppendLine(" description:");
214+
sb.AppendLine(" description: ''");
215215
}
216216
}
217217
}
@@ -226,7 +226,7 @@ internal override void WriteNotes(CommandHelp help)
226226

227227
if (string.IsNullOrEmpty(help.Notes.Trim()))
228228
{
229-
sb.AppendLine(Constants.NotesYamlHeader);
229+
sb.AppendLine(Constants.NotesYamlHeader + " ''");
230230
return;
231231
}
232232

@@ -239,15 +239,20 @@ internal override void WriteNotes(CommandHelp help)
239239

240240
internal override void WriteRelatedLinks(CommandHelp help)
241241
{
242-
sb.AppendLine(Constants.RelatedLinksYamlHeader);
243242
if (help.RelatedLinks?.Count > 0)
244243
{
244+
sb.AppendLine(Constants.RelatedLinksYamlHeader);
245+
245246
foreach (var link in help.RelatedLinks)
246247
{
247248
sb.AppendLine(string.Format("- text: '{0}'", link.LinkText));
248249
sb.AppendLine(string.Format(" href: {0}", link.Uri));
249250
}
250251
}
252+
else
253+
{
254+
sb.AppendLine(Constants.RelatedLinksYamlHeader + " []");
255+
}
251256
}
252257
}
253258

test/Pester/MeasurePlatyPSMarkdown.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ Describe "Export-MarkdownModuleFile" {
1313

1414
It "Should identify all the '<fileType>' assets" -TestCases @(
1515
@{ fileType = "unknown"; expectedCount = 2 }
16-
@{ fileType = "CommandHelp"; expectedCount = 34 }
16+
@{ fileType = "CommandHelp"; expectedCount = 35 }
1717
@{ fileType = "ModuleFile"; expectedCount = 14 }
1818
@{ fileType = "V1Schema"; expectedCount = 45 }
19-
@{ fileType = "V2Schema"; expectedCount = 3 }
19+
@{ fileType = "V2Schema"; expectedCount = 4 }
2020
) {
2121
param ($fileType, $expectedCount)
2222
$idents.Where({($_.FileType -band $fileType) -eq $fileType}).Count | Should -Be $expectedCount

test/Pester/YamlFormatting.Tests.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
Describe 'Yaml formatting tests' {
5+
It 'Inputs output and notes should have empty array when empty' {
6+
Import-MarkdownCommandHelp -Path 'assets/New-EmptyCommand.md' | Export-YamlCommandHelp -OutputFolder $TestDrive
7+
$yaml = Get-Content "$TestDrive/New-EmptyCommand.yml" -Raw
8+
9+
$isWinPS = $PSVersionTable.PSVersion.Major -eq 5
10+
11+
$inputPattern = if ($IsWindows -or $IsWinPS) { 'inputs:\r\n- name: System\.String\r\n description: ''' } else { 'inputs:\n- name: System\.String\n description: ''' }
12+
$outputPattern = if ($IsWindows -or $IsWinPS) { 'outputs:\r\n- name: System\.String\r\n description: ''' } else { 'outputs:\n- name: System\.String\n description: ''' }
13+
$notesPattern = "notes: ''"
14+
$linksPattern = "links: \[\]"
15+
16+
$yaml | Should -Match $inputPattern
17+
$yaml | Should -Match $outputPattern
18+
$yaml | Should -Match $notesPattern
19+
$yaml | Should -Match $linksPattern
20+
}
21+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
document type: cmdlet
3+
external help file: New-EmptyCommand-Help.xml
4+
HelpUri: ''
5+
Locale: en-US
6+
Module Name: ''
7+
ms.date: 03/04/2025
8+
PlatyPS schema version: 2024-05-01
9+
title: New-EmptyCommand
10+
---
11+
12+
# New-EmptyCommand
13+
14+
## SYNOPSIS
15+
16+
{{ Fill in the Synopsis }}
17+
18+
## SYNTAX
19+
20+
### __AllParameterSets
21+
22+
```
23+
New-EmptyCommand [[-InputString] <string>] [<CommonParameters>]
24+
```
25+
26+
## ALIASES
27+
28+
This cmdlet has the following aliases,
29+
{{Insert list of aliases}}
30+
31+
## DESCRIPTION
32+
33+
{{ Fill in the Description }}
34+
35+
## EXAMPLES
36+
37+
### Example 1
38+
39+
{{ Add example description here }}
40+
41+
## PARAMETERS
42+
43+
### -InputString
44+
45+
{{ Fill InputString Description }}
46+
47+
```yaml
48+
Type: System.String
49+
DefaultValue: ''
50+
SupportsWildcards: false
51+
ParameterValue: []
52+
Aliases:
53+
- InputObject
54+
- InputParameter
55+
ParameterSets:
56+
- Name: (All)
57+
Position: 0
58+
IsRequired: false
59+
ValueFromPipeline: true
60+
ValueFromPipelineByPropertyName: false
61+
ValueFromRemainingArguments: false
62+
DontShow: false
63+
AcceptedValues: []
64+
HelpMessage: ''
65+
```
66+
67+
### CommonParameters
68+
69+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
70+
-InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable,
71+
-ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see
72+
[about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
73+
74+
## INPUTS
75+
76+
### System.String
77+
78+
## OUTPUTS
79+
80+
### System.String
81+
82+
## NOTES
83+
84+
## RELATED LINKS

0 commit comments

Comments
 (0)