Fix incorrect rendering of example and import files for providers with no templates or fallback templates #300
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #9
Fixes: #191
Fixes: #193
Supersedes: #185
The
renderMissingResourceDoc()
andrenderMissingProviderDoc()
methods determine if there are any existing templates for a given resource/datasource and if not, generates new templates either by using the default templates or by generating templates from generic "fallback" templates if they exist (i.e.templates/resources.tmpl.md
). When new templates are generated in these methods, they are rendered to.md
files. After these methods are called, therenderStaticWebsite()
method is called to render the template files to.md
files and copy them into the rendered website directory. This means that templates generated during therenderMissingResourceDoc()
andrenderMissingProviderDoc()
methods are rendered to markdown twice leading to confusing and inconsistent behavior around theprintf
function which should print a string literal but would instead render the string as actual markdown.The default templates use
printf
to show example syntax of how to call thecodefile
andtffile
functions:but because of this bug, they ended up rendering as actual markdown:
instead of the expected string literal:
The changes in
cmd/tfplugindocs/testdata/scripts/schema-json/generate/framework_provider_success_generic_templates.txtar
demonstrate this difference.This PR fixes the bug by removing template rendering code from
renderMissingResourceDoc()
andrenderMissingProviderDoc()
methods and refactoring these methods to make their purposes clearer. New acceptance tests have been added to test the behavior of static files that skip new template generation.Because there may be developers using this tool who have relied on the default templates to generate docs with rendered examples, I choose to change the default templates to accommodate this after fixing the bug.