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

cmd/generate: allow HasExample and HasImport to function #155

Merged

Conversation

jacobbednarz
Copy link
Contributor

@jacobbednarz jacobbednarz commented Jun 20, 2022

When building custom templates, we have HasExample and
HasImport available that return a boolean value and allow templates
to include conditionals. Some uses of this would be to only show either
an example or import line should the files exist. However, when we are
calling these for templates both data-sources and resources only pass in an
empty string
resulting in the value always returning false.

This appears to be an oversight as the non-customisable render template
call site correctly passes in the values of these paths and the template
expression renders.

When building custom templates, we have `HasExample`[1] and
`HasImport`[2] available that return a boolean value and allow templates
to include conditionals. Some uses of this would be to only show either
an example or import line should the files exist. However, when we are
calling these for templates both data-sources and resources only pass in an
empty string[3] resulting in the value always returning `false`[4].

This appears to be an oversight as the non-customisable render template
call site correctly passes in the values[5] of these paths and the template
expression renders.

[1]: https://github.com/hashicorp/terraform-plugin-docs/blob/6e1a3339859e55625941bcef8ab365552235ca3b/internal/provider/template.go#L137
[2]: https://github.com/hashicorp/terraform-plugin-docs/blob/6e1a3339859e55625941bcef8ab365552235ca3b/internal/provider/template.go#L140
[3]: https://github.com/hashicorp/terraform-plugin-docs/blob/6e1a3339859e55625941bcef8ab365552235ca3b/internal/provider/generate.go#L420
[4]: https://github.com/hashicorp/terraform-plugin-docs/blob/e52e735a834db7cdbd980cc817989588c77d96d4/internal/provider/template.go#L198
[5]: https://github.com/hashicorp/terraform-plugin-docs/blob/6e1a3339859e55625941bcef8ab365552235ca3b/internal/provider/generate.go##L258
@jacobbednarz jacobbednarz requested a review from a team as a code owner Jun 20, 2022
@detro detro added the bug Something isn't working label Jun 23, 2022
detro
detro previously approved these changes Jun 23, 2022
Copy link
Contributor

@detro detro left a comment

I think this looks great, and it is yet another improvement to this tool that you are really helping to shape.

Can you please add the CHANGELOG section, describing the bugfix succinctly. I suspect this will be the first item in the v0.10.2 release.

internal/provider/generate.go Show resolved Hide resolved
internal/provider/generate.go Show resolved Hide resolved
@detro detro added this to the v0.10.2 milestone Jun 23, 2022
@jacobbednarz
Copy link
Contributor Author

jacobbednarz commented Jun 23, 2022

thanks for the review! appreciate it 🤩

will pop a CHANGELOG entry in when I'm in front of a computer tomorrow morning.

@jacobbednarz
Copy link
Contributor Author

jacobbednarz commented Jun 23, 2022

added a CHANGELOG entry with under "Unreleased" - feel free to update this when you know the release date.

detro
detro approved these changes Jun 24, 2022
Copy link
Contributor

@detro detro left a comment

LGTM

@detro detro merged commit ad61b2c into hashicorp:main Jun 24, 2022
1 check passed
@jacobbednarz jacobbednarz deleted the support-example-and-import-filepaths branch Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working command/generate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants