-
Notifications
You must be signed in to change notification settings - Fork 70
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
Allowing single word resources to use templates #147
Allowing single word resources to use templates #147
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sad that we need this, but looks good to me 🚀
internal/provider/util.go
Outdated
// are identical after file extensions have been stripped from the | ||
// latter. This allows single word resources (e.g., http) to use | ||
// templates (e.g., http.md.tmpl). | ||
func resourceName(shortName, relFile string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a quick unit test for this?
internal/provider/generate.go
Outdated
@@ -414,7 +414,7 @@ func (g *generator) renderStaticWebsite(providerName string, providerSchema *tfj | |||
g.infof("rendering %q", rel) | |||
switch relDir { | |||
case "data-sources/": | |||
resName := shortName + "_" + removeAllExt(relFile) | |||
resName := resourceName(shortName, relFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: isn't shortName
the Provider shortname here?
In the case of the HTTP provider (through which you identified the issue), I believe the http
refers to the resource. Otherwise if, for example, you decide to create a second resource in this provider (say, for the sake of it, https
), you won't be able to match it OR it would match the wrong file.
I'll leave a comment in the unit test below.
internal/provider/util_test.go
Outdated
templateFileName string | ||
expectedResourceName string | ||
}{ | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add another case where you have a resource named (just for kicks) https
, using the same format used by the http
provider?
I say this because the http
provider is here not respecting the convention: <provider>_<resource>
when exposed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@detro you mean along the lines of:
{
"provider short name different from template file name",
"https",
"http.md.tmpl",
"https_http",
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
"provider short name different from template file name",
"http",
"https.md.tmpl",
"https",
},
What I'm expecting is that this test would fail, because the provider name is http
, but the resource name is https
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@detro I've refactored following discussion.
If the |
I'd be a BIG fan of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 🚀
internal/provider/util_test.go
Outdated
{ | ||
"provider short name concatenated with same template file name matches schema name", | ||
map[string]*tfjson.Schema{ | ||
"tls_tls": {}, | ||
}, | ||
"tls", | ||
"tls.md.tmpl", | ||
&tfjson.Schema{}, | ||
"tls_tls", | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: While Go allows you to omit field names, I personally find it a little more difficult to read the structs once the struct definition is "beyond the fold" since its based on ordering. e.g. my brain is like what is the 3rd field defined as "tls" here? I have to scroll up, see providerShortName, scroll back down
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 0.9.0 (June 1, 2022) | ||
|
||
NEW FEATURES: | ||
|
||
* cmd/tflugindocs: Additional CLI arguments `provider-name`, `rendered-provider-name`, `rendered-website-dir`, `examples-dir`, `website-temp-dir`, and `website-source-dir`. These allow to further customise generated doc ([#95](https://github.com/hashicorp/terraform-plugin-docs/pull/95)). | ||
* cmd/tfplugindocs: Additional CLI arguments `provider-name`, `rendered-provider-name`, `rendered-website-dir`, `examples-dir`, `website-temp-dir`, and `website-source-dir`. These allow to further customise generated doc ([#95](https://github.com/hashicorp/terraform-plugin-docs/pull/95)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those are definitely typos I made 🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries. I like that we're keeping an eye out for each other 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👩🍳 💋
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Currently, it is not possible to have single word
resources
ordata sources
(e.g.,http
) use templates in the generation of docs. This PR addresses that by allowing single word resources and data sources to use a matching template (e.g.,http
data source usinghttp.md.tmpl
template).An error is now returned if a resource cannot be found using either the provider short name or the provider short name concatenated with the template file name.