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

chore: Improves schema Description / MarkdownDescription #2605

Merged
merged 17 commits into from
Sep 20, 2024

Conversation

lantoli
Copy link
Member

@lantoli lantoli commented Sep 17, 2024

Description

Improves schema Description / MarkdownDescription.

  • Unit tests to verify that both Description and MarkdownDescription are defined and have the same value.
  • Runtime update to Description so only MarkdownDescription is needed.

Implementation details:

  • Runtime changes are done with reflection as there are not setter methods so interfaces can not be used.
  • An alternative would be to have specific code for each underlaying struct but that's very verbose, for more info see 94c7ef6
  • However tests can be done with interfaces.
  • Also a good thing of doing it in different ways is that bugs in a implementation style can be caught by the other one.

Link to any related issue(s): CLOUDP-274028

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals I have added appropriate changelog entries.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

@lantoli lantoli force-pushed the CLOUDP-274028_markdown_description branch from 88f9105 to e7cf7c4 Compare September 18, 2024 05:26
@lantoli lantoli marked this pull request as ready for review September 20, 2024 10:02
@lantoli lantoli requested review from a team as code owners September 20, 2024 10:02
Copy link
Contributor

APIx bot: a message has been sent to Docs Slack channel

if ptr.Kind() != reflect.Ptr {
panic("not ptr, please fix caller")
}
v := ptr.Elem()
Copy link
Member Author

Choose a reason for hiding this comment

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

they're short var names but it's in line with conventional naming when doing reflection

}
v := ptr.Elem()
if v.Kind() != reflect.Struct {
panic("not struct, please fix caller")
Copy link
Member Author

Choose a reason for hiding this comment

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

added multiple panic to make sure it works as expected.

These panics will be caught in unit tests so they won't make it to master, e.g. in TestResourceSchemas

newPtr := reflect.New(v.Type())
newPtr.Elem().Set(v)
updateAttr(newPtr.Interface())
f.SetMapIndex(k, newPtr.Elem())
Copy link
Member Author

Choose a reason for hiding this comment

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

maps are not addressable so a new element is created and udpated

@@ -0,0 +1,73 @@
package conversion
Copy link
Collaborator

Choose a reason for hiding this comment

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

curious if we could unit test this, but might not be worth it?

Copy link
Member Author

@lantoli lantoli Sep 20, 2024

Choose a reason for hiding this comment

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

we could, although TestResourceSchemas is testing it indirectly

Copy link
Member Author

Choose a reason for hiding this comment

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

@EspenAlbert at the end I created some unit tests here 318c46c

Copy link
Collaborator

@EspenAlbert EspenAlbert left a comment

Choose a reason for hiding this comment

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

Great work!
Almost net negative PR 😅 +165 −143

GetMarkdownDescription() string
}

func checkDescriptor(name string, d descriptor, diagnostics *diag.Diagnostics) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

Copy link
Member Author

@lantoli lantoli Sep 20, 2024

Choose a reason for hiding this comment

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

Almost net negative PR 😅 +165 −143

it'll be negative in the future when more schemas are added ;-)

@lantoli
Copy link
Member Author

lantoli commented Sep 20, 2024

no doc review needed as it's only deleting duplicated doc

@lantoli lantoli merged commit 0aeb0df into master Sep 20, 2024
34 of 35 checks passed
@lantoli lantoli deleted the CLOUDP-274028_markdown_description branch September 20, 2024 20:59
Copy link
Contributor

@carriecwk carriecwk left a comment

Choose a reason for hiding this comment

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

LGTM

lantoli added a commit that referenced this pull request Sep 25, 2024
* master: (27 commits)
  chore: Bump github.com/hashicorp/terraform-plugin-framework (#2632)
  chore: Bump tj-actions/verify-changed-files (#2629)
  chore: Bump peter-evans/create-pull-request from 7.0.3 to 7.0.5 (#2628)
  chore: Bump go.mongodb.org/atlas-sdk/v20240805004 (#2630)
  chore: Bump github.com/hashicorp/terraform-plugin-go (#2631)
  fix: Makes `mongodbatlas_alert_configuration` Datadog acceptance tests non-parallel (#2626)
  chore: Improves schema Description / MarkdownDescription (#2605)
  fix doc (#2619)
  chore: Updates CHANGELOG.md header for v1.20.0 release
  chore: Updates examples link in index.md for v1.20.0 release
  chore: Updates CHANGELOG.md for #2617
  chore: Removes 1.20 deprecations (#2617)
  chore: Updates CHANGELOG.md for #2603
  fix: Updates `integration_id` in `mongodbatlas_alert_configuration` resource to be Optional+Computed (#2603)
  chore: fixed examples broken links (#2613)
  adjust instance size of sharded cluster to M30 and above (#2615)
  doc: remove EOL sentences (#2616)
  Dialed in the version (#2614)
  chore: Updates CHANGELOG.md for #2604
  fix: Supports using decimal in cluster+adv_cluster advanced_configuration `oplog_min_retention_hours` (#2604)
  ...

# Conflicts:
#	go.mod
#	go.sum
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

Successfully merging this pull request may close these issues.

3 participants