Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type change of double quoted strings of booleans/integers (and other issues) #144

Closed
MODUSCarstenScholling opened this issue Sep 23, 2024 · 3 comments

Comments

@MODUSCarstenScholling
Copy link

Hi there,

I have a kind of an issue with a datatype change causing a schema validation error later in doxfx. I am not fully sure if this is caused by PowerShell-Yaml or the underlying dll.

The used file is a stripped reference file generated by Microsoft ALDoc (Business Central, ERP). These files are usually fed into docfx to generate online help.

$yamlText = @'
### YamlMime:BusinessCentralApplicationObject
fqName: '"Dummy"'
sourceTableType:
  internalReference: O:Table::Microsoft#Foundation#Navigate#Document_Entry
  name: Microsoft.Foundation.Navigate."Document Entry"
  isExternal: false
objectProperties:
- name: ApplicationArea
  value: '#All'
  promoted: false
- name: DeleteAllowed
  value: "False"
  promoted: false
- name: SourceTable
  value: "265"
  promoted: true
  xrefType:
    internalReference: O:Table::Microsoft#Foundation#Navigate#Document_Entry
    name: Microsoft.Foundation.Navigate."Document Entry"
    isExternal: false
methods:
- syntax:
    content: procedure SetSelectItemsMode()
  summary: >-
    Set the page in the "Select Items" Mode. This means that after the "Find" Button ist used, a item list will appear where the user can choose one or more items.

    After closing the item list page this page will also close and over the filter for the seleceted items can be retrieved through procedure "GetItemSelectionFilter()"
  name: SetSelectItemsMode
  uid: M:Page::M365_Navigate_SearchAttributes.SetSelectItemsMode
commentId: O:Page::M365 Navigate SearchAttributes
name: '"M365 Navigate SearchAttributes"'
uid: O:Page::M365_Navigate_SearchAttributes
'@;

Import-Module -Name 'powershell-yaml' -Force -Scope Local;

Write-Host 'ORIGINAL';
$yamlText;

$yaml = $yamlText | ConvertFrom-Yaml -Ordered;
$newYamlText = $yaml | ConvertTo-Yaml;

Write-Host "`n`nRESULT";
$newYamlText;

ORIGINAL ($yamlText):

### YamlMime:BusinessCentralApplicationObject
fqName: '"Dummy"'
sourceTableType:
  internalReference: O:Table::Microsoft#Foundation#Navigate#Document_Entry
  name: Microsoft.Foundation.Navigate."Document Entry"
  isExternal: false
objectProperties:
- name: ApplicationArea
  value: '#All'
  promoted: false
- name: DeleteAllowed
  value: "False"
  promoted: false
- name: SourceTable
  value: "265"
  promoted: true
  xrefType:
    internalReference: O:Table::Microsoft#Foundation#Navigate#Document_Entry
    name: Microsoft.Foundation.Navigate."Document Entry"
    isExternal: false
methods:
- syntax:
    content: procedure SetSelectItemsMode()
  summary: >-
    Set the page in the "Select Items" Mode. This means that after the "Find" Button ist used, a item list will appear where the user can choose one or more items.

    After closing the item list page this page will also close and over the filter for the seleceted items can be retrieved through procedure "GetItemSelectionFilter()"
  name: SetSelectItemsMode
  uid: M:Page::M365_Navigate_SearchAttributes.SetSelectItemsMode
commentId: O:Page::M365 Navigate SearchAttributes
name: '"M365 Navigate SearchAttributes"'
uid: O:Page::M365_Navigate_SearchAttributes

RESULT ($newYamlText)

fqName: '"Dummy"'
sourceTableType:
  internalReference: O:Table::Microsoft#Foundation#Navigate#Document_Entry
  name: Microsoft.Foundation.Navigate."Document Entry"
  isExternal: false
objectProperties:
- name: ApplicationArea
  value: '#All'
  promoted: false
- name: DeleteAllowed
  value: False
  promoted: false
- name: SourceTable
  value: "265"
  promoted: true
  xrefType:
    internalReference: O:Table::Microsoft#Foundation#Navigate#Document_Entry
    name: Microsoft.Foundation.Navigate."Document Entry"
    isExternal: false
methods:
- syntax:
    content: procedure SetSelectItemsMode()
  summary: |-
    Set the page in the "Select Items" Mode. This means that after the "Find" Button ist used, a item list will appear where the user can choose one or more items.
    After closing the item list page this page will also close and over the filter for the seleceted items can be retrieved through procedure "GetItemSelectionFilter()"
  name: SetSelectItemsMode
  uid: M:Page::M365_Navigate_SearchAttributes.SetSelectItemsMode
commentId: O:Page::M365 Navigate SearchAttributes
name: '"M365 Navigate SearchAttributes"'
uid: O:Page::M365_Navigate_SearchAttributes

RESULT WITH COMMENTS

## MISSING YamlMime
fqName: '"Dummy"'
sourceTableType:
  internalReference: O:Table::Microsoft#Foundation#Navigate#Document_Entry
  name: Microsoft.Foundation.Navigate."Document Entry"
  isExternal: false
objectProperties:
- name: ApplicationArea
  value: '#All'
  promoted: false
- name: DeleteAllowed
  value: False ## Now a boolean instead of a string "False"
  promoted: false
- name: SourceTable
  value: "265"
  promoted: true
  xrefType:
    internalReference: O:Table::Microsoft#Foundation#Navigate#Document_Entry
    name: Microsoft.Foundation.Navigate."Document Entry"
    isExternal: false
methods:
- syntax:
    content: procedure SetSelectItemsMode()
  summary: |- ## Was >- before
    Set the page in the "Select Items" Mode. This means that after the "Find" Button ist used, a item list will appear where the user can choose one or more items.
## Missing newline
    After closing the item list page this page will also close and over the filter for the seleceted items can be retrieved through procedure "GetItemSelectionFilter()"
  name: SetSelectItemsMode
  uid: M:Page::M365_Navigate_SearchAttributes.SetSelectItemsMode
commentId: O:Page::M365 Navigate SearchAttributes
name: '"M365 Navigate SearchAttributes"'
uid: O:Page::M365_Navigate_SearchAttributes

While I mentioned all issues I have found so far, the datatype conversion string to boolean ist the most annoying :)

What I've seen so far is, that the Node.Style is DoubleQuoted. I tried to handle it (surround with double quotes). That resulted in '"False"', single and double quoted. However, the validation was successful then.

@gabriel-samfira
Copy link
Member

Hi @MODUSCarstenScholling

the >- notation for literal strings does not preserve newlines (from what I remember), whereas using |- will do that. So if it can be helped at all, you could replace >- with |- if preserving that newline is important.

With the currently released version 0.4.7, I tried your yaml and got the following:

PS /home/gabriel> $yamlText = @'
>> ### YamlMime:BusinessCentralApplicationObject
>> fqName: '"Dummy"'
>> sourceTableType:
>>   internalReference: O:Table::Microsoft#Foundation#Navigate#Document_Entry
>>   name: Microsoft.Foundation.Navigate."Document Entry"
>>   isExternal: false
>> objectProperties:
>> - name: ApplicationArea
>>   value: '#All'
>>   promoted: false
>> - name: DeleteAllowed
>>   value: "False"
>>   promoted: false
>> - name: SourceTable
>>   value: "265"
>>   promoted: true
>>   xrefType:
>>     internalReference: O:Table::Microsoft#Foundation#Navigate#Document_Entry
>>     name: Microsoft.Foundation.Navigate."Document Entry"
>>     isExternal: false
>> methods:
>> - syntax:
>>     content: procedure SetSelectItemsMode()
>>   summary: |-
>>     Set the page in the "Select Items" Mode. This means that after the "Find" Button ist used, a item list will appear where the user can choose one or more items.
>> 
>>     After closing the item list page this page will also close and over the filter for the seleceted items can be retrieved through procedure "GetItemSelectionFilter()"
>>   name: SetSelectItemsMode
>>   uid: M:Page::M365_Navigate_SearchAttributes.SetSelectItemsMode
>> commentId: O:Page::M365 Navigate SearchAttributes
>> name: '"M365 Navigate SearchAttributes"'
>> uid: O:Page::M365_Navigate_SearchAttributes
>> '@;
PS /home/gabriel> cfy -Ordered $yamlText | cty
fqName: '"Dummy"'
sourceTableType:
  internalReference: O:Table::Microsoft#Foundation#Navigate#Document_Entry
  name: Microsoft.Foundation.Navigate."Document Entry"
  isExternal: false
objectProperties:
- name: ApplicationArea
  value: '#All'
  promoted: false
- name: DeleteAllowed
  value: "False"
  promoted: false
- name: SourceTable
  value: "265"
  promoted: true
  xrefType:
    internalReference: O:Table::Microsoft#Foundation#Navigate#Document_Entry
    name: Microsoft.Foundation.Navigate."Document Entry"
    isExternal: false
methods:
- syntax:
    content: procedure SetSelectItemsMode()
  summary: |-
    Set the page in the "Select Items" Mode. This means that after the "Find" Button ist used, a item list will appear where the user can choose one or more items.

    After closing the item list page this page will also close and over the filter for the seleceted items can be retrieved through procedure "GetItemSelectionFilter()"
  name: SetSelectItemsMode
  uid: M:Page::M365_Navigate_SearchAttributes.SetSelectItemsMode
commentId: O:Page::M365 Navigate SearchAttributes
name: '"M365 Navigate SearchAttributes"'
uid: O:Page::M365_Navigate_SearchAttributes

PS /home/gabriel> get-Module powershell-yaml

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     0.4.7                 powershell-yaml                     {ConvertFrom-Yaml, ConvertTo-Yaml, cfy, cty}

Types seem to be preserved. The only change I made to your Yaml is the >- --> |-.

Also, you shouldn't need to single quote an already double quoted string.

Could you check which version of powershell-yaml you're using?

Also, I have been trying to get some feedback on an idea which has to do with modeling the data that gets deserialized into specific powershell types. If you're willing, would you mind having a look at:

and potentially offer feedback on that PR?

@MODUSCarstenScholling
Copy link
Author

Thank you @gabriel-samfira ,

the >- notation for literal strings does not preserve newlines (from what I remember), whereas using |- will do that.

Indeed, you are right. |- keeps newline, >- removes newlines. I had mixed them up. I think the source (XML comments) is not passing this correctly here. I'll have another look at that.

With the currently released version 0.4.7, I tried your yaml and got the following:
Types seem to be preserved.

I should have stayed in bed today. It was version 0.4.3. We are currently converting processes from PS5 to PS7. 0.4.3 was installed locally for PS5 (WindowsPowerShell), 0.4.7 globally in PS7 (PowerShell). I accidentally tested with 0.4.3, I'm really sorry!

0.4.7 works as expected.

I will have a look at the PR later today.

@gabriel-samfira
Copy link
Member

No worries! Glad it works!

No rush or obligation to give any feedback on the above mentioned PR, unless you feel that it's inclusion might be useful or detrimental to your experience using the module. It's more of an exploratory PR to gauge if people would want something like that. It would live side by side with existing functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants