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

Do not use title for objects containing only additionalProperties or patternProperties #1801

Merged

Conversation

zecakeh
Copy link
Contributor

@zecakeh zecakeh commented Apr 24, 2024

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:

image

After:

Capture d’écran du 2024-04-24 12-31-37

Before:

image

After:

image

Before:

image

After:

image

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

…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>
@zecakeh zecakeh requested a review from a team as a code owner April 24, 2024 10:44
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
Copy link
Member

@richvdh richvdh left a 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.

layouts/partials/openapi/render-object-table.html Outdated Show resolved Hide resolved
@zecakeh zecakeh mentioned this pull request Apr 24, 2024
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))) }}
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 161 to 170
{{ 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 }}
Copy link
Member

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 }}

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

zecakeh added 4 commits April 30, 2024 18:08
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>
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

Thanks!

@richvdh richvdh merged commit 1fc25d8 into matrix-org:main Apr 30, 2024
12 checks passed
@zecakeh zecakeh deleted the type-not-title-for-additional-pattern branch April 30, 2024 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants