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

Fix class resource generation #163

Merged
merged 45 commits into from
Nov 17, 2024

Conversation

dan-hughes
Copy link
Contributor

@dan-hughes dan-hughes commented Oct 25, 2024

Pull Request (PR) description

Update documentation generation for Class Based Dsc Resources.
Reworked to not use Ast.

This Pull Request (PR) fixes the following issues

Task list

  • Added an entry to the change log under the Unreleased section of the file CHANGELOG.md.
    Entry should say what was changed and how that affects users (if applicable), and
    reference the issue being resolved (if applicable).
  • Documentation added/updated in README.md.
  • Comment-based help added/updated.
  • Localization strings added/updated in all localization files as appropriate.
  • Examples appropriately added/updated.
  • Unit tests added/updated. See DSC Community Testing Guidelines.
  • Integration tests added/updated (where possible). See DSC Community Testing Guidelines.
  • New/changed code adheres to DSC Community Style Guidelines.

This change is Reviewable

Copy link

codecov bot commented Oct 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94%. Comparing base (10f93b3) to head (22101f6).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@         Coverage Diff         @@
##           main   #163   +/-   ##
===================================
  Coverage    94%    94%           
===================================
  Files        70     72    +2     
  Lines      1325   1336   +11     
===================================
+ Hits       1251   1262   +11     
  Misses       74     74           
Files with missing lines Coverage Δ
...ource/Private/Get-ClassPropertyCustomAttribute.ps1 100% <100%> (ø)
source/Private/Get-ClassResourceProperty.ps1 100% <100%> (ø)
source/Private/Get-DscPropertyType.ps1 100% <100%> (ø)
...ource/Private/Get-DscResourceAttributeProperty.ps1 100% <100%> (ø)
...e/Private/Get-DscResourceSchemaPropertyContent.ps1 100% <100%> (ø)
source/Private/New-DscClassResourceWikiPage.ps1 100% <100%> (ø)
...Private/Test-ClassPropertyDscAttributeArgument.ps1 100% <100%> (ø)

@dan-hughes
Copy link
Contributor Author

@johlju, it's not ready yet but are you happy with the general approach?

I've tested on DnsServerDsc, WSManDsc and ComputerManagementDsc and it seems to do what it should.

If you think this is good then I'll finish it off, add tests and clean up.

@johlju
Copy link
Member

johlju commented Oct 26, 2024

Just curious what the benefits are to not use AST? I would have thought that parsing AST would be the better approach. Do we really need to refactor this much to solve the two issues? 🤔

@dan-hughes
Copy link
Contributor Author

It was simpler to just call GetProperties() on the class which provides all declared and inherited properties in one command. This includes any properties from outside the module e.g. localizedData from DscResource.Base.

I started looking at it and what initially started as a relatively small change kept growing as each change had a knock on effect to not using AST.
The sorting fix is an easy one, it's generating the Docs for multi level inheritance that took the work, especially if needing properties from outside the module.

There is also scope for the type column in the table to link to a defined Class or Enum.

@johlju
Copy link
Member

johlju commented Oct 26, 2024

If this means the code will be simplified in the end, then I good with it. I can't see any downsides at this point.

@dan-hughes dan-hughes force-pushed the fix-class-resource-generation branch from e550fc4 to 17c5160 Compare November 7, 2024 17:09
@dan-hughes dan-hughes marked this pull request as ready for review November 7, 2024 17:10
@dan-hughes
Copy link
Contributor Author

@johlju, can you give this a once over?

It would be good to get it merged then configure a module to pull the pre-release to see what it looks like.

@dan-hughes
Copy link
Contributor Author

@johlju, can you take a look please? Check I've added the correct tasks in build.yml.

Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 20 of 21 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dan-hughes)


source/Private/Get-ClassResourcePropertyState2.ps1 line 18 at r2 (raw file):

        Returns the property state for the property 'KeyName'.
#>
function Get-ClassResourcePropertyState2

Is there a reason the function name end with 2? Maybe call it Get-DscResourcePropertyAttribute or something. Not sure what Key, Mandatory, NotConfigurable goes under what term, but 'attribute' might be good as any?

@johlju
Copy link
Member

johlju commented Nov 17, 2024

@johlju, can you take a look please? Check I've added the correct tasks in build.yml.

It looks okay to me.

@dan-hughes
Copy link
Contributor Author

Reviewed 20 of 21 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dan-hughes)

source/Private/Get-ClassResourcePropertyState2.ps1 line 18 at r2 (raw file):

        Returns the property state for the property 'KeyName'.
#>
function Get-ClassResourcePropertyState2

Is there a reason the function name end with 2? Maybe call it Get-DscResourcePropertyAttribute or something. Not sure what Key, Mandatory, NotConfigurable goes under what term, but 'attribute' might be good as any?

It was a copy and paste of an AST function. I can rename though.

@dan-hughes
Copy link
Contributor Author

@johlju, function name updated.

Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 4 files at r3, all commit messages.
Reviewable status: 18 of 21 files reviewed, 1 unresolved discussion (waiting on @dan-hughes)


source/Private/Get-ClassResourcePropertyState2.ps1 line 18 at r2 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

It was a copy and paste of an AST function. I can rename though.

Using Get-ClassResourcePropertyType is very close to the other function Get-DscPropertyType that returns the actual type of a property/parameter. This a "property" inside the of the [DscResource()] attribute, so maybe Key is attribute property? So, maybe Get-DscResourceAttributeProperty?

@dan-hughes
Copy link
Contributor Author

@johlju, done.

Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 4 of 4 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @dan-hughes)

@johlju johlju merged commit 04ce853 into dsccommunity:main Nov 17, 2024
14 checks passed
@dan-hughes dan-hughes deleted the fix-class-resource-generation branch November 17, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants