-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
Do not use title
for objects containing only additionalProperties
or patternProperties
#1801
Do not use title
for objects containing only additionalProperties
or patternProperties
#1801
Conversation
…patternProperties Previously, titles would appear that do not link to a subchema definition. It would also mean that named subschemas would appear without being clearly referenced. Now, the type clearly shows the nesting of objects and subschema definitions should be clearly referenced. Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
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.
Yes, I'd noticed this too. Suppressing the title when we aren't going to make a separate table sounds right to me.
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
*/}} | ||
{{ define "partials/object-type-or-title" }} | ||
{{ $type := "object" }} | ||
{{ if .title }} | ||
{{ if and .title (or .properties (not (or .additionalProperties .patternProperties))) }} |
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.
we should mention .properties
in the comment for this partial.
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.
Done
{{ if and .title (or .properties (not (or .additionalProperties .patternProperties))) }} | ||
{{/* | ||
If the property has a `title`, use that rather than `type`. | ||
This means we can write things like `EventFilter` rather than `object`. | ||
We only want to use the title in two cases: | ||
|
||
* The object is rendered as a separate table that will use the same | ||
title, which means that the object must have `properties`. | ||
* The object doesn't define any properties, because showing the title | ||
(like `EventFilter`) is better than showing `object`. | ||
*/}} | ||
{{ $type = .title | htmlEscape }} |
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 must say this logic makes my head explode, though I think it's probably right.
What if we did something like this instead:
{{ $title = or .title "object" }}
{{ if .anchor }}
{{ $title = printf "<a href=\"#%s\">%s</a>" (htmlEscape .anchor) $type }}
{{ end }}
{{ if .properties }}
{{/*
The object has its own (regular) properties, so we will make a separate table for it.
Refer to it using its title, if it has one.
*/}}
{{ $type = $title }}
{{ else if reflect.IsMap .additionalProperties }}
// as before
{{ else if reflect.IsMap .patternProperties }}
// as before
{{ else }}
{{/*
No properties, so there won't be a separate table. We use the title anyway, because showing the title
(like `EventFilter`) is better than showing `object`.
*/}}
{{ $type = $title }}
{{ end }}
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.
Yes, that's probably easier to read. I'll change it.
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.
Changed
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
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.
Thanks!
Previously, titles would appear that do not link to a subschema definition. It would also mean that named subschemas would appear without being clearly referenced.
Now, the type clearly shows the nesting of objects and subschema definitions should be clearly referenced.
Examples:
Before:
After:
Before:
After:
Before:
After:
Alternatively, we could just remove the
title
from the objects manually, allowing us to show a title when we really want to.The rendered types can be improved later by using formats as introduced in #1796.
Preview: https://pr1801--matrix-spec-previews.netlify.app