Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class HaPanelDevAction extends LitElement {
<td>
${this.hass.localize(
`component.${domain}.services.${serviceName}.fields.${field.key}.example`
) || field.example}
) || JSON.stringify(field.example)}
Comment on lines 299 to +301
Copy link
Member

Choose a reason for hiding this comment

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

Mixing JSON with YAML seems confusing. I propose just YAML formatting complex objects like this, where dump is imported from "js-yaml"

Suggested change
${this.hass.localize(
`component.${domain}.services.${serviceName}.fields.${field.key}.example`
) || field.example}
) || JSON.stringify(field.example)}
${this.hass.localize(
`component.${domain}.services.${serviceName}.fields.${field.key}.example`
) ||
(typeof field.example === "object"
? html`<pre>${dump(field.example)}</pre>`
: field.example)}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MindFreeze agreed, although in some instances json is way more helpful (e.g. if feeding the data into the REST API - which is what I was doing when I stumbled across this issue).

Would having two example columns (one for JSON, one for yaml) be out of the question?

I noticed the Microsoft started doing similar a while ago where they have a help page with API examples in multiple languages.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this page is meant for using/documenting the REST API, we generally use YAML for everything, and that is what we should display here. I would not add yet another column.

</td>
</tr>`
)}
Expand Down
Loading